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

95 lines
3.4 KiB
C#

using System;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace Superlazy.UI
{
[CanEditMultipleObjects]
[CustomEditor(typeof(SLUIButton))]
public class SLUIButtonEditor : Editor
{
private SLUIButton component;
private string[] methods;
private static string filter;
private void OnEnable()
{
component = target as SLUIButton;
methods = SLUIEditorUtil.GetAllCommands();
}
public override void OnInspectorGUI()
{
if (component.button != null)
{
UnityEngine.Events.UnityAction p = component.ButtonAction;
UnityEditor.Events.UnityEventTools.RemovePersistentListener(component.button.onClick, p);
}
if (component.bindParent == null)
{
EditorGUILayout.LabelField("Can't find session Entity");
}
else
{
EditorGUILayout.LabelField("SessionEntity : " + component.bindParent.BindPath);
}
filter = EditorGUILayout.TextField("Binding Command Filter", filter);
var filterMethods = methods;
if (string.IsNullOrEmpty(filter) == false)
{
filterMethods = methods.Where(name => name.ToLower().Contains(filter.ToLower())).ToArray();
}
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Binding Command : " + component.command);
var currMethod = Array.FindIndex(filterMethods, methodName => methodName == component.command);
currMethod = currMethod < 0 ? 0 : currMethod; // None 표기용
var newMethod = EditorGUILayout.Popup(currMethod, filterMethods);
if (newMethod > 0)
{
component.command = filterMethods[newMethod];
}
else
{
component.command = "";
}
}
EditorGUILayout.EndHorizontal();
if (component.comparison == null) component.comparison = new SLValueComparison();
if (component.bindParent) component.comparison.OnInspector(component.bindParent);
if (component.comparison.useCheckValue)
{
component.useGrayScale = EditorGUILayout.Toggle("Use GrayScale Disable", component.useGrayScale);
}
component.focus = EditorGUILayout.Toggle("focus", component.focus);
if (string.IsNullOrEmpty(component.focusBind) == false) EditorGUILayout.LabelField($"focus bind{component.bindParent.BindPath}.{component.focusBind}");
component.focusBind = EditorGUILayout.TextField("focus bind", component.focusBind);
component.selectIsHover = EditorGUILayout.Toggle("Select is hover", component.selectIsHover);
component.fastClick = EditorGUILayout.Toggle("fast click", component.fastClick);
component.clickSound = EditorGUILayout.TextField("click sound", component.clickSound);
component.ViewEntity();
if (GUI.changed && Application.isPlaying == false)
{
EditorUtility.SetDirty(component);
EditorSceneManager.MarkAllScenesDirty();
}
}
}
}