forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHierarchyTraversal.cs
More file actions
37 lines (31 loc) · 1.19 KB
/
HierarchyTraversal.cs
File metadata and controls
37 lines (31 loc) · 1.19 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
namespace UnityEngine.UIElements.StyleSheets
{
// Utility class to abstract away the concerne of traversing the visual tree
internal abstract class HierarchyTraversal
{
public virtual void Traverse(VisualElement element)
{
TraverseRecursive(element, 0);
}
// Subclasses are responsible for calling Recurse() on the element
public abstract void TraverseRecursive(VisualElement element, int depth);
protected void Recurse(VisualElement element, int depth)
{
int i = 0;
while (i < element.hierarchy.childCount)
{
var child = element.hierarchy[i];
TraverseRecursive(child, depth + 1);
// if the child has been moved to another parent, which happens when its parent has changed, then do not increment the iterator
if (child.hierarchy.parent != element)
continue;
i++;
}
}
}
}