Files
plugin-library/Assets/00.StaryEvoTools/Editor/HybridClREntranceEditor.cs
2025-10-31 11:18:23 +08:00

95 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using Stary.Evo.Editor;
using UnityEditor;
using UnityEngine;
namespace Stary.Evo
{
[CustomEditor(typeof(HybridClREntrance))]
public class HybridClREntranceEditor : UnityEditor.Editor
{
/// <summary>
/// 序列化属性在OnEnable中获取
/// </summary>
[HideInInspector] private SerializedProperty domain;
private SerializedProperty stage;
/// <summary>
/// 序列化属性在OnEnable中获取
/// </summary>
[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)
{
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();
}
}
}