mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2024-12-23 01:59:40 +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 string Name { get; internal set; }
|
||||
public bool Enabled { get; internal set; }
|
||||
public int SiblingIndex { get; internal set; }
|
||||
|
||||
public bool Expanded => Tree.IsCellExpanded(InstanceID);
|
||||
|
||||
@ -26,27 +27,32 @@ namespace UnityExplorer.UI.Widgets
|
||||
Value = transform;
|
||||
Parent = parent;
|
||||
InstanceID = transform.GetInstanceID();
|
||||
SiblingIndex = transform.GetSiblingIndex();
|
||||
Update(transform, depth);
|
||||
}
|
||||
|
||||
public bool Update(Transform transform, int depth)
|
||||
{
|
||||
bool ret = false;
|
||||
bool changed = false;
|
||||
|
||||
if (Value != transform
|
||||
|| depth != Depth
|
||||
|| ChildCount != transform.childCount
|
||||
|| Name != transform.name
|
||||
|| Enabled != transform.gameObject.activeSelf)
|
||||
|| Enabled != transform.gameObject.activeSelf
|
||||
|| SiblingIndex != transform.GetSiblingIndex())
|
||||
{
|
||||
changed = true;
|
||||
|
||||
Value = transform;
|
||||
Depth = depth;
|
||||
ChildCount = transform.childCount;
|
||||
Name = transform.name;
|
||||
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.Widgets;
|
||||
using UniverseLib.UI.Widgets.ScrollView;
|
||||
using UniverseLib.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
@ -36,6 +37,7 @@ namespace UnityExplorer.UI.Widgets
|
||||
public ButtonRef ExpandButton;
|
||||
public ButtonRef NameButton;
|
||||
public Toggle EnabledToggle;
|
||||
public InputFieldRef SiblingIndex;
|
||||
|
||||
public LayoutElement spacer;
|
||||
|
||||
@ -77,6 +79,9 @@ namespace UnityExplorer.UI.Widgets
|
||||
|
||||
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
||||
|
||||
if (!SiblingIndex.Component.isFocused)
|
||||
SiblingIndex.Text = cached.Value.GetSiblingIndex().ToString();
|
||||
|
||||
int childCount = cached.Value.childCount;
|
||||
if (childCount > 0)
|
||||
{
|
||||
@ -118,6 +123,17 @@ namespace UnityExplorer.UI.Widgets
|
||||
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)
|
||||
{
|
||||
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
||||
@ -152,10 +168,22 @@ namespace UnityExplorer.UI.Widgets
|
||||
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
nameLabel.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
Color normal = new Color(0.11f, 0.11f, 0.11f);
|
||||
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
||||
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
||||
Color disabled = new Color(1, 1, 1, 0);
|
||||
// Sibling index input
|
||||
|
||||
SiblingIndex = UIFactory.CreateInputField(this.UIRoot, "SiblingIndexInput", string.Empty);
|
||||
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(NameButton.Component, normal, highlight, pressed, disabled);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user