92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.FrameAnimation.Editor
|
|
{
|
|
[CustomEditor(typeof(FrameAnimationPlayer))]
|
|
public sealed class FrameAnimationPlayerEditor : UnityEditor.Editor
|
|
{
|
|
private SerializedProperty graphProperty;
|
|
private SerializedProperty playOnEnableProperty;
|
|
private SerializedProperty speedProperty;
|
|
|
|
private void OnEnable()
|
|
{
|
|
graphProperty = serializedObject.FindProperty("graph");
|
|
playOnEnableProperty = serializedObject.FindProperty("playOnEnable");
|
|
speedProperty = serializedObject.FindProperty("speed");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
EditorGUILayout.PropertyField(graphProperty);
|
|
EditorGUILayout.PropertyField(playOnEnableProperty);
|
|
EditorGUILayout.PropertyField(speedProperty);
|
|
|
|
DrawConfigurationWarnings();
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
if (Application.isPlaying)
|
|
{
|
|
DrawRuntimeState();
|
|
}
|
|
}
|
|
|
|
private void DrawConfigurationWarnings()
|
|
{
|
|
var player = (FrameAnimationPlayer)target;
|
|
var spriteRenderer = player.GetComponent<SpriteRenderer>();
|
|
var image = player.GetComponent<Image>();
|
|
|
|
if (player.GetComponent<FrameClipPlayer>() != null)
|
|
{
|
|
EditorGUILayout.HelpBox(
|
|
"同一 GameObject 不能同时包含 FrameAnimationPlayer 和 FrameClipPlayer。",
|
|
MessageType.Error);
|
|
}
|
|
|
|
if (spriteRenderer == null && image == null)
|
|
{
|
|
EditorGUILayout.HelpBox(
|
|
"同一 GameObject 上必须存在一个 SpriteRenderer 或 Image。",
|
|
MessageType.Error);
|
|
}
|
|
else if (spriteRenderer != null && image != null)
|
|
{
|
|
EditorGUILayout.HelpBox(
|
|
"同一 GameObject 不能同时存在 SpriteRenderer 和 Image。",
|
|
MessageType.Error);
|
|
}
|
|
|
|
if (graphProperty.objectReferenceValue == null)
|
|
{
|
|
EditorGUILayout.HelpBox("尚未绑定 FrameAnimationGraph。", MessageType.Error);
|
|
}
|
|
|
|
if (!FrameAnimationValueUtility.IsValidSpeed(speedProperty.floatValue))
|
|
{
|
|
EditorGUILayout.HelpBox("Speed 必须是有限且不小于 0 的数值。", MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private void DrawRuntimeState()
|
|
{
|
|
var player = (FrameAnimationPlayer)target;
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.LabelField("Runtime State", EditorStyles.boldLabel);
|
|
using (new EditorGUI.DisabledScope(true))
|
|
{
|
|
EditorGUILayout.EnumPopup("State", player.State);
|
|
EditorGUILayout.TextField("Playable", player.CurrentPlayableId);
|
|
EditorGUILayout.TextField("Clip", player.CurrentClipId);
|
|
EditorGUILayout.TextField("Node", player.CurrentNodeId);
|
|
EditorGUILayout.IntField("Frame", player.CurrentFrameIndex);
|
|
}
|
|
|
|
Repaint();
|
|
}
|
|
}
|
|
}
|