// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik //
#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEngine;
namespace Animancer.Editor.Tools
{
/// [Editor-Only] [Pro-Only]
/// A base for modifying s.
///
///
/// Documentation: Animancer Tools
///
/// https://kybernetik.com.au/animancer/api/Animancer.Editor.Tools/AnimationModifierTool
///
[Serializable]
public abstract class AnimationModifierTool : AnimancerToolsWindow.Tool
{
/************************************************************************************************************************/
[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()
{
AnimancerToolsWindow.BeginChangeCheck();
var animation = (AnimationClip)EditorGUILayout.ObjectField("Animation", _Animation, typeof(AnimationClip), false);
if (AnimancerToolsWindow.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