using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using BF; namespace BFEditor { [CustomEditor(typeof(UIHelper))] public class UIHelperInspector : Editor { UIHelper helper; void OnEnable() { helper = target as UIHelper; } public override void OnInspectorGUI() { GUILayout.Space(5); DrawNotchScreenAdapterNode(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(2); DrawEffectList(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(2); } void DrawNotchScreenAdapterNode() { GUIStyle style = new GUIStyle(); style.fontSize = 14; // GUILayout.Label("需要适配刘海屏的节点", style, GUILayout.ExpandWidth(false)); // EditorGUI.BeginChangeCheck(); // GUILayout.BeginHorizontal(); // { // GameObject go = (GameObject)EditorGUILayout.ObjectField("", helper.NotchScreenNode, typeof(GameObject), true, GUILayout.Width(140)); // if (EditorGUI.EndChangeCheck()) // { // Undo.RecordObject(helper, helper.name + "Change NotchScreenAdapterNode"); // helper.NotchScreenNode = go; // EditorUtility.SetDirty(helper); // } // float adjust = EditorGUILayout.FloatField("附加偏移值(仅刘海屏有效)", helper.AdjustHeight); // if (helper.AdjustHeight != adjust) // { // Undo.RecordObject(helper, helper.name + "Change NotchScreenAdjustHeight"); // helper.AdjustHeight = adjust; // EditorUtility.SetDirty(helper); // } // GUILayout.FlexibleSpace(); // if (GUILayout.Button("刷新", GUILayout.Width(100))) // { // if (Application.isPlaying) { // if (SafeAreaManager.CheckIfSimulate()) // { // helper.FitNotchScreen(); // } // else{ // Debug.Log("请先在'游戏设置'菜单中打开异形屏模拟环境"); // } // } // else // { // Debug.Log("刷新功能仅在Editor运行时用于预览"); // } // } // GUILayout.FlexibleSpace(); // if (GUILayout.Button("Remove", GUILayout.Width(100))) // { // Undo.RecordObject(helper, helper.name + "Remove NotchScreenAdapterNode"); // helper.NotchScreenNode = null; // EditorUtility.SetDirty(helper); // } // } // GUILayout.EndHorizontal(); GUILayout.Label("需要适配刘海屏的节点列表:", style); // if (GUILayout.Button("刷新", GUILayout.Width(100))) // { // if (Application.isPlaying) { // if (SafeAreaManager.CheckIfSimulate()) // { // helper.FitNotchScreen(); // } // else{ // Debug.Log("请先在'游戏设置'菜单中打开异形屏模拟环境"); // } // } // else // { // Debug.Log("刷新功能仅在Editor运行时用于预览"); // } // } for (int index = 0; index < helper.NotchScreenNodeList.Count; ++ index) { GUILayout.BeginHorizontal(); { EditorGUI.BeginChangeCheck(); GameObject go = (GameObject)EditorGUILayout.ObjectField("", helper.NotchScreenNodeList[index].gameObject, typeof(GameObject), true, GUILayout.Width(140)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(helper, helper.name + "Change NotchScreenNode"); NotchScreenNode node = new NotchScreenNode(); node.gameObject = go; node.adjustHeight = helper.NotchScreenNodeList[index].adjustHeight; helper.NotchScreenNodeList[index] = node; EditorUtility.SetDirty(helper); } float adjust = EditorGUILayout.FloatField("附加偏移值(暂无效)", helper.NotchScreenNodeList[index].adjustHeight); if (helper.NotchScreenNodeList[index].adjustHeight != adjust) { Undo.RecordObject(helper, helper.name + "Change NotchScreenAdjustHeight"); NotchScreenNode node = new NotchScreenNode(); node.gameObject = helper.NotchScreenNodeList[index].gameObject; node.adjustHeight = adjust; helper.NotchScreenNodeList[index] = node; EditorUtility.SetDirty(helper); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", GUILayout.Width(100))) { Undo.RecordObject(helper, helper.name + "Remove NotchScreenNode"); EditorApplication.Beep(); helper.NotchScreenNodeList.RemoveAt(index); EditorUtility.SetDirty(helper); } } GUILayout.EndHorizontal(); } if (GUILayout.Button("Add")) { Undo.RecordObject(helper, helper.name + "Add NotchScreenNode Info"); EditorApplication.Beep(); helper.NotchScreenNodeList.Add(new NotchScreenNode()); EditorUtility.SetDirty(helper); } } void DrawEffectList() { GUIStyle style = new GUIStyle(); style.fontSize = 14; GUILayout.Label("需要排序的节点列表:", style); for (int i = 0; i < helper.EffectList.Count; ++i) { GUILayout.BeginHorizontal(); { EditorGUI.BeginChangeCheck(); BaseSortingOrderHelper go = (BaseSortingOrderHelper)EditorGUILayout.ObjectField("", helper.EffectList[i], typeof(BaseSortingOrderHelper), true, GUILayout.Width(140)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(helper, helper.name + "Change EffectObject"); helper.EffectList[i] = go; EditorUtility.SetDirty(helper); } if (go != null) { GUILayout.Label("GroupOrder:", EditorStyles.label, GUILayout.Width(70)); EditorGUI.BeginChangeCheck(); string newGroupOrder = GUILayout.TextField(helper.EffectList[i].GroupOrder.ToString(), GUILayout.Width(40)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(helper, helper.name + "Change EffectObject GroupOrder"); int order; if(int.TryParse(newGroupOrder, out order)){ helper.EffectList[i].GroupOrder = order; }else{ helper.EffectList[i].GroupOrder = 0; } EditorUtility.SetDirty(helper); } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", GUILayout.Width(80))) { Undo.RecordObject(helper, helper.name + "Remove EffectObject Info"); EditorApplication.Beep(); helper.EffectList.RemoveAt(i); EditorUtility.SetDirty(helper); } } GUILayout.EndHorizontal(); } if (GUILayout.Button("Add")) { Undo.RecordObject(helper, helper.name + "Add EffectObject Info"); EditorApplication.Beep(); helper.EffectList.Add(null); EditorUtility.SetDirty(helper); } } } }