using System; using System.Collections; using System.Collections.Generic; using Gameplay; using Sirenix.OdinInspector.Editor; using UnityEditor; using UnityEditor.UI; using UnityEngine; using UnityEngine.UIElements; [CustomEditor(typeof(ShowComponent), true)] public class ShowComponentInspector : OdinEditor { private ShowComponent Target => target as ShowComponent; /// /// 角色演出点列表 /// private readonly List listCharacterShowPoint = new(); /// /// 道具演出点列表 /// private readonly List listItemShowPointRoot = new(); /// /// 记录上一次角色演出点根节点 /// private Transform lastCharacterShowPointRoot; /// /// 记录上一次道具演出点根节点 /// private Transform lastItemShowPointRoot; /// /// 角色演出点是否展开 /// private bool isCharacterFoldOut; /// /// 道具演出点是否展开 /// private bool isItemFoldOut; private GUIStyle style; private void InitGuiStyle() { if (style == null) { style = new(GUI.skin.label) { fontSize = 30, }; style.normal.textColor = Color.black; } } public override void OnInspectorGUI() { base.OnInspectorGUI(); RefreshShowPoint(); if (CommonUtils.IsInGame()) { GUI.enabled = false; EditorGUILayout.IntField("抽取目标数", Target.CharacterMaxCount); GUI.enabled = true; } isCharacterFoldOut = EditorGUILayout.Foldout(isCharacterFoldOut, $"角色演出点: ({listCharacterShowPoint.Count}个)"); if (isCharacterFoldOut) { foreach (Transform tsShowPoint in listCharacterShowPoint) { EditorGUILayout.LabelField(tsShowPoint.name); } } isItemFoldOut = EditorGUILayout.Foldout(isItemFoldOut, $"道具演出点:({listItemShowPointRoot.Count}个)"); if (isItemFoldOut) { foreach (Transform tsShowPoint in listItemShowPointRoot) { EditorGUILayout.LabelField(tsShowPoint.name); } } } private void OnSceneGUI() { InitGuiStyle(); int pointID = 1; Color oldColor = Handles.color; Handles.color = Color.red; foreach (Transform tsShowPoint in listCharacterShowPoint) { if (tsShowPoint) { Handles.DrawSolidDisc(tsShowPoint.position, Vector3.up, 0.2f); Handles.Label(tsShowPoint.position, $"{pointID}", style); } pointID++; } pointID = 1; Handles.color = Color.blue; foreach (Transform tsShowPoint in listItemShowPointRoot) { if (tsShowPoint) { Handles.DrawSolidDisc(tsShowPoint.position, Vector3.up, 0.2f); Handles.Label(tsShowPoint.position, $"{pointID}", style); } pointID++; } Handles.color = oldColor; } private void RefreshShowPoint() { if (lastCharacterShowPointRoot != Target.TsShowPointRoot) { lastCharacterShowPointRoot = Target.TsShowPointRoot; listCharacterShowPoint.Clear(); if (Target.TsShowPointRoot == null) return; for (int i = 0; i < Target.TsShowPointRoot.childCount; ++i) { listCharacterShowPoint.Add(Target.TsShowPointRoot.GetChild(i)); } } if (lastItemShowPointRoot != Target.TsItemShowPointRoot) { lastItemShowPointRoot = Target.TsItemShowPointRoot; listItemShowPointRoot.Clear(); if (Target.TsItemShowPointRoot == null) return; for (int i = 0; i < Target.TsItemShowPointRoot.childCount; ++i) { listItemShowPointRoot.Add(Target.TsItemShowPointRoot.GetChild(i)); } } } }