-
Notifications
You must be signed in to change notification settings - Fork 0
/
SYHierarchyOrganizing.cs
44 lines (41 loc) · 1.34 KB
/
SYHierarchyOrganizing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections.Generic;
using System.Linq;
using JSchool.Modules.Common.LCH.Attributes;
using UnityEngine;
namespace JSchool.SYLab
{
public class SYHierarchyOrganizing : MonoBehaviour
{
public Transform[] targets;
[ShowInInspector]
public void DoOrganizing()
{
foreach (var target in targets)
{
List<Transform> childs = new List<Transform>();
for (int i = 0; i < target.childCount; i++)
childs.Add(target.GetChild(i));
childs = childs.OrderBy(x => x.name.Length).ToList();
for (int i = 0; i < childs.Count; i++)
{
int index2 = 0;
while (index2 < childs.Count)
{
if (childs[i].Equals(childs[index2]))
{
index2++;
continue;
}
if (childs[index2].name.Contains(childs[i].name))
{
childs[index2].SetParent(childs[i]);
childs.RemoveAt(index2);
}
else
index2++;
}
}
}
}
}
}