// Animancer // https://kybernetik.com.au/animancer // Copyright 2021 Kybernetik // #if UNITY_EDITOR using System; using UnityEditor; using UnityEngine; namespace Animancer.Editor { partial class AnimancerToolsWindow { /// [Editor-Only] [Pro-Only] A base for modifying s. /// /// Documentation: Animancer Tools /// /// https://kybernetik.com.au/animancer/api/Animancer.Editor/AnimationModifierPanel /// [Serializable] public abstract class AnimationModifierPanel : Panel { /************************************************************************************************************************/ [SerializeField] private AnimationClip _Animation; /// The currently selected asset. public AnimationClip Animation => _Animation; /************************************************************************************************************************/ /// public override void OnEnable(int index) { base.OnEnable(index); OnAnimationChanged(); } /************************************************************************************************************************/ /// public override void OnSelectionChanged() { if (Selection.activeObject is AnimationClip animation) { _Animation = animation; OnAnimationChanged(); } } /************************************************************************************************************************/ /// Called whenever the selected changes. protected virtual void OnAnimationChanged() { } /************************************************************************************************************************/ /// public override void DoBodyGUI() { BeginChangeCheck(); var animation = (AnimationClip)EditorGUILayout.ObjectField("Animation", _Animation, typeof(AnimationClip), false); if (EndChangeCheck(ref _Animation, animation)) OnAnimationChanged(); } /************************************************************************************************************************/ /// Calls on the animation. protected bool SaveAs() { AnimancerGUI.Deselect(); if (SaveModifiedAsset( "Save Modified Animation", "Where would you like to save the new animation?", _Animation, Modify)) { _Animation = null; OnAnimationChanged(); return true; } else return false; } /************************************************************************************************************************/ /// Override this to apply the desired modifications to the `animation` before it is saved. protected virtual void Modify(AnimationClip animation) { } /************************************************************************************************************************/ } } } #endif