2022-01-31 21:24:01 +11:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using System;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using System.Reflection;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.Inspectors;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
using UnityExplorer.UI.Widgets;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib;
|
|
|
|
|
using UniverseLib.UI;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.UI.Models;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib.UI.Widgets;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.UI.Widgets.ScrollView;
|
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;
|
|
|
|
|
|
2022-01-24 17:49:49 +11:00
|
|
|
|
public bool Enabled => enabled;
|
|
|
|
|
private bool enabled;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public Action<CachedTransform> OnExpandToggled;
|
2021-06-14 18:43:26 +10:00
|
|
|
|
public Action<CachedTransform> OnEnableToggled;
|
2021-05-16 21:46:19 +10:00
|
|
|
|
public Action<GameObject> OnGameObjectClicked;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
|
|
|
|
public CachedTransform cachedTransform;
|
2022-01-24 17:49:49 +11:00
|
|
|
|
public int cellIndex;
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public GameObject UIRoot { get; set; }
|
|
|
|
|
public RectTransform Rect { get; set; }
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public ButtonRef ExpandButton;
|
|
|
|
|
public ButtonRef NameButton;
|
2021-06-14 18:43:26 +10:00
|
|
|
|
public Toggle EnabledToggle;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
|
|
|
|
public LayoutElement spacer;
|
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
public void Enable()
|
2021-05-16 21:46:19 +10:00
|
|
|
|
{
|
2022-01-24 17:49:49 +11:00
|
|
|
|
enabled = true;
|
2021-06-14 18:43:26 +10:00
|
|
|
|
UIRoot.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
|
{
|
2022-01-24 17:49:49 +11:00
|
|
|
|
enabled = false;
|
2021-06-14 18:43:26 +10:00
|
|
|
|
UIRoot.SetActive(false);
|
2021-05-16 21:46:19 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
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();
|
|
|
|
|
|
2022-01-24 17:49:49 +11:00
|
|
|
|
this.cellIndex = cellIndex;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
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
|
|
|
|
{
|
2022-01-24 17:49:49 +11:00
|
|
|
|
string name = cached.Value.name?.Trim();
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
name = "<i><color=grey>untitled</color></i>";
|
|
|
|
|
NameButton.ButtonText.text = name;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
NameButton.ButtonText.color = cached.Value.gameObject.activeSelf ? Color.white : Color.grey;
|
2021-04-22 22:57:04 +10:00
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
|
|
|
|
|
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-05-11 19:18:27 +10:00
|
|
|
|
ExpandButton.Component.interactable = true;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
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-05-11 19:18:27 +10:00
|
|
|
|
ExpandButton.Component.interactable = false;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
public void OnMainButtonClicked()
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-06-14 18:43:26 +10:00
|
|
|
|
if (cachedTransform.Value)
|
|
|
|
|
OnGameObjectClicked?.Invoke(cachedTransform.Value.gameObject);
|
|
|
|
|
else
|
|
|
|
|
ExplorerCore.LogWarning("The object was destroyed!");
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
public void OnExpandClicked()
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-06-14 18:43:26 +10:00
|
|
|
|
OnExpandToggled?.Invoke(cachedTransform);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
private void OnEnableClicked(bool value)
|
2021-04-15 20:18:03 +10:00
|
|
|
|
{
|
2021-06-14 18:43:26 +10:00
|
|
|
|
OnEnableToggled?.Invoke(cachedTransform);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
public GameObject CreateContent(GameObject parent)
|
2021-04-16 02:49:46 +10:00
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
2021-06-14 18:43:26 +10:00
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(UIRoot, false, false, true, true, 2, childAlignment: TextAnchor.MiddleCenter);
|
2021-05-01 20:55:27 +10:00
|
|
|
|
Rect = UIRoot.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(UIRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
var spacerObj = UIFactory.CreateUIObject("Spacer", UIRoot, new Vector2(0, 0));
|
2021-04-26 19:56:21 +10:00
|
|
|
|
UIFactory.SetLayoutElement(spacerObj, minWidth: 0, flexibleWidth: 0, minHeight: 0, flexibleHeight: 0);
|
|
|
|
|
this.spacer = spacerObj.GetComponent<LayoutElement>();
|
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
// Expand arrow
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
ExpandButton = UIFactory.CreateButton(this.UIRoot, "ExpandButton", "►");
|
2021-05-11 19:18:27 +10:00
|
|
|
|
UIFactory.SetLayoutElement(ExpandButton.Component.gameObject, minWidth: 15, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-06-14 18:43:26 +10:00
|
|
|
|
// Enabled toggle
|
|
|
|
|
|
|
|
|
|
var toggleObj = UIFactory.CreateToggle(UIRoot, "BehaviourToggle", out EnabledToggle, out var behavText, default, 17, 17);
|
|
|
|
|
UIFactory.SetLayoutElement(toggleObj, minHeight: 17, flexibleHeight: 0, minWidth: 17);
|
|
|
|
|
EnabledToggle.onValueChanged.AddListener(OnEnableClicked);
|
|
|
|
|
|
|
|
|
|
// Name button
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
NameButton = UIFactory.CreateButton(this.UIRoot, "NameButton", "Name", null);
|
2021-05-11 19:18:27 +10:00
|
|
|
|
UIFactory.SetLayoutElement(NameButton.Component.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
var nameLabel = NameButton.Component.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);
|
2022-01-31 21:24:01 +11:00
|
|
|
|
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
|
|
|
|
RuntimeHelper.SetColorBlock(NameButton.Component, 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;
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
UIRoot.SetActive(false);
|
2021-04-16 02:49:46 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
return this.UIRoot;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|