Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 0e37e80

Browse files
committed
Add sibling index input to transform tree cells
1 parent 621a9cd commit 0e37e80

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/UI/Widgets/TransformTree/CachedTransform.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class CachedTransform
1717
public int ChildCount { get; internal set; }
1818
public string Name { get; internal set; }
1919
public bool Enabled { get; internal set; }
20+
public int SiblingIndex { get; internal set; }
2021

2122
public bool Expanded => Tree.IsCellExpanded(InstanceID);
2223

@@ -26,27 +27,32 @@ public CachedTransform(TransformTree tree, Transform transform, int depth, Cache
2627
Value = transform;
2728
Parent = parent;
2829
InstanceID = transform.GetInstanceID();
30+
SiblingIndex = transform.GetSiblingIndex();
2931
Update(transform, depth);
3032
}
3133

3234
public bool Update(Transform transform, int depth)
3335
{
34-
bool ret = false;
36+
bool changed = false;
3537

3638
if (Value != transform
3739
|| depth != Depth
3840
|| ChildCount != transform.childCount
3941
|| Name != transform.name
40-
|| Enabled != transform.gameObject.activeSelf)
42+
|| Enabled != transform.gameObject.activeSelf
43+
|| SiblingIndex != transform.GetSiblingIndex())
4144
{
45+
changed = true;
46+
4247
Value = transform;
4348
Depth = depth;
4449
ChildCount = transform.childCount;
4550
Name = transform.name;
4651
Enabled = transform.gameObject.activeSelf;
47-
ret = true;
52+
SiblingIndex = transform.GetSiblingIndex();
4853
}
49-
return ret;
54+
55+
return changed;
5056
}
5157
}
5258
}

src/UI/Widgets/TransformTree/TransformCell.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using UniverseLib.UI.Models;
1414
using UniverseLib.UI.Widgets;
1515
using UniverseLib.UI.Widgets.ScrollView;
16+
using UniverseLib.Utility;
1617

1718
namespace UnityExplorer.UI.Widgets
1819
{
@@ -36,6 +37,7 @@ public class TransformCell : ICell
3637
public ButtonRef ExpandButton;
3738
public ButtonRef NameButton;
3839
public Toggle EnabledToggle;
40+
public InputFieldRef SiblingIndex;
3941

4042
public LayoutElement spacer;
4143

@@ -77,6 +79,9 @@ public void ConfigureCell(CachedTransform cached, int cellIndex)
7779

7880
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
7981

82+
if (!SiblingIndex.Component.isFocused)
83+
SiblingIndex.Text = cached.Value.GetSiblingIndex().ToString();
84+
8085
int childCount = cached.Value.childCount;
8186
if (childCount > 0)
8287
{
@@ -118,6 +123,17 @@ private void OnEnableClicked(bool value)
118123
OnEnableToggled?.Invoke(cachedTransform);
119124
}
120125

126+
private void OnSiblingIndexEndEdit(string input)
127+
{
128+
if (this.cachedTransform == null || !this.cachedTransform.Value)
129+
return;
130+
131+
if (int.TryParse(input.Trim(), out int index))
132+
this.cachedTransform.Value.SetSiblingIndex(index);
133+
134+
this.SiblingIndex.Text = this.cachedTransform.Value.GetSiblingIndex().ToString();
135+
}
136+
121137
public GameObject CreateContent(GameObject parent)
122138
{
123139
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
@@ -152,10 +168,22 @@ public GameObject CreateContent(GameObject parent)
152168
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
153169
nameLabel.alignment = TextAnchor.MiddleLeft;
154170

155-
Color normal = new Color(0.11f, 0.11f, 0.11f);
156-
Color highlight = new Color(0.25f, 0.25f, 0.25f);
157-
Color pressed = new Color(0.05f, 0.05f, 0.05f);
158-
Color disabled = new Color(1, 1, 1, 0);
171+
// Sibling index input
172+
173+
SiblingIndex = UIFactory.CreateInputField(this.UIRoot, "SiblingIndexInput", string.Empty);
174+
SiblingIndex.Component.textComponent.fontSize = 11;
175+
SiblingIndex.Component.textComponent.alignment = TextAnchor.MiddleRight;
176+
var siblingImage = SiblingIndex.GameObject.GetComponent<Image>();
177+
siblingImage.color = new(0f, 0f, 0f, 0.25f);
178+
UIFactory.SetLayoutElement(SiblingIndex.GameObject, 35, 20, 0, 0);
179+
SiblingIndex.Component.GetOnEndEdit().AddListener(OnSiblingIndexEndEdit);
180+
181+
// Setup selectables
182+
183+
Color normal = new(0.11f, 0.11f, 0.11f);
184+
Color highlight = new(0.25f, 0.25f, 0.25f);
185+
Color pressed = new(0.05f, 0.05f, 0.05f);
186+
Color disabled = new(1, 1, 1, 0);
159187
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
160188
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
161189

0 commit comments

Comments
 (0)