Sprite群组编辑器

This commit is contained in:
2025-03-05 14:13:33 +08:00
parent c640f79c09
commit 49bfc8e3de
57 changed files with 8355 additions and 160 deletions
+58
View File
@@ -0,0 +1,58 @@
using UnityEditor;
using UnityEngine;
namespace AibisDream.SystemEditor
{
public static class EditorKit
{
public static readonly GUIStyle BoldFont = new(EditorStyles.label)
{
fontStyle = FontStyle.Bold
};
public static int SortingLayerField(string label, int id)
{
// 先获取layer
var layers = GetSortingLayerNames();
// 将ID转为idx
var idx = TransSortingLayer2Idx(id);
var newIdx = EditorGUILayout.Popup(label, idx, layers);
return TransIdx2SortingLayer(newIdx);
}
private static string[] GetSortingLayerNames()
{
// 获取所有 Sorting Layer 名称
var layerCount = SortingLayer.layers.Length;
var sortingLayerNames = new string[layerCount];
for (var i = 0; i < layerCount; i++)
{
sortingLayerNames[i] = SortingLayer.layers[i].name;
}
return sortingLayerNames;
}
private static int TransSortingLayer2Idx(int id)
{
var layers = SortingLayer.layers;
for (var i = 0; i < layers.Length; i++)
{
if (layers[i].id == id) return i;
}
return 0;
}
private static int TransIdx2SortingLayer(int idx)
{
if (idx < 0 || idx >= SortingLayer.layers.Length)
{
return SortingLayer.layers[0].id;
}
return SortingLayer.layers[idx].id;
}
}
}