2020-10-28 06:39:26 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.Helpers;
|
2020-11-05 17:33:04 +11:00
|
|
|
|
using UnityExplorer.UI;
|
|
|
|
|
using UnityExplorer.UI.PageModel;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2020-11-05 17:33:04 +11:00
|
|
|
|
namespace UnityExplorer.Inspectors
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
|
|
|
|
public class InspectorManager
|
|
|
|
|
{
|
|
|
|
|
public static InspectorManager Instance { get; private set; }
|
|
|
|
|
|
2020-10-28 20:52:40 +11:00
|
|
|
|
public InspectorManager()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
ConstructInspectorPane();
|
|
|
|
|
}
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
|
|
|
|
public InspectorBase m_activeInspector;
|
|
|
|
|
public readonly List<InspectorBase> m_currentInspectors = new List<InspectorBase>();
|
2020-10-28 07:14:00 +11:00
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
public GameObject m_tabBarContent;
|
2020-10-28 07:14:00 +11:00
|
|
|
|
public GameObject m_inspectorContent;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2020-11-02 20:48:53 +11:00
|
|
|
|
for (int i = 0; i < m_currentInspectors.Count; i++)
|
2020-10-28 06:39:26 +11:00
|
|
|
|
{
|
2020-11-02 20:48:53 +11:00
|
|
|
|
if (i >= m_currentInspectors.Count)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
m_currentInspectors[i].Update();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Inspect(object obj)
|
|
|
|
|
{
|
|
|
|
|
#if CPP
|
|
|
|
|
obj = obj.Il2CppCast(ReflectionHelpers.GetActualType(obj));
|
|
|
|
|
#endif
|
|
|
|
|
UnityEngine.Object unityObj = obj as UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
if (InspectorBase.ObjectNullOrDestroyed(obj, unityObj))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainMenu.Instance.SetPage(HomePage.Instance);
|
|
|
|
|
|
|
|
|
|
// check if currently inspecting this object
|
|
|
|
|
foreach (InspectorBase tab in m_currentInspectors)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(obj, tab.Target))
|
|
|
|
|
{
|
|
|
|
|
SetInspectorTab(tab);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#if CPP
|
|
|
|
|
else if (unityObj && tab.Target is UnityEngine.Object uTabObj)
|
|
|
|
|
{
|
|
|
|
|
if (unityObj.m_CachedPtr == uTabObj.m_CachedPtr)
|
|
|
|
|
{
|
|
|
|
|
SetInspectorTab(tab);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InspectorBase inspector;
|
|
|
|
|
if (obj is GameObject go)
|
|
|
|
|
{
|
|
|
|
|
inspector = new GameObjectInspector(go);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inspector = new InstanceInspector(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_currentInspectors.Add(inspector);
|
2020-11-05 17:33:04 +11:00
|
|
|
|
inspector.SetContentInactive();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
|
|
|
|
SetInspectorTab(inspector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Inspect(Type type)
|
|
|
|
|
{
|
|
|
|
|
// TODO static type inspection
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetInspectorTab(InspectorBase inspector)
|
|
|
|
|
{
|
|
|
|
|
UnsetInspectorTab();
|
|
|
|
|
|
|
|
|
|
m_activeInspector = inspector;
|
|
|
|
|
|
2020-11-05 17:33:04 +11:00
|
|
|
|
inspector.SetContentActive();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
|
|
|
|
Color activeColor = new Color(0, 0.25f, 0, 1);
|
|
|
|
|
ColorBlock colors = inspector.tabButton.colors;
|
|
|
|
|
colors.normalColor = activeColor;
|
|
|
|
|
colors.highlightedColor = activeColor;
|
|
|
|
|
inspector.tabButton.colors = colors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UnsetInspectorTab()
|
|
|
|
|
{
|
|
|
|
|
if (m_activeInspector == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 17:33:04 +11:00
|
|
|
|
m_activeInspector.SetContentInactive();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
|
|
|
|
ColorBlock colors = m_activeInspector.tabButton.colors;
|
|
|
|
|
colors.normalColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
|
|
|
|
colors.highlightedColor = new Color(0.1f, 0.3f, 0.1f, 1);
|
|
|
|
|
m_activeInspector.tabButton.colors = colors;
|
|
|
|
|
|
|
|
|
|
m_activeInspector = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region INSPECTOR PANE
|
|
|
|
|
|
|
|
|
|
public void ConstructInspectorPane()
|
|
|
|
|
{
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var mainObj = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f));
|
|
|
|
|
LayoutElement rightLayout = mainObj.AddComponent<LayoutElement>();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
rightLayout.flexibleWidth = 999999;
|
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var rightGroup = mainObj.GetComponent<VerticalLayoutGroup>();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
rightGroup.childForceExpandHeight = true;
|
|
|
|
|
rightGroup.childForceExpandWidth = true;
|
|
|
|
|
rightGroup.childControlHeight = true;
|
|
|
|
|
rightGroup.childControlWidth = true;
|
|
|
|
|
rightGroup.spacing = 10;
|
|
|
|
|
rightGroup.padding.left = 8;
|
|
|
|
|
rightGroup.padding.right = 8;
|
|
|
|
|
rightGroup.padding.top = 8;
|
|
|
|
|
rightGroup.padding.bottom = 8;
|
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var inspectorTitle = UIFactory.CreateLabel(mainObj, TextAnchor.UpperLeft);
|
2020-10-28 06:39:26 +11:00
|
|
|
|
Text title = inspectorTitle.GetComponent<Text>();
|
|
|
|
|
title.text = "Inspector";
|
|
|
|
|
title.fontSize = 20;
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var titleLayout = inspectorTitle.AddComponent<LayoutElement>();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
titleLayout.minHeight = 30;
|
|
|
|
|
titleLayout.flexibleHeight = 0;
|
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
m_tabBarContent = UIFactory.CreateGridGroup(mainObj, new Vector2(185, 20), new Vector2(5, 2), new Color(0.1f, 0.1f, 0.1f, 1));
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var gridGroup = m_tabBarContent.GetComponent<GridLayoutGroup>();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
gridGroup.padding.top = 4;
|
|
|
|
|
gridGroup.padding.left = 4;
|
|
|
|
|
gridGroup.padding.right = 4;
|
|
|
|
|
gridGroup.padding.bottom = 4;
|
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
// inspector content area
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
m_inspectorContent = UIFactory.CreateVerticalGroup(mainObj, new Color(0.1f, 0.1f, 0.1f, 1.0f));
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var contentGroup = m_inspectorContent.GetComponent<VerticalLayoutGroup>();
|
|
|
|
|
contentGroup.childForceExpandHeight = true;
|
|
|
|
|
contentGroup.childForceExpandWidth = true;
|
|
|
|
|
contentGroup.childControlHeight = true;
|
|
|
|
|
contentGroup.childControlWidth = true;
|
|
|
|
|
contentGroup.spacing = 5;
|
|
|
|
|
contentGroup.padding.top = 5;
|
|
|
|
|
contentGroup.padding.left = 5;
|
|
|
|
|
contentGroup.padding.right = 5;
|
|
|
|
|
contentGroup.padding.bottom = 5;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-10-28 07:14:00 +11:00
|
|
|
|
var contentLayout = m_inspectorContent.AddComponent<LayoutElement>();
|
|
|
|
|
contentLayout.preferredHeight = 900;
|
|
|
|
|
contentLayout.flexibleHeight = 10000;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|