Files
Echo/Assets/_Project/Scripts/Tests/HierarchySorterTest.cs
T

51 lines
1.6 KiB
C#
Raw Normal View History

2026-07-08 19:53:15 +08:00
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using Test_2022.Utils;
namespace Test_2022.Tests
{
public class HierarchySorterTest
{
[MenuItem("Tools/Hierarchy/Test Sorting (Create Test Objects)")]
private static void CreateTestObjects()
{
GameObject parent = new GameObject("Test Parent");
string[] testNames = { "Zebra", "Apple", "Monkey", "Ball", "Cat", "Dog" };
foreach (string name in testNames)
{
GameObject child = new GameObject(name);
child.transform.SetParent(parent.transform);
}
Selection.activeGameObject = parent;
Debug.Log($"已创建测试对象:{parent.name},包含 {testNames.Length} 个子对象");
}
[MenuItem("Tools/Hierarchy/Test Sorting (Verify Order)")]
private static void VerifyTestObjects()
{
GameObject[] selectedObjects = Selection.gameObjects;
if (selectedObjects.Length == 0)
{
Debug.LogWarning("请先选择一个父对象进行测试!");
return;
}
foreach (GameObject parent in selectedObjects)
{
Debug.Log($"验证对象: {parent.name}");
for (int i = 0; i < parent.transform.childCount; i++)
{
Transform child = parent.transform.GetChild(i);
Debug.Log($" [{i}]: {child.name}");
}
}
}
}
}
#endif