// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // #if UNITY_EDITOR using System; using UnityEditor; using UnityEngine; namespace Animancer.Editor { /// [Editor-Only] Draws the Inspector GUI for an . /// https://kybernetik.com.au/animancer/api/Animancer.Editor/ParametizedAnimancerStateDrawer_1 /// public abstract class ParametizedAnimancerStateDrawer : AnimancerStateDrawer where T : AnimancerState { /************************************************************************************************************************/ /// The number of parameters being managed by the target state. public virtual int ParameterCount => 0; /// Returns the name of a parameter being managed by the target state. /// The target state doesn't manage any parameters. public virtual string GetParameterName(int index) => throw new NotSupportedException(); /// Returns the type of a parameter being managed by the target state. /// The target state doesn't manage any parameters. public virtual AnimatorControllerParameterType GetParameterType(int index) => throw new NotSupportedException(); /// Returns the value of a parameter being managed by the target state. /// The target state doesn't manage any parameters. public virtual object GetParameterValue(int index) => throw new NotSupportedException(); /// Sets the value of a parameter being managed by the target state. /// The target state doesn't manage any parameters. public virtual void SetParameterValue(int index, object value) => throw new NotSupportedException(); /************************************************************************************************************************/ /// /// Creates a new to manage the Inspector GUI for the `state`. /// protected ParametizedAnimancerStateDrawer(T state) : base(state) { } /************************************************************************************************************************/ /// protected override void DoDetailsGUI() { base.DoDetailsGUI(); if (!IsExpanded) return; var count = ParameterCount; if (count <= 0) return; var labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth -= AnimancerGUI.IndentSize; for (int i = 0; i < count; i++) { var type = GetParameterType(i); if (type == 0) continue; var name = GetParameterName(i); var value = GetParameterValue(i); EditorGUI.BeginChangeCheck(); var area = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before); area = EditorGUI.IndentedRect(area); switch (type) { case AnimatorControllerParameterType.Float: value = EditorGUI.FloatField(area, name, (float)value); break; case AnimatorControllerParameterType.Int: value = EditorGUI.IntField(area, name, (int)value); break; case AnimatorControllerParameterType.Bool: value = EditorGUI.Toggle(area, name, (bool)value); break; case AnimatorControllerParameterType.Trigger: value = EditorGUI.Toggle(area, name, (bool)value, EditorStyles.radioButton); break; default: EditorGUI.LabelField(area, name, "Unsupported Type: " + type); break; } if (EditorGUI.EndChangeCheck()) SetParameterValue(i, value); } EditorGUIUtility.labelWidth = labelWidth; } /************************************************************************************************************************/ } } #endif