using System; using Stary.Evo.Editor; using UnityEditor; using UnityEngine; namespace Stary.Evo { [CustomEditor(typeof(HybridClREntrance))] public class HybridClREntranceEditor : UnityEditor.Editor { /// /// 序列化属性,在OnEnable中获取 /// [HideInInspector] private SerializedProperty domain; private SerializedProperty stage; /// /// 序列化属性,在OnEnable中获取 /// [HideInInspector] private SerializedProperty loadDomain; private string[] domainNames; private string[] artNames; private string[] loadDomainNames; private async void OnEnable() { domain = serializedObject.FindProperty("domain"); loadDomain = serializedObject.FindProperty("loadDomain"); stage = serializedObject.FindProperty("stage"); domainNames = CreatAssetWindow.GetCreatDomainAllName(); artNames = await ArtLoadAssetServer.GetServerDomainAllName(); // 创建新数组,长度+1并在第0位插入null // 创建新数组,长度+1并在第0位插入null loadDomainNames = new string[domainNames.Length + 1]; loadDomainNames[0] = "null"; // 第0位添加null Array.Copy(domainNames, 0, loadDomainNames, 1, domainNames.Length); // 复制原始元素到新数组从索引1开始 } public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(stage, new GUIContent("Stage")); // 在 HybridClREntranceEditor 类的 OnInspectorGUI 方法中 StageType currentStage = (StageType)stage.enumValueIndex; EditorGUILayout.Space(); string[] current = currentStage == StageType.Developer ? domainNames : artNames; if (current != null && current.Length > 0) { // 获取当前选中的索引 int selectedIndex = System.Array.IndexOf(current, domain.stringValue); if (selectedIndex < 0) selectedIndex = 0; // 默认选中第一个 // 绘制下拉选择框 selectedIndex = EditorGUILayout.Popup("Domain", selectedIndex, current); // 更新选择的域名 domain.stringValue = current[selectedIndex]; } HybridClREntrance hybridClREntrance = target as HybridClREntrance; if (GUILayout.Button("打开Domain")) { hybridClREntrance.OpenDomain(); } if (GUILayout.Button("关闭Domain")) { hybridClREntrance.CloseDomain(); } //loaddoamin绘制 // 获取当前选中的索引 if (currentStage == StageType.Developer && loadDomainNames != null && loadDomainNames.Length > 1) { int loadDomainSelectedIndex = System.Array.IndexOf(loadDomainNames, loadDomain.stringValue); if (loadDomainSelectedIndex < 0) loadDomainSelectedIndex = 0; // 默认选中第一个 // 绘制下拉选择框 loadDomainSelectedIndex = EditorGUILayout.Popup("LoadDomain", loadDomainSelectedIndex, loadDomainNames); // 更新选择的域名 loadDomain.stringValue = loadDomainNames[loadDomainSelectedIndex]; } serializedObject.ApplyModifiedProperties(); } } }