AddToFactoryWithJson() Added to Factories + Rename
This commit is contained in:
parent
c4edfef458
commit
5e0b7692b2
|
@ -1,7 +1,7 @@
|
||||||
using Syntriax.Modules.Movement.ColliderTrigger;
|
using Syntriax.Modules.Movement.ColliderTrigger;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement.TwoDimensionalImplementations
|
||||||
{
|
{
|
||||||
public class OneWay2DAirMovement : OneWay2DMovementBase
|
public class OneWay2DAirMovement : OneWay2DMovementBase
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using Syntriax.Modules.Movement.ColliderTrigger;
|
using Syntriax.Modules.Movement.ColliderTrigger;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement.TwoDimensionalImplementations
|
||||||
{
|
{
|
||||||
public class OneWay2DGroundMovement : OneWay2DMovementBase
|
public class OneWay2DGroundMovement : OneWay2DMovementBase
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement.TwoDimensionalImplementations
|
||||||
{
|
{
|
||||||
public abstract class OneWay2DMovementBase : TwoDimensionalMovementBase
|
public abstract class OneWay2DMovementBase : TwoDimensionalMovementBase
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@ using Syntriax.Modules.Movement.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement.TwoDimensionalImplementations
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Rigidbody2D))]
|
[RequireComponent(typeof(Rigidbody2D))]
|
||||||
public abstract class TwoDimensionalMovementBase : MonoBehaviour, IMovement
|
public abstract class TwoDimensionalMovementBase : MonoBehaviour, IMovement
|
||||||
|
|
|
@ -50,10 +50,13 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToDefinitions))
|
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToDefinitions))
|
||||||
{
|
AddToFactoryWithJSON(definitionTextAsset.text);
|
||||||
MovementDefinition movementDefinition = JsonUtility.FromJson<MovementDefinition>(definitionTextAsset.text);
|
|
||||||
AddDefinitionToFactory(movementDefinition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddToFactoryWithJSON(string definitionJSONText)
|
||||||
|
{
|
||||||
|
MovementDefinition movementDefinition = JsonUtility.FromJson<MovementDefinition>(definitionJSONText);
|
||||||
|
AddDefinitionToFactory(movementDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() => _definitions?.Clear();
|
public void Reset() => _definitions?.Clear();
|
||||||
|
|
|
@ -53,10 +53,13 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToCollections))
|
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToCollections))
|
||||||
{
|
AddToFactoryWithJSON(definitionTextAsset.text);
|
||||||
VMCollection collection = JsonUtility.FromJson<VMCollection>(definitionTextAsset.text);
|
|
||||||
AddCollectionToFactory(collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddToFactoryWithJSON(string definitionJSONText)
|
||||||
|
{
|
||||||
|
VMCollection collectionDefinition = JsonUtility.FromJson<VMCollection>(definitionJSONText);
|
||||||
|
AddCollectionToFactory(collectionDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() => _collections?.Clear();
|
public void Reset() => _collections?.Clear();
|
||||||
|
@ -70,7 +73,7 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
public void AddCollectionToFactory(VMCollection collection)
|
public void AddCollectionToFactory(VMCollection collection)
|
||||||
{
|
{
|
||||||
if (Collections.ContainsKey(collection.Name))
|
if (Collections.ContainsKey(collection.Name))
|
||||||
throw new System.ArgumentException($"{ collection.Name } is already in the { Name }");
|
throw new System.ArgumentException($"{collection.Name} is already in the {Name}");
|
||||||
|
|
||||||
Collections.Add(collection.Name, collection);
|
Collections.Add(collection.Name, collection);
|
||||||
}
|
}
|
||||||
|
@ -88,14 +91,14 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
if (string.IsNullOrEmpty(type.Namespace))
|
if (string.IsNullOrEmpty(type.Namespace))
|
||||||
return type.Name;
|
return type.Name;
|
||||||
|
|
||||||
return $"{ type.Namespace }.{ type.Name }";
|
return $"{type.Namespace}.{type.Name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
public void SaveCollection(VMCollection collection)
|
public void SaveCollection(VMCollection collection)
|
||||||
{
|
{
|
||||||
string jsonText = JsonUtility.ToJson(collection, true);
|
string jsonText = JsonUtility.ToJson(collection, true);
|
||||||
string path = $"Assets/Resources/{ ResourceDirectoryToCollections }{collection.Name}.json";
|
string path = $"Assets/Resources/{ResourceDirectoryToCollections}{collection.Name}.json";
|
||||||
System.IO.File.WriteAllText(path, jsonText);
|
System.IO.File.WriteAllText(path, jsonText);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue