// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
#if UNITY_EDITOR
using UnityEngine;
namespace Animancer.Editor
{
/// [Editor-Only] Draws a custom GUI for an object.
///
/// Every non-abstract type implementing this interface must have at least one .
///
/// https://kybernetik.com.au/animancer/api/Animancer.Editor/ICustomGUI
///
public interface ICustomGUI
{
/************************************************************************************************************************/
/// The optional label to draw in front of the field.
GUIContent Label { get; set; }
/// The target object for which this GUI will be drawn.
object Value { get; set; }
/// Draws the GUI for the .
void DoGUI();
/************************************************************************************************************************/
}
/// [Editor-Only] Draws a custom GUI for an object.
///
/// Every non-abstract type inheriting from this class must have at least one .
///
/// https://kybernetik.com.au/animancer/api/Animancer.Editor/CustomGUI_1
///
public abstract class CustomGUI : ICustomGUI
{
/************************************************************************************************************************/
/// The object for which this GUI will be drawn.
public T Value { get; protected set; }
///
object ICustomGUI.Value
{
get => Value;
set => Value = (T)value;
}
/************************************************************************************************************************/
///
public GUIContent Label { get; set; } = GUIContent.none;
/************************************************************************************************************************/
///
public abstract void DoGUI();
/************************************************************************************************************************/
}
/// [Editor-Only] Extension methods for .
/// https://kybernetik.com.au/animancer/api/Animancer.Editor/CustomGUIExtensions
///
public static class CustomGUIExtensions
{
/************************************************************************************************************************/
/// Sets the .
public static void SetLabel(
this ICustomGUI customGUI,
string text,
string tooltip = null,
Texture image = null)
{
var label = customGUI.Label;
if (label == null || label == GUIContent.none)
customGUI.Label = label = new(text);
label.text = text;
label.tooltip = tooltip;
label.image = image;
}
/************************************************************************************************************************/
}
}
#endif