ProjectDDD/Packages/SLUnity/Editor/SLUI/SLUIInputFieldEditor.cs

82 lines
2.8 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace Superlazy.UI
{
[CanEditMultipleObjects]
[CustomEditor(typeof(SLUIInputField))]
public class SLUIInputFieldEditor : Editor
{
private SLUIInputField component;
private string[] methods;
private static string filter;
private void OnEnable()
{
component = target as SLUIInputField;
methods = SLUIEditorUtil.GetAllCommands();
}
public override void OnInspectorGUI()
{
if (component.bindParent == null)
{
EditorGUILayout.LabelField("Can't find session Entity");
}
else
{
component.bindingValue = EditorGUILayout.TextField("Binding Value", component.bindingValue);
component.isNumber = EditorGUILayout.Toggle("Is Number", component.isNumber);
component.useChangeValue = EditorGUILayout.Toggle("Use ChangeValue", component.useChangeValue);
if (component.useChangeValue)
{
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();
}
var currMethod = Array.FindIndex(filterMethods, 0, methodName => methodName == component.changeCommand);
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Change Command : " + component.changeCommand);
var newMethod = EditorGUILayout.Popup(currMethod, filterMethods);
if (newMethod > 0)
{
component.changeCommand = filterMethods[newMethod];
}
else
{
component.changeCommand = "";
}
}
EditorGUILayout.EndHorizontal();
}
else
{
component.changeCommand = "";
}
if (component.comparison == null) component.comparison = new SLValueComparison();
component.comparison.OnInspector(component.bindParent);
}
component.ViewEntity();
if (GUI.changed && Application.isPlaying == false)
{
EditorUtility.SetDirty(component);
EditorSceneManager.MarkAllScenesDirty();
}
}
}
}