Variable MovementCollections Added

This commit is contained in:
Syntriax 2022-02-19 16:49:34 +03:00
parent ccd9fdc435
commit c7418eb578
9 changed files with 90 additions and 5 deletions

View File

@ -2,6 +2,9 @@ namespace Syntriax.Modules.Movement.VariableMovement
{
public class DefaulVariableMovementAsset : IVariableMovementAsset
{
public static DefaulVariableMovementAsset _instance = new DefaulVariableMovementAsset();
public static DefaulVariableMovementAsset Instance => _instance;
public string MovementName => "Default Movement";
public float MovementMultiplier { get; } = 1f;

View File

@ -2,6 +2,6 @@ namespace Syntriax.Modules.Movement.VariableMovement
{
public interface IVariableMovement : IState
{
IVariableMovementAsset VariableMovementAsset { get; }
IVariableMovementAsset VariableMovementAsset { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace Syntriax.Modules.Movement.VariableMovement
{
public interface IVariableMovementCollection
{
IVariableMovementAsset DefaultVariableMovementsAsset { get; }
List<IVariableMovementAsset> VariableMovementsAssets { get; }
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 47411e74f07b72041a17185dd8483dfc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,6 +5,7 @@ namespace Syntriax.Modules.Movement.VariableMovement
public interface IVariableMovementController : IState
{
List<IVariableMovement> VariableMovements { get; }
IVariableMovementCollection VariableMovementCollection { get; set; }
IVariableMovement CurrentVariableMovement { get; }
}
}

View File

@ -2,9 +2,21 @@ namespace Syntriax.Modules.Movement.VariableMovement.SimpleImplementation
{
public class SimpleVariableMovement : IVariableMovement
{
public IVariableMovementAsset VariableMovementAsset { get; protected set; } = null;
protected IVariableMovementAsset _variableMovementAsset = null;
public IVariableMovementAsset VariableMovementAsset
{
get => _variableMovementAsset;
set
{
_variableMovementAsset = value;
StateEnabled = false;
}
}
public bool StateEnabled { get; set; } = false;
public SimpleVariableMovement() { }
public SimpleVariableMovement(IVariableMovementAsset variableMovementAsset)
=> VariableMovementAsset = variableMovementAsset;
}

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using UnityEngine;
namespace Syntriax.Modules.Movement.VariableMovement.SimpleImplementation
{
[CreateAssetMenu(fileName = "Simple VM Asset Collection", menuName = "Syntriax/Modules/Movement/VariableMovement/Simple VM Asset Collection", order = 0)]
public class SimpleVariableMovementCollection : ScriptableObject, IVariableMovementCollection
{
[SerializeField] protected SimpleVariableMovementAsset defaultVariableMovementsAsset = null;
[SerializeField] protected List<SimpleVariableMovementAsset> variableMovementsAssets = new List<SimpleVariableMovementAsset>();
public IVariableMovementAsset DefaultVariableMovementsAsset => defaultVariableMovementsAsset;
public List<IVariableMovementAsset> VariableMovementsAssets => variableMovementsAssets.ConvertAll<IVariableMovementAsset>(simple => (IVariableMovementAsset)simple);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5cee6b82ee9d68c4eb38ce2e693515d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,23 +5,45 @@ namespace Syntriax.Modules.Movement.VariableMovement.SimpleImplementation
{
public class SimpleVariableMovementController : MonoBehaviour, IVariableMovementController
{
private static IVariableMovement DefaultVariableMovement = new SimpleVariableMovement(new DefaulVariableMovementAsset());
protected IVariableMovement _defaultVariableMovement = new SimpleVariableMovement();
protected IVariableMovementCollection _variableMovementCollection = null;
public bool StateEnabled { get; set; } = false;
public List<IVariableMovement> VariableMovements { get; protected set; } = new List<IVariableMovement>();
public IVariableMovementCollection VariableMovementCollection
{
get => _variableMovementCollection;
set
{
_variableMovementCollection = value;
VariableMovements.Clear();
_defaultVariableMovement.VariableMovementAsset = value.DefaultVariableMovementsAsset;
_defaultVariableMovement.StateEnabled = true;
if (VariableMovements.Capacity < value.VariableMovementsAssets.Count)
VariableMovements.Capacity = value.VariableMovementsAssets.Count;
foreach (var asset in value.VariableMovementsAssets)
VariableMovements.Add(new SimpleVariableMovement(asset));
}
}
public IVariableMovement CurrentVariableMovement
{
get
{
if (!StateEnabled)
return DefaultVariableMovement;
return _defaultVariableMovement;
foreach (IVariableMovement variableMovement in VariableMovements)
if (variableMovement.StateEnabled)
return variableMovement;
return DefaultVariableMovement;
return _defaultVariableMovement;
}
}
}