141 lines
3.9 KiB
C#
141 lines
3.9 KiB
C#
using AlicizaX.UI.Runtime;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace AlicizaX.UI.Editor
|
|
{
|
|
[CustomEditor(typeof(UIPresetTransition))]
|
|
internal sealed class UIPresetTransitionInspector : UnityEditor.Editor
|
|
{
|
|
private enum PreviewMode
|
|
{
|
|
Open,
|
|
Close,
|
|
}
|
|
|
|
private UIPresetTransition _transition;
|
|
private PreviewMode _previewMode = PreviewMode.Open;
|
|
private float _previewProgress = 1f;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_transition = (UIPresetTransition)target;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
StopPreview();
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
EditorGUI.BeginChangeCheck();
|
|
DrawDefaultInspector();
|
|
bool inspectorChanged = EditorGUI.EndChangeCheck();
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
EditorGUILayout.Space();
|
|
DrawPreviewGUI();
|
|
|
|
if (inspectorChanged && _transition != null && _transition.EditorHasActivePreview())
|
|
{
|
|
ApplyPreview();
|
|
}
|
|
}
|
|
|
|
private void DrawPreviewGUI()
|
|
{
|
|
EditorGUILayout.LabelField("Editor Preview", EditorStyles.boldLabel);
|
|
|
|
if (targets.Length != 1)
|
|
{
|
|
EditorGUILayout.HelpBox("Preview is available when a single UIPresetTransition is selected.", MessageType.Info);
|
|
return;
|
|
}
|
|
|
|
if (EditorApplication.isPlayingOrWillChangePlaymode)
|
|
{
|
|
EditorGUILayout.HelpBox("Preset preview is only available in edit mode.", MessageType.Info);
|
|
return;
|
|
}
|
|
|
|
EditorGUILayout.HelpBox("Preview scrubs the selected transition in edit mode and restores automatically when this inspector closes.", MessageType.None);
|
|
|
|
EditorGUI.BeginChangeCheck();
|
|
_previewMode = (PreviewMode)EditorGUILayout.EnumPopup("Transition", _previewMode);
|
|
_previewProgress = EditorGUILayout.Slider("Progress", _previewProgress, 0f, 1f);
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
ApplyPreview();
|
|
}
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
if (GUILayout.Button("At Start"))
|
|
{
|
|
_previewProgress = 0f;
|
|
ApplyPreview();
|
|
}
|
|
|
|
if (GUILayout.Button("At End"))
|
|
{
|
|
_previewProgress = 1f;
|
|
ApplyPreview();
|
|
}
|
|
|
|
if (GUILayout.Button("Restore"))
|
|
{
|
|
StopPreview();
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
if (GUILayout.Button("Preview Open"))
|
|
{
|
|
_previewMode = PreviewMode.Open;
|
|
_previewProgress = 1f;
|
|
ApplyPreview();
|
|
}
|
|
|
|
if (GUILayout.Button("Preview Close"))
|
|
{
|
|
_previewMode = PreviewMode.Close;
|
|
_previewProgress = 1f;
|
|
ApplyPreview();
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
private void ApplyPreview()
|
|
{
|
|
if (_transition == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_previewMode == PreviewMode.Open)
|
|
{
|
|
_transition.EditorPreviewOpen(_previewProgress);
|
|
}
|
|
else
|
|
{
|
|
_transition.EditorPreviewClose(_previewProgress);
|
|
}
|
|
|
|
SceneView.RepaintAll();
|
|
Repaint();
|
|
}
|
|
|
|
private void StopPreview()
|
|
{
|
|
if (_transition == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_transition.EditorStopPreview();
|
|
SceneView.RepaintAll();
|
|
}
|
|
}
|
|
}
|