Default Variable Movement Field is now Optional

This commit is contained in:
Syntriax 2022-04-03 19:56:25 +03:00
parent cda057ebeb
commit c4edfef458
1 changed files with 6 additions and 3 deletions

View File

@ -67,7 +67,7 @@ namespace Syntriax.Modules.Movement.Config
public void AddDefinitionToFactory(MovementDefinition movementDefinition) public void AddDefinitionToFactory(MovementDefinition movementDefinition)
{ {
if (Definitions.ContainsKey(movementDefinition.Name)) if (Definitions.ContainsKey(movementDefinition.Name))
throw new System.ArgumentException($"{ movementDefinition.Name } is already in the Movement Definition Factory"); throw new System.ArgumentException($"{movementDefinition.Name} is already in the Movement Definition Factory");
Definitions.Add(movementDefinition.Name, movementDefinition); Definitions.Add(movementDefinition.Name, movementDefinition);
} }
@ -75,7 +75,7 @@ namespace Syntriax.Modules.Movement.Config
public void ApplyDefinitionToGameObject(GameObject gameObject, string definitionName) public void ApplyDefinitionToGameObject(GameObject gameObject, string definitionName)
{ {
if (!Definitions.ContainsKey(definitionName)) if (!Definitions.ContainsKey(definitionName))
throw new System.ArgumentException($"The definition with name \"{ definitionName }\" does not exists in the current { Name }"); throw new System.ArgumentException($"The definition with name \"{definitionName}\" does not exists in the current {Name}");
ApplyDefinitionToGameObject(gameObject, Definitions[definitionName]); ApplyDefinitionToGameObject(gameObject, Definitions[definitionName]);
} }
@ -92,6 +92,9 @@ namespace Syntriax.Modules.Movement.Config
foreach (string monoBehaviours in definition.MonoBehaviours) foreach (string monoBehaviours in definition.MonoBehaviours)
MovementFactory.Instance.AddToGameObject(gameObject, monoBehaviours); MovementFactory.Instance.AddToGameObject(gameObject, monoBehaviours);
if (string.IsNullOrEmpty(definition.DefaultVariableMovement))
return;
IVariableMovementController variableMovementController = gameObject.GetComponent<IVariableMovementController>(); IVariableMovementController variableMovementController = gameObject.GetComponent<IVariableMovementController>();
VMCollection collection = VariableMovementFactory.Instance.Collections[definition.DefaultVariableMovement]; VMCollection collection = VariableMovementFactory.Instance.Collections[definition.DefaultVariableMovement];
variableMovementController?.LoadVariableMovementCollection(collection); variableMovementController?.LoadVariableMovementCollection(collection);
@ -101,7 +104,7 @@ namespace Syntriax.Modules.Movement.Config
public void SaveMovementDefinition(MovementDefinition definition) public void SaveMovementDefinition(MovementDefinition definition)
{ {
string jsonText = JsonUtility.ToJson(definition, true); string jsonText = JsonUtility.ToJson(definition, true);
string path = $"Assets/Resources/{ ResourceDirectoryToDefinitions }{ definition.Name }.json"; string path = $"Assets/Resources/{ResourceDirectoryToDefinitions}{definition.Name}.json";
System.IO.File.WriteAllText(path, jsonText); System.IO.File.WriteAllText(path, jsonText);
} }
#endif #endif