GameObject inspector taking shape

This commit is contained in:
sinaioutlander 2020-11-02 20:48:53 +11:00
parent b5b3e90b09
commit b9b5d721c8
7 changed files with 270 additions and 46 deletions

View File

@ -29,9 +29,12 @@ namespace ExplorerBeta.UI.Main
public void Update()
{
foreach (InspectorBase tab in m_currentInspectors)
for (int i = 0; i < m_currentInspectors.Count; i++)
{
tab.Update();
if (i >= m_currentInspectors.Count)
break;
m_currentInspectors[i].Update();
}
}

View File

@ -1,10 +1,18 @@
using System;
using System.Collections.Generic;
using ExplorerBeta.Helpers;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace ExplorerBeta.UI.Main.Inspectors
{
// TODO:
// make page handler for children and component lists
// -- clicking a child.. open new tab or change this tab target?
// make top info panel (path, scene, layer, enabled)
// make controls panel (transform controls, set parent, etc)
public class GameObjectInspector : InspectorBase
{
public override string TabLabel => $" [G] {TargetGO?.name}";
@ -12,6 +20,10 @@ namespace ExplorerBeta.UI.Main.Inspectors
// just to help with casting in il2cpp
public GameObject TargetGO;
// cached ui elements
public TMP_InputField m_nameInput;
public TMP_InputField m_pathInput;
public GameObjectInspector(GameObject target) : base(target)
{
TargetGO = target;
@ -34,7 +46,18 @@ namespace ExplorerBeta.UI.Main.Inspectors
return;
}
// TODO refresh children and components
m_nameInput.text = TargetGO.name;
m_pathInput.text = TargetGO.transform.GetTransformPath();
}
private void ChangeInspectorTarget(GameObject newTarget)
{
if (!newTarget)
return;
this.Target = this.TargetGO = newTarget;
// ?
}
#region UI CONSTRUCTION
@ -45,34 +68,198 @@ namespace ExplorerBeta.UI.Main.Inspectors
this.Content = UIFactory.CreateScrollView(parent, out GameObject scrollContent, new Color(0.1f, 0.1f, 0.1f, 1));
var nameObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var nameText = nameObj.GetComponent<Text>();
nameText.text = TargetGO.name;
nameText.fontSize = 18;
var scrollLayout = scrollContent.GetComponent<VerticalLayoutGroup>();
scrollLayout.childForceExpandHeight = false;
scrollLayout.childControlHeight = true;
scrollLayout.spacing = 5;
var childListObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var childListText = childListObj.GetComponent<Text>();
childListText.text = "Children:";
ConstructTopArea(scrollContent);
foreach (Transform child in TargetGO.transform)
ConstructChildList(scrollContent);
ConstructCompList(scrollContent);
ConstructControls(scrollContent);
}
private void ConstructTopArea(GameObject scrollContent)
{
// name row
var nameObj = UIFactory.CreateHorizontalGroup(scrollContent, new Color(0.1f, 0.1f, 0.1f));
var nameGroup = nameObj.GetComponent<HorizontalLayoutGroup>();
nameGroup.childForceExpandHeight = false;
nameGroup.childForceExpandWidth = false;
nameGroup.childControlHeight = false;
nameGroup.childControlWidth = true;
var nameRect = nameObj.GetComponent<RectTransform>();
nameRect.sizeDelta = new Vector2(nameRect.sizeDelta.x, 25);
var nameLayout = nameObj.AddComponent<LayoutElement>();
nameLayout.minHeight = 25;
nameLayout.flexibleHeight = 0;
var nameTextObj = UIFactory.CreateTMPLabel(nameObj, TextAlignmentOptions.Left);
var nameTextText = nameTextObj.GetComponent<TextMeshProUGUI>();
nameTextText.text = "Name:";
nameTextText.fontSize = 14;
var nameTextLayout = nameTextObj.AddComponent<LayoutElement>();
nameTextLayout.minHeight = 25;
nameTextLayout.flexibleHeight = 0;
nameTextLayout.minWidth = 60;
nameTextLayout.flexibleWidth = 0;
var nameInputObj = UIFactory.CreateTMPInput(nameObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var nameInputRect = nameInputObj.GetComponent<RectTransform>();
nameInputRect.sizeDelta = new Vector2(nameInputRect.sizeDelta.x, 25);
m_nameInput = nameInputObj.GetComponent<TMP_InputField>();
m_nameInput.text = TargetGO.name;
m_nameInput.lineType = TMP_InputField.LineType.SingleLine;
var applyNameBtnObj = UIFactory.CreateButton(nameObj);
var applyNameBtn = applyNameBtnObj.GetComponent<Button>();
applyNameBtn.onClick.AddListener(new Action(() =>
{
var childLabelObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var childLabelText = childLabelObj.GetComponent<Text>();
childLabelText.text = " - " + child.name;
}
TargetGO.name = m_nameInput.text;
}));
var applyNameText = applyNameBtnObj.GetComponentInChildren<Text>();
applyNameText.text = "Apply";
applyNameText.fontSize = 14;
var applyNameLayout = applyNameBtnObj.AddComponent<LayoutElement>();
applyNameLayout.minWidth = 65;
applyNameLayout.minHeight = 25;
applyNameLayout.flexibleHeight = 0;
var applyNameRect = applyNameBtnObj.GetComponent<RectTransform>();
applyNameRect.sizeDelta = new Vector2(applyNameRect.sizeDelta.x, 25);
var compListObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var compListText = compListObj.GetComponent<Text>();
compListText.text = "Components:";
// path row
var pathObj = UIFactory.CreateHorizontalGroup(scrollContent, new Color(0.1f, 0.1f, 0.1f));
var pathGroup = pathObj.GetComponent<HorizontalLayoutGroup>();
pathGroup.childForceExpandHeight = false;
pathGroup.childForceExpandWidth = false;
pathGroup.childControlHeight = false;
pathGroup.childControlWidth = true;
var pathRect = pathObj.GetComponent<RectTransform>();
pathRect.sizeDelta = new Vector2(pathRect.sizeDelta.x, 25);
var pathLayout = pathObj.AddComponent<LayoutElement>();
pathLayout.minHeight = 25;
pathLayout.flexibleHeight = 0;
var pathTextObj = UIFactory.CreateTMPLabel(pathObj, TextAlignmentOptions.Left);
var pathTextText = pathTextObj.GetComponent<TextMeshProUGUI>();
pathTextText.text = "Path:";
pathTextText.fontSize = 14;
var pathTextLayout = pathTextObj.AddComponent<LayoutElement>();
pathTextLayout.minHeight = 25;
pathTextLayout.flexibleHeight = 0;
pathTextLayout.minWidth = 60;
pathTextLayout.flexibleWidth = 0;
// TODO back button here (if has parent)
var pathInputObj = UIFactory.CreateTMPInput(pathObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var pathInputRect = pathInputObj.GetComponent<RectTransform>();
pathInputRect.sizeDelta = new Vector2(pathInputRect.sizeDelta.x, 25);
m_pathInput = pathInputObj.GetComponent<TMP_InputField>();
m_pathInput.text = TargetGO.transform.GetTransformPath();
var pathInputLayout = pathInputObj.AddComponent<LayoutElement>();
pathInputLayout.minHeight = 25;
pathInputLayout.flexibleHeight = 0;
var applyPathBtnObj = UIFactory.CreateButton(pathObj);
var applyPathBtn = applyPathBtnObj.GetComponent<Button>();
applyNameBtn.onClick.AddListener(new Action(() =>
{
ExplorerCore.Log("TODO");
}));
var applyPathText = applyPathBtnObj.GetComponentInChildren<Text>();
applyPathText.text = "Apply";
applyPathText.fontSize = 14;
var applyBtnLayout = applyPathBtnObj.AddComponent<LayoutElement>();
applyBtnLayout.minWidth = 65;
applyBtnLayout.minHeight = 25;
applyBtnLayout.flexibleHeight = 0;
var applyBtnRect = applyPathBtnObj.GetComponent<RectTransform>();
applyBtnRect.sizeDelta = new Vector2(applyNameRect.sizeDelta.x, 25);
}
private void ConstructChildList(GameObject scrollContent)
{
// todo put this in a RefreshChildren method, and use page handler
var childTitleObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var childTitleText = childTitleObj.GetComponent<Text>();
childTitleText.text = "Children:";
var childrenScrollObj = UIFactory.CreateScrollView(scrollContent, out GameObject subContent, new Color(0.15f, 0.15f, 0.15f));
var contentLayout = childrenScrollObj.AddComponent<LayoutElement>();
contentLayout.minHeight = 50;
contentLayout.flexibleHeight = 10000;
var contentGroup = subContent.GetComponent<VerticalLayoutGroup>();
contentGroup.spacing = 4;
for (int i = 0; i < TargetGO.transform.childCount; i++)
{
var child = TargetGO.transform.GetChild(i);
var buttonObj = UIFactory.CreateButton(subContent);
var btnImage = buttonObj.GetComponent<Image>();
btnImage.color = new Color(0.15f, 0.15f, 0.15f);
var button = buttonObj.GetComponent<Button>();
button.onClick.AddListener(new Action(() =>
{
ChangeInspectorTarget(child?.gameObject);
}));
var buttonText = buttonObj.GetComponentInChildren<Text>();
var text = child.name;
if (child.childCount > 0)
text = $"<color=grey>[{child.childCount}]</color> {text}";
buttonText.text = text;
buttonText.color = child.gameObject.activeSelf ? Color.green : Color.red;
}
}
private void ConstructCompList(GameObject scrollContent)
{
// todo put this in a RefreshComponents method, and use page handler
var compTitleObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var compTitleText = compTitleObj.GetComponent<Text>();
compTitleText.text = "Components:";
var compScrollObj = UIFactory.CreateScrollView(scrollContent, out GameObject subContent, new Color(0.15f, 0.15f, 0.15f));
var contentLayout = compScrollObj.AddComponent<LayoutElement>();
contentLayout.minHeight = 50;
contentLayout.flexibleHeight = 10000;
var contentGroup = subContent.GetComponent<VerticalLayoutGroup>();
contentGroup.spacing = 4;
foreach (var comp in TargetGO.GetComponents<Component>())
{
var compLabelObj = UIFactory.CreateLabel(scrollContent, TextAnchor.MiddleLeft);
var compText = compLabelObj.GetComponent<Text>();
compText.text = " - " + comp.GetType().Name;
var buttonObj = UIFactory.CreateButton(subContent);
var btnImage = buttonObj.GetComponent<Image>();
btnImage.color = new Color(0.15f, 0.15f, 0.15f);
var button = buttonObj.GetComponent<Button>();
button.onClick.AddListener(new Action(() =>
{
InspectorManager.Instance.Inspect(comp);
}));
var buttonText = buttonObj.GetComponentInChildren<Text>();
buttonText.text = ReflectionHelpers.GetActualType(comp).FullName;
}
}
private void ConstructControls(GameObject scrollContent)
{
// todo GO controls
}
#endregion

View File

@ -59,14 +59,22 @@ namespace ExplorerBeta.UI.Main.Inspectors
GameObject.Destroy(Content);
}
int thisIndex = -1;
if (InspectorManager.Instance.m_currentInspectors.Contains(this))
{
thisIndex = InspectorManager.Instance.m_currentInspectors.IndexOf(this);
InspectorManager.Instance.m_currentInspectors.Remove(this);
}
if (ReferenceEquals(InspectorManager.Instance.m_activeInspector, this))
{
InspectorManager.Instance.UnsetInspectorTab();
}
if (InspectorManager.Instance.m_currentInspectors.Contains(this))
{
InspectorManager.Instance.m_currentInspectors.Remove(this);
if (InspectorManager.Instance.m_currentInspectors.Count > 0)
{
var prevTab = InspectorManager.Instance.m_currentInspectors[thisIndex > 0 ? thisIndex - 1 : 0];
InspectorManager.Instance.SetInspectorTab(prevTab);
}
}
}

