mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Add sibling index input to transform tree cells
This commit is contained in:
parent
621a9cd72e
commit
0e37e8030c
@ -17,6 +17,7 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
public int ChildCount { get; internal set; }
|
public int ChildCount { get; internal set; }
|
||||||
public string Name { get; internal set; }
|
public string Name { get; internal set; }
|
||||||
public bool Enabled { get; internal set; }
|
public bool Enabled { get; internal set; }
|
||||||
|
public int SiblingIndex { get; internal set; }
|
||||||
|
|
||||||
public bool Expanded => Tree.IsCellExpanded(InstanceID);
|
public bool Expanded => Tree.IsCellExpanded(InstanceID);
|
||||||
|
|
||||||
@ -26,27 +27,32 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
Value = transform;
|
Value = transform;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
InstanceID = transform.GetInstanceID();
|
InstanceID = transform.GetInstanceID();
|
||||||
|
SiblingIndex = transform.GetSiblingIndex();
|
||||||
Update(transform, depth);
|
Update(transform, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(Transform transform, int depth)
|
public bool Update(Transform transform, int depth)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool changed = false;
|
||||||
|
|
||||||
if (Value != transform
|
if (Value != transform
|
||||||
|| depth != Depth
|
|| depth != Depth
|
||||||
|| ChildCount != transform.childCount
|
|| ChildCount != transform.childCount
|
||||||
|| Name != transform.name
|
|| Name != transform.name
|
||||||
|| Enabled != transform.gameObject.activeSelf)
|
|| Enabled != transform.gameObject.activeSelf
|
||||||
|
|| SiblingIndex != transform.GetSiblingIndex())
|
||||||
{
|
{
|
||||||
|
changed = true;
|
||||||
|
|
||||||
Value = transform;
|
Value = transform;
|
||||||
Depth = depth;
|
Depth = depth;
|
||||||
ChildCount = transform.childCount;
|
ChildCount = transform.childCount;
|
||||||
Name = transform.name;
|
Name = transform.name;
|
||||||
Enabled = transform.gameObject.activeSelf;
|
Enabled = transform.gameObject.activeSelf;
|
||||||
ret = true;
|
SiblingIndex = transform.GetSiblingIndex();
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ using UniverseLib.UI;
|
|||||||
using UniverseLib.UI.Models;
|
using UniverseLib.UI.Models;
|
||||||
using UniverseLib.UI.Widgets;
|
using UniverseLib.UI.Widgets;
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.Widgets
|
namespace UnityExplorer.UI.Widgets
|
||||||
{
|
{
|
||||||
@ -36,6 +37,7 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
public ButtonRef ExpandButton;
|
public ButtonRef ExpandButton;
|
||||||
public ButtonRef NameButton;
|
public ButtonRef NameButton;
|
||||||
public Toggle EnabledToggle;
|
public Toggle EnabledToggle;
|
||||||
|
public InputFieldRef SiblingIndex;
|
||||||
|
|
||||||
public LayoutElement spacer;
|
public LayoutElement spacer;
|
||||||
|
|
||||||
@ -77,6 +79,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
||||||
|
|
||||||
|
if (!SiblingIndex.Component.isFocused)
|
||||||
|
SiblingIndex.Text = cached.Value.GetSiblingIndex().ToString();
|
||||||
|
|
||||||
int childCount = cached.Value.childCount;
|
int childCount = cached.Value.childCount;
|
||||||
if (childCount > 0)
|
if (childCount > 0)
|
||||||
{
|
{
|
||||||
@ -118,6 +123,17 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
OnEnableToggled?.Invoke(cachedTransform);
|
OnEnableToggled?.Invoke(cachedTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSiblingIndexEndEdit(string input)
|
||||||
|
{
|
||||||
|
if (this.cachedTransform == null || !this.cachedTransform.Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (int.TryParse(input.Trim(), out int index))
|
||||||
|
this.cachedTransform.Value.SetSiblingIndex(index);
|
||||||
|
|
||||||
|
this.SiblingIndex.Text = this.cachedTransform.Value.GetSiblingIndex().ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public GameObject CreateContent(GameObject parent)
|
public GameObject CreateContent(GameObject parent)
|
||||||
{
|
{
|
||||||
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
||||||
@ -152,10 +168,22 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
nameLabel.alignment = TextAnchor.MiddleLeft;
|
nameLabel.alignment = TextAnchor.MiddleLeft;
|
||||||
|
|
||||||
Color normal = new Color(0.11f, 0.11f, 0.11f);
|
// Sibling index input
|
||||||
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
|
||||||
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
SiblingIndex = UIFactory.CreateInputField(this.UIRoot, "SiblingIndexInput", string.Empty);
|
||||||
Color disabled = new Color(1, 1, 1, 0);
|
SiblingIndex.Component.textComponent.fontSize = 11;
|
||||||
|
SiblingIndex.Component.textComponent.alignment = TextAnchor.MiddleRight;
|
||||||
|
var siblingImage = SiblingIndex.GameObject.GetComponent<Image>();
|
||||||
|
siblingImage.color = new(0f, 0f, 0f, 0.25f);
|
||||||
|
UIFactory.SetLayoutElement(SiblingIndex.GameObject, 35, 20, 0, 0);
|
||||||
|
SiblingIndex.Component.GetOnEndEdit().AddListener(OnSiblingIndexEndEdit);
|
||||||
|
|
||||||
|
// Setup selectables
|
||||||
|
|
||||||
|
Color normal = new(0.11f, 0.11f, 0.11f);
|
||||||
|
Color highlight = new(0.25f, 0.25f, 0.25f);
|
||||||
|
Color pressed = new(0.05f, 0.05f, 0.05f);
|
||||||
|
Color disabled = new(1, 1, 1, 0);
|
||||||
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
||||||
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
|
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user