using System; using System.Linq; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; namespace Superlazy.UI { [CanEditMultipleObjects] [CustomEditor(typeof(SLUIEntity))] public class SLUIEntityEditor : Editor { private SLUIEntity component; private static string filter; private static string[] methods; private void OnEnable() { component = target as SLUIEntity; methods = SLUIEditorUtil.GetAllCommands(); } public override void OnInspectorGUI() { BindCheck(); component.useOnOff = EditorGUILayout.Toggle("Use On Off", component.useOnOff); if (component.useOnOff) { if (component.comparison == null) component.comparison = new SLValueComparison(); component.comparison.OnInspector(component); 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.onCommand); var newMethod = EditorGUILayout.Popup("Turn On : " + component.onCommand, currMethod, filterMethods); if (newMethod > 0) { component.onCommand = filterMethods[newMethod]; } else { component.onCommand = ""; } } { var currMethod = Array.FindIndex(filterMethods, 0, methodName => methodName == component.offCommand); var newMethod = EditorGUILayout.Popup("Turn Off : " + component.offCommand, currMethod, filterMethods); if (newMethod > 0) { component.offCommand = filterMethods[newMethod]; } else { component.offCommand = ""; } } } component.ViewEntity(); if (GUI.changed && Application.isPlaying == false) { EditorUtility.SetDirty(component); EditorSceneManager.MarkAllScenesDirty(); } } public void BindCheck() { EditorGUILayout.LabelField("Bind :" + component.BindPath); var parent = component.transform.parent?.GetComponentInParent(); component.inherit = EditorGUILayout.Toggle("Use Inherit : " + parent?.BindPath, component.inherit); if (parent != null) { component.bindParent = parent; } else { component.bindParent = null; } if (component.inherit) { EditorGUILayout.ObjectField("Inherit", component.bindParent, typeof(SLUIObjectOnOff), false); } if (component.bindParent == null) // no inherit { component.bind = EditorGUILayout.TextField("Bind", component.bind); } else if (component.bindParent is SLUIList) // list inherit { if (Application.isPlaying == false) { if (component.inherit == false || component.bind != "[~]" || component.useOnOff) { EditorUtility.SetDirty(component); } component.inherit = true; component.bind = "[~]"; component.useOnOff = false; } } else // entity inherit { component.bind = EditorGUILayout.TextField("Bind", component.bind); } } } }