View File

@ -240,7 +240,6 @@ namespace ExplorerBeta.UI.Main
m_lastResizeHoverType = resizeType;
m_resizeCursorImage.SetActive(true);
ExplorerCore.Log("Set image active.");
// set the rotation for the resize icon
float iconRotation = 0f;

View File

@ -142,15 +142,14 @@ namespace ExplorerBeta.UI.Main
if (!handles.Contains(m_currentSceneHandle))
{
ExplorerCore.Log("Reverting to default scene");
m_sceneDropdown.transform.Find("Label").GetComponent<Text>().text = names[0];
SetScene(handles[0]);
SetTargetScene(handles[0]);
}
}
public void SetScene(string name) => SetScene(GetSceneHandle(name));
public void SetTargetScene(string name) => SetTargetScene(GetSceneHandle(name));
public void SetScene(int handle)
public void SetTargetScene(int handle)
{
if (handle == -1)
return;
@ -172,8 +171,11 @@ namespace ExplorerBeta.UI.Main
//m_scenePathText.ForceMeshUpdate();
}
public void SetSceneListObject(GameObject obj)
public void SetTargetObject(GameObject obj)
{
if (!obj)
return;
m_scenePathText.text = obj.name;
//m_scenePathText.ForceMeshUpdate();
@ -195,7 +197,7 @@ namespace ExplorerBeta.UI.Main
return;
}
SetSceneListObject(m_sceneShortList[index]);
SetTargetObject(m_sceneShortList[index]);
}
private void OnSceneListPageTurn()
@ -242,10 +244,13 @@ namespace ExplorerBeta.UI.Main
{
GameObject obj = objects[i + startIndex];
if (!obj)
continue;
if (i >= m_sceneShortList.Count)
{
m_sceneShortList.Add(obj);
AddSceneButton();
AddObjectListButton();
}
else
{
@ -316,7 +321,7 @@ namespace ExplorerBeta.UI.Main
void SetSceneFromDropdown(int val)
{
string scene = m_sceneDropdown.options[val].text;
SetScene(scene);
SetTargetScene(scene);
}
GameObject scenePathGroupObj = UIFactory.CreateHorizontalGroup(leftPane, new Color(1, 1, 1, 0f));
@ -346,14 +351,14 @@ namespace ExplorerBeta.UI.Main
void SetSceneObjectParent()
{
if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent)
if (!m_selectedSceneObject || !m_selectedSceneObject.transform.parent?.gameObject)
{
m_selectedSceneObject = null;
SetScene(m_currentSceneHandle);
SetTargetScene(m_currentSceneHandle);
}
else
{
SetSceneListObject(m_selectedSceneObject.transform.parent.gameObject);
SetTargetObject(m_selectedSceneObject.transform.parent.gameObject);
}
}
@ -400,7 +405,13 @@ namespace ExplorerBeta.UI.Main
colors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
scroll.colors = colors;
VerticalLayoutGroup sceneGroup = m_sceneListCanvas.GetComponent<VerticalLayoutGroup>();
var horiScroll = scrollObj.transform.Find("Scrollbar Horizontal");
horiScroll.gameObject.SetActive(false);
var scrollRect = scrollObj.GetComponentInChildren<ScrollRect>();
scrollRect.horizontalScrollbar = null;
var sceneGroup = m_sceneListCanvas.GetComponent<VerticalLayoutGroup>();
sceneGroup.childControlHeight = true;
sceneGroup.spacing = 2;
@ -409,7 +420,7 @@ namespace ExplorerBeta.UI.Main
m_sceneListPageHandler.OnPageChanged += OnSceneListPageTurn;
}
private void AddSceneButton()
private void AddObjectListButton()
{
int thisIndex = m_sceneListTexts.Count();

View File

@ -391,7 +391,7 @@ namespace ExplorerBeta.UI
return toggleObj;
}
public static GameObject CreateTMPInput(GameObject parent)
public static GameObject CreateTMPInput(GameObject parent, int fontSize = 16, int overflowMode = 0, int alignment = 257)
{
GameObject mainObj = CreateUIObject("InputField (TMP)", parent);
@ -436,9 +436,11 @@ namespace ExplorerBeta.UI
GameObject placeHolderObj = CreateUIObject("Placeholder", textArea);
TextMeshProUGUI placeholderText = placeHolderObj.AddComponent<TextMeshProUGUI>();
placeholderText.fontSize = 16;
placeholderText.fontSize = fontSize;
placeholderText.text = "...";
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
placeholderText.overflowMode = (TextOverflowModes)overflowMode;
placeholderText.alignment = (TextAlignmentOptions)alignment;
RectTransform placeHolderRect = placeHolderObj.GetComponent<RectTransform>();
placeHolderRect.anchorMin = Vector2.zero;
@ -454,9 +456,11 @@ namespace ExplorerBeta.UI
GameObject inputTextObj = CreateUIObject("Text", textArea);
TextMeshProUGUI inputText = inputTextObj.AddComponent<TextMeshProUGUI>();
inputText.fontSize = 16;
inputText.fontSize = fontSize;
inputText.text = "";
inputText.color = new Color(1f, 1f, 1f, 1f);
inputText.overflowMode = (TextOverflowModes)overflowMode;
inputText.alignment = (TextAlignmentOptions)alignment;
RectTransform inputTextRect = inputTextObj.GetComponent<RectTransform>();
inputTextRect.anchorMin = Vector2.zero;
@ -464,9 +468,9 @@ namespace ExplorerBeta.UI
inputTextRect.offsetMin = Vector2.zero;
inputTextRect.offsetMax = Vector2.zero;
LayoutElement test = inputTextObj.AddComponent<LayoutElement>();
test.preferredWidth = 990;
test.flexibleWidth = 500;
LayoutElement inputTextLayout = inputTextObj.AddComponent<LayoutElement>();
inputTextLayout.preferredWidth = 990;
inputTextLayout.flexibleWidth = 500;
mainInput.textComponent = inputText;
@ -523,6 +527,7 @@ namespace ExplorerBeta.UI
GameObject dropdownObj = CreateUIObject("Dropdown", parent, thickSize);
GameObject labelObj = CreateUIObject("Label", dropdownObj);
GameObject arrowObj = CreateUIObject("Arrow", dropdownObj);
GameObject templateObj = CreateUIObject("Template", dropdownObj);
GameObject viewportObj = CreateUIObject("Viewport", templateObj);
GameObject contentObj = CreateUIObject("Content", viewportObj);
@ -546,6 +551,15 @@ namespace ExplorerBeta.UI
SetDefaultTextValues(itemLabelText);
itemLabelText.alignment = TextAnchor.MiddleLeft;
var arrowText = arrowObj.AddComponent<Text>();
SetDefaultTextValues(arrowText);
arrowText.text = "▼";
var arrowRect = arrowObj.GetComponent<RectTransform>();
arrowRect.anchorMin = new Vector2(1f, 0.5f);
arrowRect.anchorMax = new Vector2(1f, 0.5f);
arrowRect.sizeDelta = new Vector2(20f, 20f);
arrowRect.anchoredPosition = new Vector2(-15f, 0f);
Image itemBgImage = itemBgObj.AddComponent<Image>();
itemBgImage.color = new Color(0.25f, 0.45f, 0.25f, 1.0f);

View File

@ -8,6 +8,7 @@ namespace ExplorerBeta.Unstrip.Scenes
{
public class SceneUnstrip
{
#if MONO
public static GameObject[] GetRootGameObjects(Scene scene) => scene.GetRootGameObjects();
public static GameObject[] GetRootGameObjects(int handle)
@ -22,6 +23,7 @@ namespace ExplorerBeta.Unstrip.Scenes
}
//Scene.GetRootGameObjects();
#endif
#if CPP
internal delegate void d_GetRootGameObjects(int handle, IntPtr list);