Variable Movement Removed Temporarily
This commit is contained in:
parent
99f5cf4fa4
commit
364fc6b935
|
@ -6,14 +6,12 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
public struct MovementDefinition
|
public struct MovementDefinition
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public string DefaultVariableMovement;
|
|
||||||
public MovementConfig[] MovementConfigs;
|
public MovementConfig[] MovementConfigs;
|
||||||
public string[] MonoBehaviours;
|
public string[] MonoBehaviours;
|
||||||
|
|
||||||
public MovementDefinition(string name, string defaultVariableMovement, MovementConfig[] movementConfigs, string[] monoBehaviours)
|
public MovementDefinition(string name, MovementConfig[] movementConfigs, string[] monoBehaviours)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
DefaultVariableMovement = defaultVariableMovement;
|
|
||||||
MovementConfigs = movementConfigs;
|
MovementConfigs = movementConfigs;
|
||||||
MonoBehaviours = monoBehaviours;
|
MonoBehaviours = monoBehaviours;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Syntriax.Modules.Movement.VariableMovement;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.Config
|
namespace Syntriax.Modules.Movement.Config
|
||||||
|
@ -94,13 +93,6 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
if (definition.MonoBehaviours != null)
|
if (definition.MonoBehaviours != null)
|
||||||
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>();
|
|
||||||
VMCollection collection = VariableMovementFactory.Instance.Collections[definition.DefaultVariableMovement];
|
|
||||||
variableMovementController?.LoadVariableMovementCollection(collection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using UnityEngine;
|
|
||||||
using Syntriax.Modules.Movement.VariableMovement;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.Config
|
|
||||||
{
|
|
||||||
public class VariableMovementFactory : MonoBehaviour
|
|
||||||
{
|
|
||||||
private const string Name = "Variable Movement Factory";
|
|
||||||
private const int InitialCapacity = 64;
|
|
||||||
private const string ResourceDirectoryToCollections = "Modules/Syntriax/Movement/Variable Movement/Collections/";
|
|
||||||
|
|
||||||
private static VariableMovementFactory _instance = null;
|
|
||||||
public static VariableMovementFactory Instance
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_instance == null)
|
|
||||||
_instance = new GameObject(Name).AddComponent<VariableMovementFactory>();
|
|
||||||
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dictionary<string, VMCollection> _collections = null;
|
|
||||||
public Dictionary<string, VMCollection> Collections
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_collections == null)
|
|
||||||
Initialize();
|
|
||||||
|
|
||||||
return _collections;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
if (_instance == this)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Destroy(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Initialize()
|
|
||||||
{
|
|
||||||
if (_collections == null)
|
|
||||||
_collections = new Dictionary<string, VMCollection>(InitialCapacity);
|
|
||||||
|
|
||||||
Reset();
|
|
||||||
|
|
||||||
foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll<TextAsset>(ResourceDirectoryToCollections))
|
|
||||||
AddToFactoryWithJSON(definitionTextAsset.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddToFactoryWithJSON(string definitionJSONText)
|
|
||||||
{
|
|
||||||
VMCollection collectionDefinition = JsonUtility.FromJson<VMCollection>(definitionJSONText);
|
|
||||||
AddCollectionToFactory(collectionDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset() => _collections?.Clear();
|
|
||||||
|
|
||||||
public void AddCollectionsToFactory(List<VMCollection> collections)
|
|
||||||
{
|
|
||||||
foreach (VMCollection collection in collections)
|
|
||||||
AddCollectionToFactory(collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddCollectionToFactory(VMCollection collection)
|
|
||||||
{
|
|
||||||
if (Collections.ContainsKey(collection.Name))
|
|
||||||
throw new System.ArgumentException($"{collection.Name} is already in the {Name}");
|
|
||||||
|
|
||||||
Collections.Add(collection.Name, collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public Component AddToGameObject(GameObject gameObject, string name)
|
|
||||||
// {
|
|
||||||
// if (!Collections.ContainsKey(name))
|
|
||||||
// throw new ArgumentException($"The key \"{ name }\" does not exists in the current Movement Factory");
|
|
||||||
|
|
||||||
// return gameObject.AddComponent(Collections[name]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public string GetTypeName(Type type)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(type.Namespace))
|
|
||||||
return type.Name;
|
|
||||||
|
|
||||||
return $"{type.Namespace}.{type.Name}";
|
|
||||||
}
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
public void SaveCollection(VMCollection collection)
|
|
||||||
{
|
|
||||||
string jsonText = JsonUtility.ToJson(collection, true);
|
|
||||||
string path = $"Assets/Resources/{ResourceDirectoryToCollections}{collection.Name}.json";
|
|
||||||
System.IO.File.WriteAllText(path, jsonText);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 514a385e4a5f87b47ae0f508bc253fb9
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 726dbb7aaeb452e42b1faf1318513cdb
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,7 +0,0 @@
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
public interface IVariableMovement
|
|
||||||
{
|
|
||||||
VMAsset Asset { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 6cdf8a548c241e0419fcf7e95c760cae
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,14 +0,0 @@
|
||||||
using System;
|
|
||||||
using UnityEngine.InputSystem;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
public interface IVariableMovementController
|
|
||||||
{
|
|
||||||
IVariableMovement ActiveVariableMovement { get; }
|
|
||||||
Action<IVariableMovement> OnVariableMovementChanged { get; set; }
|
|
||||||
IInputActionCollection InputActionCollection { get; set; }
|
|
||||||
|
|
||||||
void LoadVariableMovementCollection(VMCollection collection);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 8626f2dd751462548adce79ccb84d6d3
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,12 +0,0 @@
|
||||||
using System;
|
|
||||||
using UnityEngine.InputSystem;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
public interface IVariableMovementWithState : IVariableMovement
|
|
||||||
{
|
|
||||||
bool Enabled { get; set; }
|
|
||||||
Action<bool> OnToggleStateChanged { get; set; }
|
|
||||||
IInputActionCollection InputCollection { set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: c4e5bc603a4ef1342abf1e987cfced7f
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 63a9b9d234afa1d4d81a6f018393c057
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,10 +0,0 @@
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
[CreateAssetMenu(fileName = "VMAsset", menuName = "Syntriax/Modules/Movement/Variable Movement/Asset", order = 0)]
|
|
||||||
public class VMAssetSO : ScriptableObject
|
|
||||||
{
|
|
||||||
public VMAsset asset;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 675d01134857a5b4aa8278985b7d2c09
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,10 +0,0 @@
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
[CreateAssetMenu(fileName = "VMCollection", menuName = "Syntriax/Modules/Movement/Variable Movement/Collection", order = 0)]
|
|
||||||
public class VMCollectionSO : ScriptableObject
|
|
||||||
{
|
|
||||||
public VMCollection collection;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: b6d52a12481917c4b877c026fa81dfef
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public struct VMAsset
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
public float Multiplier;
|
|
||||||
public string ActionReference;
|
|
||||||
|
|
||||||
public VMAsset(string name, float multiplier, string actionReference)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Multiplier = multiplier;
|
|
||||||
ActionReference = actionReference;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 35f90754856e0cf43a33a1a6bc5e0423
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public struct VMCollection
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
public VMAsset DefaultAsset;
|
|
||||||
public VMAsset[] VMAssets;
|
|
||||||
|
|
||||||
public VMCollection(string name, VMAsset defaultAsset, VMAsset[] vMAssets)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
DefaultAsset = defaultAsset;
|
|
||||||
VMAssets = vMAssets;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 6c9addcc3980a2948b5c2e493f8f1642
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,11 +0,0 @@
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
public class VariableMovement : IVariableMovement
|
|
||||||
{
|
|
||||||
public VMAsset Asset { get; set; }
|
|
||||||
|
|
||||||
public VariableMovement() { }
|
|
||||||
public VariableMovement(VMAsset asset)
|
|
||||||
=> Asset = asset;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 9fa3a5e4edf40ce42a96a32da76de626
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,114 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.InputSystem;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
public class VariableMovementController : MonoBehaviour, IVariableMovementController
|
|
||||||
{
|
|
||||||
public Action<IVariableMovement> OnVariableMovementChanged { get; set; } = null;
|
|
||||||
private IInputActionCollection _inputActionCollection = null;
|
|
||||||
public IInputActionCollection InputActionCollection
|
|
||||||
{
|
|
||||||
get => _inputActionCollection;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_inputActionCollection = value;
|
|
||||||
|
|
||||||
foreach (IVariableMovementWithState variableMovement in variableMovementsWithState)
|
|
||||||
variableMovement.InputCollection = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private IVariableMovement _activeVariableMovement = null;
|
|
||||||
public IVariableMovement ActiveVariableMovement
|
|
||||||
{
|
|
||||||
get => _activeVariableMovement;
|
|
||||||
protected set
|
|
||||||
{
|
|
||||||
_activeVariableMovement = value;
|
|
||||||
OnVariableMovementChanged.Invoke(value);
|
|
||||||
|
|
||||||
if (movementController != null)
|
|
||||||
SetMultiplierToActiveMovement(movementController.ActiveMovement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool isSet = false;
|
|
||||||
protected IMovementController movementController = null;
|
|
||||||
protected IVariableMovement defaultVariableMovement = null;
|
|
||||||
protected List<IVariableMovementWithState> variableMovementsWithState = null;
|
|
||||||
protected VMCollection collection;
|
|
||||||
|
|
||||||
protected virtual void Awake()
|
|
||||||
{
|
|
||||||
defaultVariableMovement = new VariableMovement();
|
|
||||||
variableMovementsWithState = new List<IVariableMovementWithState>(16);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Start()
|
|
||||||
{
|
|
||||||
movementController = GetComponent<IMovementController>();
|
|
||||||
movementController.OnMovementActivated += SetMultiplierToActiveMovement;
|
|
||||||
movementController.OnMovementDeactivated += ResetMultiplierToDefault;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ResetMultiplierToDefault(IMovement currentMovement)
|
|
||||||
{
|
|
||||||
if (!isSet)
|
|
||||||
return;
|
|
||||||
|
|
||||||
currentMovement.MovementMultiplier = defaultVariableMovement.Asset.Multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SetMultiplierToActiveMovement(IMovement currentMovement)
|
|
||||||
{
|
|
||||||
if (!isSet)
|
|
||||||
return;
|
|
||||||
|
|
||||||
currentMovement.MovementMultiplier = ActiveVariableMovement.Asset.Multiplier;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadVariableMovementCollection(VMCollection collection)
|
|
||||||
{
|
|
||||||
this.collection = collection;
|
|
||||||
isSet = true;
|
|
||||||
|
|
||||||
UnsubscribeFromMovements();
|
|
||||||
|
|
||||||
variableMovementsWithState.Clear();
|
|
||||||
foreach (VMAsset asset in collection.VMAssets)
|
|
||||||
variableMovementsWithState.Add(new VariableMovementWithState(asset, InputActionCollection));
|
|
||||||
defaultVariableMovement.Asset = collection.DefaultAsset;
|
|
||||||
|
|
||||||
SubscribeToMovements();
|
|
||||||
UpdateActiveVariableMovement();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void SubscribeToMovements()
|
|
||||||
{
|
|
||||||
foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState)
|
|
||||||
variableMovementWithState.OnToggleStateChanged += VariableMovementStateListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void UnsubscribeFromMovements()
|
|
||||||
{
|
|
||||||
foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState)
|
|
||||||
variableMovementWithState.OnToggleStateChanged -= VariableMovementStateListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VariableMovementStateListener(bool arg0) => UpdateActiveVariableMovement();
|
|
||||||
protected virtual void UpdateActiveVariableMovement()
|
|
||||||
{
|
|
||||||
foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState)
|
|
||||||
if (variableMovementWithState.Enabled)
|
|
||||||
{
|
|
||||||
ActiveVariableMovement = variableMovementWithState;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActiveVariableMovement = defaultVariableMovement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 9c54e2868362dbe4eab92c16ee11fc42
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,80 +0,0 @@
|
||||||
using System;
|
|
||||||
using UnityEngine.InputSystem;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.VariableMovement
|
|
||||||
{
|
|
||||||
public class VariableMovementWithState : IVariableMovementWithState
|
|
||||||
{
|
|
||||||
public Action<bool> OnToggleStateChanged { get; set; } = null;
|
|
||||||
private bool _enabled = false;
|
|
||||||
public bool Enabled
|
|
||||||
{
|
|
||||||
get => _enabled;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
bool isNewValue = _enabled != value;
|
|
||||||
|
|
||||||
_enabled = value;
|
|
||||||
|
|
||||||
if (isNewValue)
|
|
||||||
OnToggleStateChanged.Invoke(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private VMAsset _asset;
|
|
||||||
public VMAsset Asset
|
|
||||||
{
|
|
||||||
get => _asset;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
UpdateBindings();
|
|
||||||
|
|
||||||
_asset = value;
|
|
||||||
|
|
||||||
Enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInputActionCollection _inputCollection = null;
|
|
||||||
public IInputActionCollection InputCollection
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_inputCollection == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_inputCollection = value;
|
|
||||||
UpdateBindings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InputAction actionReference = null;
|
|
||||||
|
|
||||||
public VariableMovementWithState(VMAsset asset, IInputActionCollection inputCollection)
|
|
||||||
{
|
|
||||||
InputCollection = inputCollection;
|
|
||||||
Asset = asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Cancelled(InputAction.CallbackContext obj) => Enabled = false;
|
|
||||||
protected void Performed(InputAction.CallbackContext obj) => Enabled = true;
|
|
||||||
|
|
||||||
protected void UpdateBindings()
|
|
||||||
{
|
|
||||||
if (actionReference != null)
|
|
||||||
{
|
|
||||||
actionReference.performed -= Performed;
|
|
||||||
actionReference.canceled -= Cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_inputCollection != null)
|
|
||||||
foreach (InputAction action in _inputCollection)
|
|
||||||
if (action.name == Asset.ActionReference)
|
|
||||||
{
|
|
||||||
actionReference = action;
|
|
||||||
actionReference.performed += Performed;
|
|
||||||
actionReference.canceled += Cancelled;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 95216561eb395f54596b439538c1c691
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in New Issue