屏幕问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.SystemEditor
|
||||
@@ -22,6 +22,38 @@ namespace AibisDream.SystemEditor
|
||||
return TransIdx2SortingLayer(newIdx);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用 SerializedProperty 绘制 SortingLayer 下拉菜单(基于ID)
|
||||
/// </summary>
|
||||
/// <param name="label">显示的标签</param>
|
||||
/// <param name="property">存储排序层ID的 SerializedProperty(int 类型)</param>
|
||||
public static void SortingLayerField(GUIContent label, SerializedProperty property)
|
||||
{
|
||||
if (property == null || property.propertyType != SerializedPropertyType.Integer)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Property must be an integer type for sorting layer ID.", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// 获取所有排序层名称
|
||||
string[] sortingLayerNames = GetSortingLayerNames();
|
||||
// 将当前ID转为索引
|
||||
int currentId = property.intValue;
|
||||
int currentIndex = TransSortingLayer2Idx(currentId);
|
||||
|
||||
// 显示下拉菜单
|
||||
int newIndex = EditorGUILayout.Popup(label, currentIndex, sortingLayerNames);
|
||||
|
||||
// 如果选择了新的排序层,更新属性值为新的ID
|
||||
if (EditorGUI.EndChangeCheck() || newIndex != currentIndex)
|
||||
{
|
||||
int newId = TransIdx2SortingLayer(newIndex);
|
||||
property.intValue = newId;
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] GetSortingLayerNames()
|
||||
{
|
||||
// 获取所有 Sorting Layer 名称
|
||||
|
||||
Reference in New Issue
Block a user