78 lines
2.8 KiB
C#
78 lines
2.8 KiB
C#
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;
|
||
|
||
/// <summary>
|
||
/// 序列化属性,在OnEnable中获取
|
||
/// </summary>
|
||
[HideInInspector]
|
||
private SerializedProperty loadDomain;
|
||
private string[] domainNames;
|
||
|
||
private string[] loadDomainNames;
|
||
private void OnEnable()
|
||
{
|
||
domain = serializedObject.FindProperty("domain");
|
||
loadDomain = serializedObject.FindProperty("loadDomain");
|
||
domainNames = CreatAssetWindow.GetCreatDomainAllName();
|
||
|
||
// 创建新数组,长度+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();
|
||
|
||
// 获取当前选中的索引
|
||
int selectedIndex = System.Array.IndexOf(domainNames, domain.stringValue);
|
||
if (selectedIndex < 0) selectedIndex = 0; // 默认选中第一个
|
||
|
||
// 绘制下拉选择框
|
||
selectedIndex = EditorGUILayout.Popup("Domain", selectedIndex, domainNames);
|
||
|
||
// 更新选择的域名
|
||
domain.stringValue = domainNames[selectedIndex];
|
||
|
||
HybridClREntrance hybridClREntrance = target as HybridClREntrance;
|
||
if (GUILayout.Button("打开Domain"))
|
||
{
|
||
hybridClREntrance.OpenDomain();
|
||
}
|
||
if (GUILayout.Button("关闭Domain"))
|
||
{
|
||
hybridClREntrance.CloseDomain();
|
||
}
|
||
|
||
//loaddoamin绘制
|
||
// 获取当前选中的索引
|
||
|
||
|
||
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();
|
||
}
|
||
}
|
||
} |