ProjectDDD/Packages/SLUnity/Editor/SLUI/SLUIValueEditor.cs
2025-07-08 19:46:31 +09:00

135 lines
5.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace Superlazy.UI
{
[CanEditMultipleObjects]
[CustomEditor(typeof(SLUIValue))]
public class SLUIValueEditor : Editor
{
private SLUIValue component;
private void OnEnable()
{
component = target as SLUIValue;
}
public override void OnInspectorGUI()
{
if (component.bindParent == null)
{
EditorGUILayout.LabelField("Can't find session Entity");
}
else
{
EditorGUILayout.LabelField("Bind : " + component.bindParent.BindPath);
}
if (component.text != null)
{
component.useRaw = EditorGUILayout.Toggle("UseRaw", component.useRaw);
component.bindingValue = EditorGUILayout.TextField("Binding[Text]", component.bindingValue);
if (string.IsNullOrEmpty(component.bindingValue) == false)
{
component.gameObject.name = component.bindingValue;
}
if (component.useRaw == false)
{
component.prefix = EditorGUILayout.TextField("Prefix", component.prefix);
component.postfix = EditorGUILayout.TextField("Postfix", component.postfix);
component.userInput = EditorGUILayout.Toggle("User Input", component.userInput);
component.tagID ??= string.Empty;
var formats = new List<SLTag>();
formats.CreateInstanceList();
var optionSTRs = new List<string>(formats.Select(p => p.ToString() + "(" + p.Tag + ")"));
var currOption = formats.FindIndex(pair => pair.Tag == component.tagID);
var newOption = EditorGUILayout.Popup("TagOption", currOption, optionSTRs.ToArray());
component.tagID = formats.ElementAt(newOption).Tag;
}
component.ignoreColorTag = EditorGUILayout.Toggle("Ignore Color Tag", component.ignoreColorTag);
component.useUpdate = EditorGUILayout.Toggle("Use Update Value", component.useUpdate);
if (component.useUpdate)
{
component.useTypingEffect = false;
component.typingEndBind = string.Empty;
component.typingEndState = string.Empty;
component.startDelay = 0.2f;
component.delay = 0.03f;
}
else
{
component.useTypingEffect = EditorGUILayout.Toggle("Use Typing Effect", component.useTypingEffect);
if (component.useTypingEffect)
{
component.startDelay = EditorGUILayout.FloatField("Typing Effect Delay", component.startDelay);
component.delay = EditorGUILayout.FloatField("Typing Effect Duration", component.delay);
component.typingEndBind = EditorGUILayout.TextField("Typing End Bind", component.typingEndBind);
if (string.IsNullOrEmpty(component.typingEndState) == false)
{
EditorGUILayout.LabelField($"On Typing End : Session.UIState.{component.typingEndState} = true");
}
component.typingEndState = EditorGUILayout.TextField("Typing Effect EndState", component.typingEndState);
}
}
component.useSmoothing = EditorGUILayout.Toggle("Use Smoothing", component.useSmoothing);
if (component.useSmoothing)
{
component.smoothingDelay = EditorGUILayout.FloatField("Delay", component.smoothingDelay);
component.beforeSmoothingValue = EditorGUILayout.TextField("BeforeValue", component.beforeSmoothingValue);
}
}
else if (component.image != null)
{
component.bindingValue = EditorGUILayout.TextField("Binding[Image]", component.bindingValue);
var formats = new List<SLTag>();
formats.CreateInstanceList();
component.tagID ??= string.Empty;
var optionSTRs = new List<string>(formats.Select(p => p.ToString() + "(" + p.Tag + ")"));
var currOption = formats.FindIndex(pair => pair.Tag == component.tagID);
var newOption = EditorGUILayout.Popup("TagOption", currOption, optionSTRs.ToArray());
component.tagID = formats.ElementAt(newOption).Tag;
}
else if (component.slider != null)
{
component.bindingValue = EditorGUILayout.TextField("Bind Text[Current]", component.bindingValue);
component.bindingMaxValue = EditorGUILayout.TextField("Bind Text[Max]", component.bindingMaxValue);
component.useSmoothing = EditorGUILayout.Toggle("Use Smoothing", component.useSmoothing);
if (component.useSmoothing)
{
component.smoothingDelay = EditorGUILayout.FloatField("Delay", component.smoothingDelay);
}
}
else
{
EditorGUILayout.LabelField("Can't find UI Component");
}
component.ViewEntity();
if (GUI.changed && Application.isPlaying == false)
{
EditorUtility.SetDirty(component);
EditorSceneManager.MarkAllScenesDirty();
}
}
}
}