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;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using UnityExplorer.UI.Inspectors;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
using UnityExplorer.UI.Widgets;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Widgets
|
|
|
|
|
{
|
2021-04-16 02:49:46 +10:00
|
|
|
|
public class TransformCell : ICell
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public float DefaultHeight => 25f;
|
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
public bool Enabled => m_enabled;
|
|
|
|
|
private bool m_enabled;
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public Action<CachedTransform> OnExpandToggled;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
|
|
|
|
public CachedTransform cachedTransform;
|
|
|
|
|
public int _cellIndex;
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public GameObject UIRoot => uiRoot;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
public GameObject uiRoot;
|
2021-04-21 23:07:15 +10:00
|
|
|
|
public RectTransform Rect => m_rect;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
private RectTransform m_rect;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public ButtonRef ExpandButton;
|
|
|
|
|
public ButtonRef NameButton;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
|
|
|
|
public LayoutElement spacer;
|
|
|
|
|
|
|
|
|
|
public void ConfigureCell(CachedTransform cached, int cellIndex)
|
|
|
|
|
{
|
2021-04-22 22:57:04 +10:00
|
|
|
|
if (cached == null)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("Setting TransformTree cell but the CachedTransform is null!");
|
2021-04-16 04:33:13 +10:00
|
|
|
|
return;
|
2021-04-22 22:57:04 +10:00
|
|
|
|
}
|
2021-04-16 04:33:13 +10:00
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
if (!Enabled)
|
|
|
|
|
Enable();
|
|
|
|
|
|
|
|
|
|
_cellIndex = cellIndex;
|
|
|
|
|
cachedTransform = cached;
|
|
|
|
|
|
|
|
|
|
spacer.minWidth = cached.Depth * 15;
|
|
|
|
|
|
2021-04-22 22:57:04 +10:00
|
|
|
|
if (cached.Value)
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
NameButton.ButtonText.text = cached.Value.name;
|
|
|
|
|
NameButton.ButtonText.color = cached.Value.gameObject.activeSelf ? Color.white : Color.grey;
|
2021-04-22 22:57:04 +10:00
|
|
|
|
|
|
|
|
|
int childCount = cached.Value.childCount;
|
|
|
|
|
if (childCount > 0)
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
NameButton.ButtonText.text = $"<color=grey>[{childCount}]</color> {NameButton.ButtonText.text}";
|
2021-04-22 22:57:04 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
ExpandButton.Button.interactable = true;
|
|
|
|
|
ExpandButton.ButtonText.text = cached.Expanded ? "▼" : "►";
|
|
|
|
|
ExpandButton.ButtonText.color = cached.Expanded ? new Color(0.5f, 0.5f, 0.5f) : new Color(0.3f, 0.3f, 0.3f);
|
2021-04-22 22:57:04 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
ExpandButton.Button.interactable = false;
|
|
|
|
|
ExpandButton.ButtonText.text = "▪";
|
|
|
|
|
ExpandButton.ButtonText.color = new Color(0.3f, 0.3f, 0.3f);
|
2021-04-22 22:57:04 +10:00
|
|
|
|
}
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
NameButton.ButtonText.text = $"[Destroyed]";
|
|
|
|
|
NameButton.ButtonText.color = Color.red;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
OnExpandToggled?.Invoke(cachedTransform);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMainButtonClicked()
|
|
|
|
|
{
|
2021-04-16 02:49:46 +10:00
|
|
|
|
if (cachedTransform.Value)
|
2021-04-26 19:56:21 +10:00
|
|
|
|
InspectorManager.Inspect(cachedTransform.Value.gameObject);
|
2021-04-16 02:49:46 +10:00
|
|
|
|
else
|
|
|
|
|
ExplorerCore.LogWarning("The object was destroyed!");
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public GameObject CreateContent(GameObject parent)
|
2021-04-16 02:49:46 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
uiRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(uiRoot, true, true, true, true, 2, childAlignment: TextAnchor.MiddleCenter);
|
|
|
|
|
m_rect = uiRoot.GetComponent<RectTransform>();
|
|
|
|
|
m_rect.anchorMin = new Vector2(0, 1);
|
|
|
|
|
m_rect.anchorMax = new Vector2(0, 1);
|
|
|
|
|
m_rect.pivot = new Vector2(0.5f, 1);
|
|
|
|
|
m_rect.sizeDelta = new Vector2(25, 25);
|
|
|
|
|
UIFactory.SetLayoutElement(uiRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
var spacerObj = UIFactory.CreateUIObject("Spacer", uiRoot, new Vector2(0, 0));
|
|
|
|
|
UIFactory.SetLayoutElement(spacerObj, minWidth: 0, flexibleWidth: 0, minHeight: 0, flexibleHeight: 0);
|
|
|
|
|
this.spacer = spacerObj.GetComponent<LayoutElement>();
|
|
|
|
|
|
|
|
|
|
ExpandButton = UIFactory.CreateButton(this.uiRoot, "ExpandButton", "►");
|
|
|
|
|
UIFactory.SetLayoutElement(ExpandButton.Button.gameObject, minWidth: 15, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
NameButton = UIFactory.CreateButton(this.uiRoot, "NameButton", "Name", null);
|
|
|
|
|
UIFactory.SetLayoutElement(NameButton.Button.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
var nameLabel = NameButton.Button.GetComponentInChildren<Text>();
|
2021-04-16 02:49:46 +10:00
|
|
|
|
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
|
|
|
nameLabel.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
Color normal = new Color(0.11f, 0.11f, 0.11f);
|
2021-04-16 02:49:46 +10:00
|
|
|
|
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);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(ExpandButton.Button, normal, highlight, pressed, disabled);
|
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(NameButton.Button, normal, highlight, pressed, disabled);
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
NameButton.OnClick += OnMainButtonClicked;
|
|
|
|
|
ExpandButton.OnClick += OnExpandClicked;
|
|
|
|
|
|
|
|
|
|
uiRoot.SetActive(false);
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
return this.uiRoot;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|