2021-04-15 20:18:03 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.UI.Widgets.InfiniteScroll;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Widgets
|
|
|
|
|
{
|
2021-04-16 02:49:46 +10:00
|
|
|
|
public class TransformCell : ICell
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
|
|
|
|
public bool Enabled => m_enabled;
|
|
|
|
|
private bool m_enabled;
|
|
|
|
|
|
|
|
|
|
public TransformTree tree;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
|
|
|
|
public CachedTransform cachedTransform;
|
|
|
|
|
public int _cellIndex;
|
|
|
|
|
|
|
|
|
|
public GameObject uiRoot;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
|
|
|
|
public Text nameLabel;
|
|
|
|
|
public Button nameButton;
|
|
|
|
|
|
|
|
|
|
public Text expandLabel;
|
|
|
|
|
public Button expandButton;
|
|
|
|
|
|
|
|
|
|
public LayoutElement spacer;
|
|
|
|
|
|
2021-04-16 02:49:46 +10:00
|
|
|
|
public TransformCell(TransformTree tree, GameObject cellUI, Button nameButton, Button expandButton, LayoutElement spacer)
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-04-16 02:49:46 +10:00
|
|
|
|
this.tree = tree;
|
|
|
|
|
this.uiRoot = cellUI;
|
|
|
|
|
this.nameButton = nameButton;
|
|
|
|
|
this.nameLabel = nameButton.GetComponentInChildren<Text>();
|
|
|
|
|
this.expandButton = expandButton;
|
|
|
|
|
this.expandLabel = expandButton.GetComponentInChildren<Text>();
|
|
|
|
|
this.spacer = spacer;
|
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
nameButton.onClick.AddListener(OnMainButtonClicked);
|
|
|
|
|
expandButton.onClick.AddListener(OnExpandClicked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This is called from the SetCell method in DataSource
|
|
|
|
|
public void ConfigureCell(CachedTransform cached, int cellIndex)
|
|
|
|
|
{
|
|
|
|
|
if (!Enabled)
|
|
|
|
|
Enable();
|
|
|
|
|
|
|
|
|
|
_cellIndex = cellIndex;
|
|
|
|
|
cachedTransform = cached;
|
|
|
|
|
|
|
|
|
|
spacer.minWidth = cached.Depth * 15;
|
|
|
|
|
|
2021-04-16 02:49:46 +10:00
|
|
|
|
nameLabel.text = cached.Value.name;
|
|
|
|
|
nameLabel.color = cached.Value.gameObject.activeSelf ? Color.white : Color.grey;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-04-16 02:49:46 +10:00
|
|
|
|
int childCount = cached.Value.childCount;
|
|
|
|
|
if (childCount > 0)
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-04-16 02:49:46 +10:00
|
|
|
|
nameLabel.text = $"<color=grey>[{childCount}]</color> {nameLabel.text}";
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
|
|
|
|
expandButton.interactable = true;
|
|
|
|
|
expandLabel.enabled = true;
|
|
|
|
|
expandLabel.text = cached.Expanded ? "▼" : "►";
|
|
|
|
|
expandLabel.color = cached.Expanded ? new Color(0.5f, 0.5f, 0.5f) : new Color(0.3f, 0.3f, 0.3f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
expandButton.interactable = false;
|
|
|
|
|
expandLabel.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
|
{
|
|
|
|
|
m_enabled = false;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
uiRoot.SetActive(false);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Enable()
|
|
|
|
|
{
|
|
|
|
|
m_enabled = true;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
uiRoot.SetActive(true);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnExpandClicked()
|
|
|
|
|
{
|
|
|
|
|
tree.ToggleExpandCell(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMainButtonClicked()
|
|
|
|
|
{
|
2021-04-16 02:49:46 +10:00
|
|
|
|
if (cachedTransform.Value)
|
|
|
|
|
ExplorerCore.Log($"TODO Inspect {cachedTransform.Value.name}");
|
|
|
|
|
else
|
|
|
|
|
ExplorerCore.LogWarning("The object was destroyed!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameObject CreatePrototypeCell(GameObject parent)
|
|
|
|
|
{
|
|
|
|
|
var prototype = UIFactory.CreateHorizontalGroup(parent, "PrototypeCell", true, true, true, true, 2, default,
|
|
|
|
|
new Color(0.15f, 0.15f, 0.15f), TextAnchor.MiddleCenter);
|
|
|
|
|
//var cell = prototype.AddComponent<TransformCell>();
|
|
|
|
|
var rect = prototype.GetComponent<RectTransform>();
|
|
|
|
|
rect.anchorMin = new Vector2(0, 1);
|
|
|
|
|
rect.anchorMax = new Vector2(0, 1);
|
|
|
|
|
rect.pivot = new Vector2(0.5f, 1);
|
|
|
|
|
rect.sizeDelta = new Vector2(25, 25);
|
|
|
|
|
UIFactory.SetLayoutElement(prototype, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
var spacer = UIFactory.CreateUIObject("Spacer", prototype, new Vector2(0, 0));
|
|
|
|
|
UIFactory.SetLayoutElement(spacer, minWidth: 0, flexibleWidth: 0, minHeight: 0, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
var expandButton = UIFactory.CreateButton(prototype, "ExpandButton", "►", null);
|
|
|
|
|
UIFactory.SetLayoutElement(expandButton.gameObject, minWidth: 15, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
var nameButton = UIFactory.CreateButton(prototype, "NameButton", "Name", null);
|
|
|
|
|
UIFactory.SetLayoutElement(nameButton.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
var nameLabel = nameButton.GetComponentInChildren<Text>();
|
|
|
|
|
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
|
|
|
nameLabel.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
|
|
|
|
|
Color normal = new Color(0.15f, 0.15f, 0.15f);
|
|
|
|
|
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);
|
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(expandButton, normal, highlight, pressed, disabled);
|
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(nameButton, normal, highlight, pressed, disabled);
|
|
|
|
|
|
|
|
|
|
prototype.SetActive(false);
|
|
|
|
|
|
|
|
|
|
return prototype;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|