using UnityEngine; namespace MalbersAnimations.Scriptables { /// Layer Scriptable Variable. Based on the Talk - Game Architecture with Scriptable Objects by Ryan Hipple [CreateAssetMenu(menuName = "Malbers Animations/Variables/Layer Mask", order = 2000)] public class LayerVar : ScriptableVar { /// The current value [SerializeField] private LayerMask value = 0; /// Value of the Layer Scriptable variable public virtual LayerMask Value { get => value; set { this.value = value; #if UNITY_EDITOR if (debug) Debug.Log($"{name} -> [ {value} ] ", this); #endif } } public static implicit operator int(LayerVar reference) => reference.Value; } [System.Serializable] public class LayerReference : ReferenceVar { public LayerMask ConstantValue = ~0; [RequiredField] public LayerVar Variable; public LayerReference() => Value = ~0; public LayerReference(LayerMask value) { UseConstant = true; Value = value; } public LayerReference(LayerVar value) { UseConstant = false; Value = value.Value; } public LayerMask Value { get => UseConstant || Variable == null ? ConstantValue : Variable.Value; set { if (UseConstant || Variable == null) ConstantValue = value; else Variable.Value = value; } } public static implicit operator int(LayerReference reference) => reference.Value; public static implicit operator LayerMask(LayerReference reference) => reference.Value; } #if UNITY_EDITOR [UnityEditor.CanEditMultipleObjects, UnityEditor.CustomEditor(typeof(LayerVar))] public class LayerVarEditor : VariableEditor { public override void OnInspectorGUI() { PaintInspectorGUI("LayerMask Variable"); } } #endif }