// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // #if UNITY_EDITOR using System; using UnityEditor; using UnityEngine; namespace Animancer.Editor { /// [Editor-Only] A static reference to a persistent setting stored in . /// https://kybernetik.com.au/animancer/api/Animancer.Editor/AnimancerSettingsGroup_1 public static class AnimancerSettingsGroup where T : AnimancerSettingsGroup, new() { /************************************************************************************************************************/ /// Gets or creates a in the asset. public static T Instance => AnimancerSettings.GetOrCreateData(); /************************************************************************************************************************/ } /// Base class for groups of fields that can be serialized inside . /// https://kybernetik.com.au/animancer/api/Animancer.Editor/AnimancerSettingsGroup [Serializable, InternalSerializableType] public abstract class AnimancerSettingsGroup : IComparable { /************************************************************************************************************************/ private int _DataIndex = -1; private string _BasePropertyPath; /************************************************************************************************************************/ /// The user-firendly name to display in the Inspector. public abstract string DisplayName { get; } /// The index to display this data at in the Inspector. public abstract int Index { get; } /************************************************************************************************************************/ /// Sets the index used to find instances for this group. internal void SetDataIndex(int index) { if (_DataIndex == index) return; _DataIndex = index; _BasePropertyPath = null; } /************************************************************************************************************************/ /// Returns a relative to the base of this group. protected SerializedProperty GetSerializedProperty(string propertyPath) => AnimancerSettings.GetSerializedProperty(_DataIndex, ref _BasePropertyPath, propertyPath); /************************************************************************************************************************/ /// /// Draws a for a /// property in this group. /// protected SerializedProperty DoPropertyField(string propertyPath) { var property = GetSerializedProperty(propertyPath); EditorGUILayout.PropertyField(property, true); return property; } /************************************************************************************************************************/ /// Compares the . public int CompareTo(AnimancerSettingsGroup other) => Index.CompareTo(other.Index); /************************************************************************************************************************/ } } #endif