mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
Finish GameObject Inspector, start Search page, some other UI changes/fixes
This commit is contained in:
parent
e175e9c438
commit
2efc3f6578
@ -155,6 +155,19 @@ namespace UnityExplorer.Console
|
|||||||
|
|
||||||
pos = editor.InputField.transform.TransformPoint(pos);
|
pos = editor.InputField.transform.TransformPoint(pos);
|
||||||
|
|
||||||
|
// fix position when scrolled down
|
||||||
|
var scrollSize = editor.InputField.verticalScrollbar.size;
|
||||||
|
var scrollValue = editor.InputField.verticalScrollbar.value;
|
||||||
|
|
||||||
|
scrollSize += (1 - scrollSize) * (1 - scrollValue);
|
||||||
|
|
||||||
|
if (!Mathf.Approximately(scrollSize, 1))
|
||||||
|
{
|
||||||
|
var height = editor.InputField.textViewport.rect.height;
|
||||||
|
|
||||||
|
pos.y += (1 / scrollSize * height) - height;
|
||||||
|
}
|
||||||
|
|
||||||
m_mainObj.transform.position = new Vector3(pos.x, pos.y - 3, 0);
|
m_mainObj.transform.position = new Vector3(pos.x, pos.y - 3, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace UnityExplorer
|
|||||||
|
|
||||||
new ExplorerCore();
|
new ExplorerCore();
|
||||||
|
|
||||||
HarmonyInstance.PatchAll();
|
// HarmonyInstance.PatchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void DoSceneChange(Scene arg0, Scene arg1)
|
internal static void DoSceneChange(Scene arg0, Scene arg1)
|
||||||
|
@ -4,6 +4,7 @@ using UnityExplorer.Input;
|
|||||||
using UnityExplorer.UI;
|
using UnityExplorer.UI;
|
||||||
using UnityExplorer.UI.PageModel;
|
using UnityExplorer.UI.PageModel;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
|
||||||
namespace UnityExplorer
|
namespace UnityExplorer
|
||||||
{
|
{
|
||||||
@ -87,13 +88,20 @@ namespace UnityExplorer
|
|||||||
if (!m_doneUIInit)
|
if (!m_doneUIInit)
|
||||||
CheckUIInit();
|
CheckUIInit();
|
||||||
|
|
||||||
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
if (MouseInspector.Enabled)
|
||||||
ShowMenu = !ShowMenu;
|
|
||||||
|
|
||||||
if (ShowMenu)
|
|
||||||
{
|
{
|
||||||
ForceUnlockCursor.Update();
|
MouseInspector.UpdateInspect();
|
||||||
UIManager.Update();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
||||||
|
ShowMenu = !ShowMenu;
|
||||||
|
|
||||||
|
if (ShowMenu)
|
||||||
|
{
|
||||||
|
ForceUnlockCursor.Update();
|
||||||
|
UIManager.Update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
197
src/Inspectors/GOInspector/ChildList.cs
Normal file
197
src/Inspectors/GOInspector/ChildList.cs
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
|
using UnityExplorer.UI;
|
||||||
|
using UnityExplorer.UI.Shared;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Input;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Inspectors.GOInspector
|
||||||
|
{
|
||||||
|
public class ChildList
|
||||||
|
{
|
||||||
|
internal static ChildList Instance;
|
||||||
|
|
||||||
|
public ChildList()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PageHandler s_childListPageHandler;
|
||||||
|
private static GameObject[] s_allChildren = new GameObject[0];
|
||||||
|
private static readonly List<GameObject> s_childrenShortlist = new List<GameObject>();
|
||||||
|
private static GameObject s_childListContent;
|
||||||
|
private static readonly List<Text> s_childListTexts = new List<Text>();
|
||||||
|
private static int s_lastChildCount;
|
||||||
|
|
||||||
|
internal void RefreshChildObjectList()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
|
||||||
|
s_allChildren = new GameObject[go.transform.childCount];
|
||||||
|
for (int i = 0; i < go.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
var child = go.transform.GetChild(i);
|
||||||
|
s_allChildren[i] = child.gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
var objects = s_allChildren;
|
||||||
|
s_childListPageHandler.ListCount = objects.Length;
|
||||||
|
|
||||||
|
int newCount = 0;
|
||||||
|
|
||||||
|
foreach (var itemIndex in s_childListPageHandler)
|
||||||
|
{
|
||||||
|
newCount++;
|
||||||
|
|
||||||
|
// normalized index starting from 0
|
||||||
|
var i = itemIndex - s_childListPageHandler.StartIndex;
|
||||||
|
|
||||||
|
if (itemIndex >= objects.Length)
|
||||||
|
{
|
||||||
|
if (i > s_lastChildCount || i >= s_childListTexts.Count)
|
||||||
|
break;
|
||||||
|
|
||||||
|
GameObject label = s_childListTexts[i].transform.parent.parent.gameObject;
|
||||||
|
if (label.activeSelf)
|
||||||
|
label.SetActive(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameObject obj = objects[itemIndex];
|
||||||
|
|
||||||
|
if (!obj)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i >= s_childrenShortlist.Count)
|
||||||
|
{
|
||||||
|
s_childrenShortlist.Add(obj);
|
||||||
|
AddChildListButton();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_childrenShortlist[i] = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = s_childListTexts[i];
|
||||||
|
|
||||||
|
var name = obj.name;
|
||||||
|
|
||||||
|
if (obj.transform.childCount > 0)
|
||||||
|
name = $"<color=grey>[{obj.transform.childCount}]</color> {name}";
|
||||||
|
|
||||||
|
text.text = name;
|
||||||
|
text.color = obj.activeSelf ? Color.green : Color.red;
|
||||||
|
|
||||||
|
var label = text.transform.parent.parent.gameObject;
|
||||||
|
if (!label.activeSelf)
|
||||||
|
{
|
||||||
|
label.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s_lastChildCount = newCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnChildListObjectClicked(int index)
|
||||||
|
{
|
||||||
|
if (GameObjectInspector.ActiveInstance == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (index >= s_childrenShortlist.Count || !s_childrenShortlist[index])
|
||||||
|
return;
|
||||||
|
|
||||||
|
GameObjectInspector.ActiveInstance.ChangeInspectorTarget(s_childrenShortlist[index]);
|
||||||
|
GameObjectInspector.ActiveInstance.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnChildListPageTurn()
|
||||||
|
{
|
||||||
|
if (Instance == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Instance.RefreshChildObjectList();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
|
internal void ConstructChildList(GameObject parent)
|
||||||
|
{
|
||||||
|
var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1, 1, 1, 0));
|
||||||
|
var vertGroup = vertGroupObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
vertGroup.childForceExpandHeight = false;
|
||||||
|
vertGroup.childForceExpandWidth = false;
|
||||||
|
vertGroup.childControlWidth = true;
|
||||||
|
vertGroup.spacing = 5;
|
||||||
|
var vertLayout = vertGroupObj.AddComponent<LayoutElement>();
|
||||||
|
vertLayout.minWidth = 120;
|
||||||
|
vertLayout.flexibleWidth = 25000;
|
||||||
|
vertLayout.minHeight = 200;
|
||||||
|
vertLayout.flexibleHeight = 5000;
|
||||||
|
|
||||||
|
var childTitleObj = UIFactory.CreateLabel(vertGroupObj, TextAnchor.MiddleLeft);
|
||||||
|
var childTitleText = childTitleObj.GetComponent<Text>();
|
||||||
|
childTitleText.text = "Children";
|
||||||
|
childTitleText.color = Color.grey;
|
||||||
|
childTitleText.fontSize = 14;
|
||||||
|
var childTitleLayout = childTitleObj.AddComponent<LayoutElement>();
|
||||||
|
childTitleLayout.minHeight = 30;
|
||||||
|
|
||||||
|
s_childListPageHandler = new PageHandler();
|
||||||
|
s_childListPageHandler.ConstructUI(vertGroupObj);
|
||||||
|
s_childListPageHandler.OnPageChanged += OnChildListPageTurn;
|
||||||
|
|
||||||
|
var childrenScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_childListContent, new Color(0.07f, 0.07f, 0.07f));
|
||||||
|
var contentLayout = childrenScrollObj.GetComponent<LayoutElement>();
|
||||||
|
contentLayout.minHeight = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void AddChildListButton()
|
||||||
|
{
|
||||||
|
int thisIndex = s_childListTexts.Count;
|
||||||
|
|
||||||
|
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_childListContent, new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
btnGroup.childForceExpandWidth = true;
|
||||||
|
btnGroup.childControlWidth = true;
|
||||||
|
btnGroup.childForceExpandHeight = false;
|
||||||
|
btnGroup.childControlHeight = true;
|
||||||
|
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
|
||||||
|
btnLayout.flexibleWidth = 320;
|
||||||
|
btnLayout.minHeight = 25;
|
||||||
|
btnLayout.flexibleHeight = 0;
|
||||||
|
btnGroupObj.AddComponent<Mask>();
|
||||||
|
|
||||||
|
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
|
||||||
|
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
|
||||||
|
mainBtnLayout.minHeight = 25;
|
||||||
|
mainBtnLayout.flexibleHeight = 0;
|
||||||
|
mainBtnLayout.minWidth = 240;
|
||||||
|
mainBtnLayout.flexibleWidth = 0;
|
||||||
|
Button mainBtn = mainButtonObj.GetComponent<Button>();
|
||||||
|
ColorBlock mainColors = mainBtn.colors;
|
||||||
|
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);
|
||||||
|
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||||
|
mainBtn.colors = mainColors;
|
||||||
|
#if CPP
|
||||||
|
mainBtn.onClick.AddListener(new Action(() => { OnChildListObjectClicked(thisIndex); }));
|
||||||
|
#else
|
||||||
|
mainBtn.onClick.AddListener(() => { OnChildListObjectClicked(thisIndex); });
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
|
||||||
|
mainText.alignment = TextAnchor.MiddleLeft;
|
||||||
|
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
mainText.resizeTextForBestFit = true;
|
||||||
|
mainText.resizeTextMaxSize = 14;
|
||||||
|
mainText.resizeTextMinSize = 10;
|
||||||
|
s_childListTexts.Add(mainText);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
243
src/Inspectors/GOInspector/ComponentList.cs
Normal file
243
src/Inspectors/GOInspector/ComponentList.cs
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
|
using UnityExplorer.UI;
|
||||||
|
using UnityExplorer.UI.Shared;
|
||||||
|
using UnityExplorer.Unstrip.ColorUtility;
|
||||||
|
using UnityExplorer.Unstrip.LayerMasks;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Input;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Inspectors.GOInspector
|
||||||
|
{
|
||||||
|
public class ComponentList
|
||||||
|
{
|
||||||
|
internal static ComponentList Instance;
|
||||||
|
|
||||||
|
public ComponentList()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PageHandler s_compListPageHandler;
|
||||||
|
private static Component[] s_allComps = new Component[0];
|
||||||
|
private static readonly List<Component> s_compShortlist = new List<Component>();
|
||||||
|
private static GameObject s_compListContent;
|
||||||
|
private static readonly List<Text> s_compListTexts = new List<Text>();
|
||||||
|
private static int s_lastCompCount;
|
||||||
|
public static readonly List<Toggle> s_compToggles = new List<Toggle>();
|
||||||
|
|
||||||
|
internal void RefreshComponentList()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
|
||||||
|
s_allComps = go.GetComponents<Component>().ToArray();
|
||||||
|
|
||||||
|
var components = s_allComps;
|
||||||
|
s_compListPageHandler.ListCount = components.Length;
|
||||||
|
|
||||||
|
//int startIndex = m_sceneListPageHandler.StartIndex;
|
||||||
|
|
||||||
|
int newCount = 0;
|
||||||
|
|
||||||
|
foreach (var itemIndex in s_compListPageHandler)
|
||||||
|
{
|
||||||
|
newCount++;
|
||||||
|
|
||||||
|
// normalized index starting from 0
|
||||||
|
var i = itemIndex - s_compListPageHandler.StartIndex;
|
||||||
|
|
||||||
|
if (itemIndex >= components.Length)
|
||||||
|
{
|
||||||
|
if (i > s_lastCompCount || i >= s_compListTexts.Count)
|
||||||
|
break;
|
||||||
|
|
||||||
|
GameObject label = s_compListTexts[i].transform.parent.parent.gameObject;
|
||||||
|
if (label.activeSelf)
|
||||||
|
label.SetActive(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Component comp = components[itemIndex];
|
||||||
|
|
||||||
|
if (!comp)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i >= s_compShortlist.Count)
|
||||||
|
{
|
||||||
|
s_compShortlist.Add(comp);
|
||||||
|
AddCompListButton();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_compShortlist[i] = comp;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = s_compListTexts[i];
|
||||||
|
|
||||||
|
text.text = ReflectionHelpers.GetActualType(comp).FullName;
|
||||||
|
|
||||||
|
var toggle = s_compToggles[i];
|
||||||
|
if (comp is Behaviour behaviour)
|
||||||
|
{
|
||||||
|
if (!toggle.gameObject.activeSelf)
|
||||||
|
toggle.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
toggle.isOn = behaviour.enabled;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (toggle.gameObject.activeSelf)
|
||||||
|
toggle.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var label = text.transform.parent.parent.gameObject;
|
||||||
|
if (!label.activeSelf)
|
||||||
|
{
|
||||||
|
label.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s_lastCompCount = newCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnCompToggleClicked(int index, bool value)
|
||||||
|
{
|
||||||
|
var comp = s_compShortlist[index];
|
||||||
|
|
||||||
|
(comp as Behaviour).enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnCompListObjectClicked(int index)
|
||||||
|
{
|
||||||
|
if (index >= s_compShortlist.Count || !s_compShortlist[index])
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InspectorManager.Instance.Inspect(s_compShortlist[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnCompListPageTurn()
|
||||||
|
{
|
||||||
|
if (Instance == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Instance.RefreshComponentList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
|
internal void ConstructCompList(GameObject parent)
|
||||||
|
{
|
||||||
|
var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1, 1, 1, 0));
|
||||||
|
var vertGroup = vertGroupObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
vertGroup.childForceExpandHeight = false;
|
||||||
|
vertGroup.childForceExpandWidth = false;
|
||||||
|
vertGroup.childControlWidth = true;
|
||||||
|
vertGroup.spacing = 5;
|
||||||
|
var vertLayout = vertGroupObj.AddComponent<LayoutElement>();
|
||||||
|
vertLayout.minWidth = 120;
|
||||||
|
vertLayout.flexibleWidth = 25000;
|
||||||
|
vertLayout.minHeight = 200;
|
||||||
|
vertLayout.flexibleHeight = 5000;
|
||||||
|
|
||||||
|
var compTitleObj = UIFactory.CreateLabel(vertGroupObj, TextAnchor.MiddleLeft);
|
||||||
|
var compTitleText = compTitleObj.GetComponent<Text>();
|
||||||
|
compTitleText.text = "Components";
|
||||||
|
compTitleText.color = Color.grey;
|
||||||
|
compTitleText.fontSize = 14;
|
||||||
|
var childTitleLayout = compTitleObj.AddComponent<LayoutElement>();
|
||||||
|
childTitleLayout.minHeight = 30;
|
||||||
|
|
||||||
|
s_compListPageHandler = new PageHandler();
|
||||||
|
s_compListPageHandler.ConstructUI(vertGroupObj);
|
||||||
|
s_compListPageHandler.OnPageChanged += OnCompListPageTurn;
|
||||||
|
|
||||||
|
var compScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_compListContent, new Color(0.07f, 0.07f, 0.07f));
|
||||||
|
var contentLayout = compScrollObj.AddComponent<LayoutElement>();
|
||||||
|
contentLayout.minHeight = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void AddCompListButton()
|
||||||
|
{
|
||||||
|
int thisIndex = s_compListTexts.Count;
|
||||||
|
|
||||||
|
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_compListContent, new Color(0.07f, 0.07f, 0.07f));
|
||||||
|
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
btnGroup.childForceExpandWidth = true;
|
||||||
|
btnGroup.childControlWidth = true;
|
||||||
|
btnGroup.childForceExpandHeight = false;
|
||||||
|
btnGroup.childControlHeight = true;
|
||||||
|
btnGroup.childAlignment = TextAnchor.MiddleLeft;
|
||||||
|
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
|
||||||
|
btnLayout.minWidth = 25;
|
||||||
|
btnLayout.flexibleWidth = 999;
|
||||||
|
btnLayout.minHeight = 25;
|
||||||
|
btnLayout.flexibleHeight = 0;
|
||||||
|
btnGroupObj.AddComponent<Mask>();
|
||||||
|
|
||||||
|
// Behaviour enabled toggle
|
||||||
|
|
||||||
|
var toggleObj = UIFactory.CreateToggle(btnGroupObj, out Toggle toggle, out Text toggleText);
|
||||||
|
var togBg = toggleObj.transform.Find("Background").GetComponent<Image>();
|
||||||
|
togBg.color = new Color(0.1f, 0.1f, 0.1f, 1);
|
||||||
|
var toggleLayout = toggleObj.AddComponent<LayoutElement>();
|
||||||
|
toggleLayout.minWidth = 25;
|
||||||
|
toggleLayout.flexibleWidth = 0;
|
||||||
|
toggleLayout.minHeight = 25;
|
||||||
|
toggleLayout.flexibleHeight = 0;
|
||||||
|
var checkImg = toggleObj.transform.Find("Background/Checkmark").GetComponent<Image>();
|
||||||
|
checkImg.color = SyntaxColors.Class_Instance.ToColor();
|
||||||
|
checkImg.color *= 0.66f;
|
||||||
|
#if CPP
|
||||||
|
toggle.onValueChanged.AddListener(new Action<bool>((bool val) => { OnCompToggleClicked(thisIndex, val); }));
|
||||||
|
#else
|
||||||
|
toggle.onValueChanged.AddListener((bool val) => { OnCompToggleClicked(thisIndex, val); });
|
||||||
|
#endif
|
||||||
|
toggleText.text = "";
|
||||||
|
s_compToggles.Add(toggle);
|
||||||
|
|
||||||
|
// Main component button
|
||||||
|
|
||||||
|
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
|
||||||
|
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
|
||||||
|
mainBtnLayout.minHeight = 25;
|
||||||
|
mainBtnLayout.flexibleHeight = 0;
|
||||||
|
mainBtnLayout.minWidth = 25;
|
||||||
|
mainBtnLayout.flexibleWidth = 999;
|
||||||
|
Button mainBtn = mainButtonObj.GetComponent<Button>();
|
||||||
|
ColorBlock mainColors = mainBtn.colors;
|
||||||
|
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);
|
||||||
|
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||||
|
mainBtn.colors = mainColors;
|
||||||
|
#if CPP
|
||||||
|
mainBtn.onClick.AddListener(new Action(() => { OnCompListObjectClicked(thisIndex); }));
|
||||||
|
#else
|
||||||
|
mainBtn.onClick.AddListener(() => { OnCompListObjectClicked(thisIndex); });
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Component button text
|
||||||
|
|
||||||
|
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
|
||||||
|
mainText.alignment = TextAnchor.MiddleLeft;
|
||||||
|
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
mainText.color = SyntaxColors.Class_Instance.ToColor();
|
||||||
|
mainText.resizeTextForBestFit = true;
|
||||||
|
mainText.resizeTextMaxSize = 14;
|
||||||
|
mainText.resizeTextMinSize = 8;
|
||||||
|
|
||||||
|
s_compListTexts.Add(mainText);
|
||||||
|
|
||||||
|
// TODO remove component button
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
638
src/Inspectors/GOInspector/GameObjectControls.cs
Normal file
638
src/Inspectors/GOInspector/GameObjectControls.cs
Normal file
@ -0,0 +1,638 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
|
using UnityExplorer.UI;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Input;
|
||||||
|
using UnityExplorer.Unstrip.Resources;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Inspectors.GOInspector
|
||||||
|
{
|
||||||
|
public class GameObjectControls
|
||||||
|
{
|
||||||
|
internal static GameObjectControls Instance;
|
||||||
|
|
||||||
|
public GameObjectControls()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TMP_InputField s_setParentInput;
|
||||||
|
|
||||||
|
private static ControlEditor s_positionControl;
|
||||||
|
private static ControlEditor s_localPosControl;
|
||||||
|
private static ControlEditor s_rotationControl;
|
||||||
|
private static ControlEditor s_scaleControl;
|
||||||
|
|
||||||
|
// Transform Vector editors
|
||||||
|
|
||||||
|
internal struct ControlEditor
|
||||||
|
{
|
||||||
|
public TMP_InputField fullValue;
|
||||||
|
public Slider[] sliders;
|
||||||
|
public TMP_InputField[] inputs;
|
||||||
|
public Text[] values;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool s_sliderChangedWanted;
|
||||||
|
private static Slider s_currentSlider;
|
||||||
|
private static ControlType s_currentSliderType;
|
||||||
|
private static VectorValue s_currentSliderValueType;
|
||||||
|
private static float s_currentSliderValue;
|
||||||
|
|
||||||
|
internal enum ControlType
|
||||||
|
{
|
||||||
|
position,
|
||||||
|
localPosition,
|
||||||
|
eulerAngles,
|
||||||
|
localScale
|
||||||
|
}
|
||||||
|
|
||||||
|
internal enum VectorValue
|
||||||
|
{
|
||||||
|
x, y, z
|
||||||
|
};
|
||||||
|
|
||||||
|
internal void RefreshControls()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
|
||||||
|
s_positionControl.fullValue.text = go.transform.position.ToStringLong();
|
||||||
|
s_positionControl.values[0].text = go.transform.position.x.ToString("F3");
|
||||||
|
s_positionControl.values[1].text = go.transform.position.y.ToString("F3");
|
||||||
|
s_positionControl.values[2].text = go.transform.position.z.ToString("F3");
|
||||||
|
|
||||||
|
s_localPosControl.fullValue.text = go.transform.localPosition.ToStringLong();
|
||||||
|
s_localPosControl.values[0].text = go.transform.localPosition.x.ToString("F3");
|
||||||
|
s_localPosControl.values[1].text = go.transform.localPosition.y.ToString("F3");
|
||||||
|
s_localPosControl.values[2].text = go.transform.localPosition.z.ToString("F3");
|
||||||
|
|
||||||
|
s_rotationControl.fullValue.text = go.transform.eulerAngles.ToStringLong();
|
||||||
|
s_rotationControl.values[0].text = go.transform.eulerAngles.x.ToString("F3");
|
||||||
|
s_rotationControl.values[1].text = go.transform.eulerAngles.y.ToString("F3");
|
||||||
|
s_rotationControl.values[2].text = go.transform.eulerAngles.z.ToString("F3");
|
||||||
|
|
||||||
|
s_scaleControl.fullValue.text = go.transform.localScale.ToStringLong();
|
||||||
|
s_scaleControl.values[0].text = go.transform.localScale.x.ToString("F3");
|
||||||
|
s_scaleControl.values[1].text = go.transform.localScale.y.ToString("F3");
|
||||||
|
s_scaleControl.values[2].text = go.transform.localScale.z.ToString("F3");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnSetParentClicked()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
|
||||||
|
if (!go)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var input = s_setParentInput.text;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(input))
|
||||||
|
{
|
||||||
|
go.transform.parent = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (GameObject.Find(input) is GameObject newParent)
|
||||||
|
{
|
||||||
|
go.transform.parent = newParent.transform;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ExplorerCore.Log($"Could not find any GameObject from name or path '{input}'! Note: The target must be enabled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnSliderControlChanged(float value, Slider slider, ControlType controlType, VectorValue vectorValue)
|
||||||
|
{
|
||||||
|
if (value == 0)
|
||||||
|
s_sliderChangedWanted = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!s_sliderChangedWanted)
|
||||||
|
{
|
||||||
|
s_sliderChangedWanted = true;
|
||||||
|
s_currentSlider = slider;
|
||||||
|
s_currentSliderType = controlType;
|
||||||
|
s_currentSliderValueType = vectorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_currentSliderValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void UpdateSliderControl()
|
||||||
|
{
|
||||||
|
if (!InputManager.GetMouseButton(0))
|
||||||
|
{
|
||||||
|
s_sliderChangedWanted = false;
|
||||||
|
s_currentSlider.value = 0;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameObjectInspector.ActiveInstance == null) return;
|
||||||
|
|
||||||
|
var transform = GameObjectInspector.ActiveInstance.TargetGO.transform;
|
||||||
|
|
||||||
|
// get the current vector for the control type
|
||||||
|
Vector3 vector = Vector2.zero;
|
||||||
|
switch (s_currentSliderType)
|
||||||
|
{
|
||||||
|
case ControlType.position:
|
||||||
|
vector = transform.position; break;
|
||||||
|
case ControlType.localPosition:
|
||||||
|
vector = transform.localPosition; break;
|
||||||
|
case ControlType.eulerAngles:
|
||||||
|
vector = transform.eulerAngles; break;
|
||||||
|
case ControlType.localScale:
|
||||||
|
vector = transform.localScale; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply vector value change
|
||||||
|
switch (s_currentSliderValueType)
|
||||||
|
{
|
||||||
|
case VectorValue.x:
|
||||||
|
vector.x += s_currentSliderValue; break;
|
||||||
|
case VectorValue.y:
|
||||||
|
vector.y += s_currentSliderValue; break;
|
||||||
|
case VectorValue.z:
|
||||||
|
vector.z += s_currentSliderValue; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set vector to transform member
|
||||||
|
switch (s_currentSliderType)
|
||||||
|
{
|
||||||
|
case ControlType.position:
|
||||||
|
transform.position = vector; break;
|
||||||
|
case ControlType.localPosition:
|
||||||
|
transform.localPosition = vector; break;
|
||||||
|
case ControlType.eulerAngles:
|
||||||
|
transform.eulerAngles = vector; break;
|
||||||
|
case ControlType.localScale:
|
||||||
|
transform.localScale = vector; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnVectorControlInputApplied(ControlType controlType, VectorValue vectorValue)
|
||||||
|
{
|
||||||
|
if (!(InspectorManager.Instance.m_activeInspector is GameObjectInspector instance)) return;
|
||||||
|
|
||||||
|
// get relevant input for controltype + value
|
||||||
|
|
||||||
|
TMP_InputField[] inputs = null;
|
||||||
|
switch (controlType)
|
||||||
|
{
|
||||||
|
case ControlType.position:
|
||||||
|
inputs = s_positionControl.inputs; break;
|
||||||
|
case ControlType.localPosition:
|
||||||
|
inputs = s_localPosControl.inputs; break;
|
||||||
|
case ControlType.eulerAngles:
|
||||||
|
inputs = s_rotationControl.inputs; break;
|
||||||
|
case ControlType.localScale:
|
||||||
|
inputs = s_scaleControl.inputs; break;
|
||||||
|
}
|
||||||
|
TMP_InputField input = inputs[(int)vectorValue];
|
||||||
|
|
||||||
|
float val = float.Parse(input.text);
|
||||||
|
|
||||||
|
// apply transform value
|
||||||
|
|
||||||
|
Vector3 vector = Vector3.zero;
|
||||||
|
var transform = instance.TargetGO.transform;
|
||||||
|
switch (controlType)
|
||||||
|
{
|
||||||
|
case ControlType.position:
|
||||||
|
vector = transform.position; break;
|
||||||
|
case ControlType.localPosition:
|
||||||
|
vector = transform.localPosition; break;
|
||||||
|
case ControlType.eulerAngles:
|
||||||
|
vector = transform.eulerAngles; break;
|
||||||
|
case ControlType.localScale:
|
||||||
|
vector = transform.localScale; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (vectorValue)
|
||||||
|
{
|
||||||
|
case VectorValue.x:
|
||||||
|
vector.x = val; break;
|
||||||
|
case VectorValue.y:
|
||||||
|
vector.y = val; break;
|
||||||
|
case VectorValue.z:
|
||||||
|
vector.z = val; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set back to transform
|
||||||
|
switch (controlType)
|
||||||
|
{
|
||||||
|
case ControlType.position:
|
||||||
|
transform.position = vector; break;
|
||||||
|
case ControlType.localPosition:
|
||||||
|
transform.localPosition = vector; break;
|
||||||
|
case ControlType.eulerAngles:
|
||||||
|
transform.eulerAngles = vector; break;
|
||||||
|
case ControlType.localScale:
|
||||||
|
transform.localScale = vector; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
|
internal void ConstructControls(GameObject parent)
|
||||||
|
{
|
||||||
|
var controlsObj = UIFactory.CreateVerticalGroup(parent, new Color(0.07f, 0.07f, 0.07f));
|
||||||
|
var controlsGroup = controlsObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
controlsGroup.childForceExpandWidth = false;
|
||||||
|
controlsGroup.childControlWidth = true;
|
||||||
|
controlsGroup.childForceExpandHeight = false;
|
||||||
|
controlsGroup.spacing = 5;
|
||||||
|
controlsGroup.padding.top = 4;
|
||||||
|
controlsGroup.padding.left = 4;
|
||||||
|
controlsGroup.padding.right = 4;
|
||||||
|
controlsGroup.padding.bottom = 4;
|
||||||
|
|
||||||
|
// ~~~~~~ Top row ~~~~~~
|
||||||
|
|
||||||
|
var topRow = UIFactory.CreateHorizontalGroup(controlsObj, new Color(1, 1, 1, 0));
|
||||||
|
var topRowGroup = topRow.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
topRowGroup.childForceExpandWidth = false;
|
||||||
|
topRowGroup.childControlWidth = true;
|
||||||
|
topRowGroup.childForceExpandHeight = false;
|
||||||
|
topRowGroup.childControlHeight = true;
|
||||||
|
topRowGroup.spacing = 5;
|
||||||
|
|
||||||
|
var hideButtonObj = UIFactory.CreateButton(topRow);
|
||||||
|
var hideButton = hideButtonObj.GetComponent<Button>();
|
||||||
|
var hideColors = hideButton.colors;
|
||||||
|
hideColors.normalColor = new Color(0.16f, 0.16f, 0.16f);
|
||||||
|
hideButton.colors = hideColors;
|
||||||
|
var hideText = hideButtonObj.GetComponentInChildren<Text>();
|
||||||
|
hideText.text = "Show";
|
||||||
|
hideText.fontSize = 14;
|
||||||
|
var hideButtonLayout = hideButtonObj.AddComponent<LayoutElement>();
|
||||||
|
hideButtonLayout.minWidth = 40;
|
||||||
|
hideButtonLayout.flexibleWidth = 0;
|
||||||
|
hideButtonLayout.minHeight = 25;
|
||||||
|
hideButtonLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
var topTitle = UIFactory.CreateLabel(topRow, TextAnchor.MiddleLeft);
|
||||||
|
var topText = topTitle.GetComponent<Text>();
|
||||||
|
topText.text = "Controls";
|
||||||
|
var titleLayout = topTitle.AddComponent<LayoutElement>();
|
||||||
|
titleLayout.minWidth = 100;
|
||||||
|
titleLayout.flexibleWidth = 9500;
|
||||||
|
titleLayout.minHeight = 25;
|
||||||
|
|
||||||
|
//// ~~~~~~~~ Content ~~~~~~~~ //
|
||||||
|
|
||||||
|
var contentObj = UIFactory.CreateVerticalGroup(controlsObj, new Color(1, 1, 1, 0));
|
||||||
|
var contentGroup = contentObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
contentGroup.childForceExpandHeight = false;
|
||||||
|
contentGroup.childControlHeight = true;
|
||||||
|
contentGroup.spacing = 5;
|
||||||
|
contentGroup.childForceExpandWidth = true;
|
||||||
|
contentGroup.childControlWidth = true;
|
||||||
|
|
||||||
|
// ~~ add hide button callback now that we have scroll reference ~~
|
||||||
|
#if CPP
|
||||||
|
hideButton.onClick.AddListener(new Action(OnHideClicked));
|
||||||
|
#else
|
||||||
|
hideButton.onClick.AddListener(OnHideClicked);
|
||||||
|
#endif
|
||||||
|
void OnHideClicked()
|
||||||
|
{
|
||||||
|
if (hideText.text == "Show")
|
||||||
|
{
|
||||||
|
hideText.text = "Hide";
|
||||||
|
contentObj.SetActive(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hideText.text = "Show";
|
||||||
|
contentObj.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set parent
|
||||||
|
ConstructSetParent(contentObj);
|
||||||
|
|
||||||
|
// transform controls
|
||||||
|
ConstructVector3Editor(contentObj, "Position", ControlType.position, out s_positionControl);
|
||||||
|
ConstructVector3Editor(contentObj, "Local Position", ControlType.localPosition, out s_localPosControl);
|
||||||
|
ConstructVector3Editor(contentObj, "Rotation", ControlType.eulerAngles, out s_rotationControl);
|
||||||
|
ConstructVector3Editor(contentObj, "Scale", ControlType.localScale, out s_scaleControl);
|
||||||
|
|
||||||
|
// bottom row buttons
|
||||||
|
ConstructBottomButtons(contentObj);
|
||||||
|
|
||||||
|
// set controls content inactive now that content is made (otherwise TMP font size goes way too big?)
|
||||||
|
contentObj.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ConstructSetParent(GameObject contentObj)
|
||||||
|
{
|
||||||
|
var setParentGroupObj = UIFactory.CreateHorizontalGroup(contentObj, new Color(1, 1, 1, 0));
|
||||||
|
var setParentGroup = setParentGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
setParentGroup.childForceExpandHeight = false;
|
||||||
|
setParentGroup.childControlHeight = true;
|
||||||
|
setParentGroup.childForceExpandWidth = false;
|
||||||
|
setParentGroup.childControlWidth = true;
|
||||||
|
setParentGroup.spacing = 5;
|
||||||
|
var setParentLayout = setParentGroupObj.AddComponent<LayoutElement>();
|
||||||
|
setParentLayout.minHeight = 25;
|
||||||
|
setParentLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
var setParentLabelObj = UIFactory.CreateLabel(setParentGroupObj, TextAnchor.MiddleLeft);
|
||||||
|
var setParentLabel = setParentLabelObj.GetComponent<Text>();
|
||||||
|
setParentLabel.text = "Set Parent:";
|
||||||
|
setParentLabel.color = Color.grey;
|
||||||
|
setParentLabel.fontSize = 14;
|
||||||
|
var setParentLabelLayout = setParentLabelObj.AddComponent<LayoutElement>();
|
||||||
|
setParentLabelLayout.minWidth = 110;
|
||||||
|
setParentLabelLayout.minHeight = 25;
|
||||||
|
setParentLabelLayout.flexibleWidth = 0;
|
||||||
|
|
||||||
|
var setParentInputObj = UIFactory.CreateTMPInput(setParentGroupObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
|
||||||
|
s_setParentInput = setParentInputObj.GetComponent<TMP_InputField>();
|
||||||
|
var placeholderInput = setParentInputObj.transform.Find("TextArea/Placeholder").GetComponent<TextMeshProUGUI>();
|
||||||
|
placeholderInput.text = "Enter a GameObject name or path...";
|
||||||
|
var setParentInputLayout = setParentInputObj.AddComponent<LayoutElement>();
|
||||||
|
setParentInputLayout.minHeight = 25;
|
||||||
|
setParentInputLayout.preferredWidth = 400;
|
||||||
|
setParentInputLayout.flexibleWidth = 9999;
|
||||||
|
|
||||||
|
var applyButtonObj = UIFactory.CreateButton(setParentGroupObj);
|
||||||
|
var applyButton = applyButtonObj.GetComponent<Button>();
|
||||||
|
#if CPP
|
||||||
|
applyButton.onClick.AddListener(new Action(OnSetParentClicked));
|
||||||
|
#else
|
||||||
|
applyButton.onClick.AddListener(OnSetParentClicked);
|
||||||
|
#endif
|
||||||
|
var applyText = applyButtonObj.GetComponentInChildren<Text>();
|
||||||
|
applyText.text = "Apply";
|
||||||
|
var applyLayout = applyButtonObj.AddComponent<LayoutElement>();
|
||||||
|
applyLayout.minWidth = 55;
|
||||||
|
applyLayout.flexibleWidth = 0;
|
||||||
|
applyLayout.minHeight = 25;
|
||||||
|
applyLayout.flexibleHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ConstructVector3Editor(GameObject parent, string title, ControlType type, out ControlEditor editor)
|
||||||
|
{
|
||||||
|
editor = new ControlEditor();
|
||||||
|
|
||||||
|
var topBarObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||||
|
var topGroup = topBarObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
topGroup.childForceExpandWidth = false;
|
||||||
|
topGroup.childControlWidth = true;
|
||||||
|
topGroup.childForceExpandHeight = false;
|
||||||
|
topGroup.childControlHeight = true;
|
||||||
|
topGroup.spacing = 5;
|
||||||
|
var topLayout = topBarObj.AddComponent<LayoutElement>();
|
||||||
|
topLayout.minHeight = 25;
|
||||||
|
topLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
var titleObj = UIFactory.CreateLabel(topBarObj, TextAnchor.MiddleLeft);
|
||||||
|
var titleText = titleObj.GetComponent<Text>();
|
||||||
|
titleText.text = title;
|
||||||
|
titleText.color = Color.grey;
|
||||||
|
titleText.fontSize = 14;
|
||||||
|
var titleLayout = titleObj.AddComponent<LayoutElement>();
|
||||||
|
titleLayout.minWidth = 110;
|
||||||
|
titleLayout.flexibleWidth = 0;
|
||||||
|
titleLayout.minHeight = 25;
|
||||||
|
|
||||||
|
// expand button
|
||||||
|
var expandButtonObj = UIFactory.CreateButton(topBarObj);
|
||||||
|
var expandButton = expandButtonObj.GetComponent<Button>();
|
||||||
|
var expandText = expandButtonObj.GetComponentInChildren<Text>();
|
||||||
|
expandText.text = "▼";
|
||||||
|
expandText.fontSize = 12;
|
||||||
|
var btnLayout = expandButtonObj.AddComponent<LayoutElement>();
|
||||||
|
btnLayout.minWidth = 35;
|
||||||
|
btnLayout.flexibleWidth = 0;
|
||||||
|
btnLayout.minHeight = 25;
|
||||||
|
btnLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
// readonly value input
|
||||||
|
|
||||||
|
var valueInputObj = UIFactory.CreateTMPInput(topBarObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
|
||||||
|
var valueInput = valueInputObj.GetComponent<TMP_InputField>();
|
||||||
|
valueInput.readOnly = true;
|
||||||
|
var valueInputLayout = valueInputObj.AddComponent<LayoutElement>();
|
||||||
|
valueInputLayout.minHeight = 25;
|
||||||
|
valueInputLayout.flexibleHeight = 0;
|
||||||
|
valueInputLayout.preferredWidth = 400;
|
||||||
|
valueInputLayout.flexibleWidth = 9999;
|
||||||
|
|
||||||
|
editor.fullValue = valueInput;
|
||||||
|
|
||||||
|
editor.sliders = new Slider[3];
|
||||||
|
editor.inputs = new TMP_InputField[3];
|
||||||
|
editor.values = new Text[3];
|
||||||
|
|
||||||
|
var xRow = ConstructEditorRow(parent, editor, type, VectorValue.x);
|
||||||
|
xRow.SetActive(false);
|
||||||
|
var yRow = ConstructEditorRow(parent, editor, type, VectorValue.y);
|
||||||
|
yRow.SetActive(false);
|
||||||
|
var zRow = ConstructEditorRow(parent, editor, type, VectorValue.z);
|
||||||
|
zRow.SetActive(false);
|
||||||
|
|
||||||
|
// add expand callback now that we have group reference
|
||||||
|
#if CPP
|
||||||
|
expandButton.onClick.AddListener(new Action(ToggleExpand));
|
||||||
|
#else
|
||||||
|
expandButton.onClick.AddListener(ToggleExpand);
|
||||||
|
#endif
|
||||||
|
void ToggleExpand()
|
||||||
|
{
|
||||||
|
if (xRow.activeSelf)
|
||||||
|
{
|
||||||
|
xRow.SetActive(false);
|
||||||
|
yRow.SetActive(false);
|
||||||
|
zRow.SetActive(false);
|
||||||
|
expandText.text = "▼";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xRow.SetActive(true);
|
||||||
|
yRow.SetActive(true);
|
||||||
|
zRow.SetActive(true);
|
||||||
|
expandText.text = "▲";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal GameObject ConstructEditorRow(GameObject parent, ControlEditor editor, ControlType type, VectorValue vectorValue)
|
||||||
|
{
|
||||||
|
var rowObject = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||||
|
var rowGroup = rowObject.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
rowGroup.childForceExpandWidth = false;
|
||||||
|
rowGroup.childControlWidth = true;
|
||||||
|
rowGroup.childForceExpandHeight = false;
|
||||||
|
rowGroup.childControlHeight = true;
|
||||||
|
rowGroup.spacing = 5;
|
||||||
|
var rowLayout = rowObject.AddComponent<LayoutElement>();
|
||||||
|
rowLayout.minHeight = 25;
|
||||||
|
rowLayout.flexibleHeight = 0;
|
||||||
|
rowLayout.minWidth = 100;
|
||||||
|
|
||||||
|
// Value labels
|
||||||
|
|
||||||
|
var labelObj = UIFactory.CreateLabel(rowObject, TextAnchor.MiddleLeft);
|
||||||
|
var labelText = labelObj.GetComponent<Text>();
|
||||||
|
labelText.color = Color.cyan;
|
||||||
|
labelText.text = $"{vectorValue.ToString().ToUpper()}:";
|
||||||
|
labelText.fontSize = 14;
|
||||||
|
labelText.resizeTextMaxSize = 14;
|
||||||
|
labelText.resizeTextForBestFit = true;
|
||||||
|
var labelLayout = labelObj.AddComponent<LayoutElement>();
|
||||||
|
labelLayout.minHeight = 25;
|
||||||
|
labelLayout.flexibleHeight = 0;
|
||||||
|
labelLayout.minWidth = 25;
|
||||||
|
labelLayout.flexibleWidth = 0;
|
||||||
|
|
||||||
|
// actual value label
|
||||||
|
var valueLabelObj = UIFactory.CreateLabel(rowObject, TextAnchor.MiddleLeft);
|
||||||
|
var valueLabel = valueLabelObj.GetComponent<Text>();
|
||||||
|
editor.values[(int)vectorValue] = valueLabel;
|
||||||
|
var valueLabelLayout = valueLabelObj.AddComponent<LayoutElement>();
|
||||||
|
valueLabelLayout.minWidth = 85;
|
||||||
|
valueLabelLayout.flexibleWidth = 0;
|
||||||
|
valueLabelLayout.minHeight = 25;
|
||||||
|
|
||||||
|
// Slider
|
||||||
|
|
||||||
|
var sliderObj = UIFactory.CreateSlider(rowObject);
|
||||||
|
var sliderLayout = sliderObj.AddComponent<LayoutElement>();
|
||||||
|
sliderLayout.minHeight = 20;
|
||||||
|
sliderLayout.flexibleHeight = 0;
|
||||||
|
sliderLayout.minWidth = 200;
|
||||||
|
sliderLayout.flexibleWidth = 9000;
|
||||||
|
var slider = sliderObj.GetComponent<Slider>();
|
||||||
|
slider.minValue = -2;
|
||||||
|
slider.maxValue = 2;
|
||||||
|
slider.value = 0;
|
||||||
|
#if CPP
|
||||||
|
slider.onValueChanged.AddListener(new Action<float>((float val) => { OnSliderControlChanged(val, slider, type, vectorValue); }));
|
||||||
|
#else
|
||||||
|
slider.onValueChanged.AddListener((float val) => { OnSliderControlChanged(val, slider, type, vectorValue); });
|
||||||
|
#endif
|
||||||
|
editor.sliders[(int)vectorValue] = slider;
|
||||||
|
|
||||||
|
// input field
|
||||||
|
|
||||||
|
var inputHolder = UIFactory.CreateVerticalGroup(rowObject, new Color(1, 1, 1, 0));
|
||||||
|
var inputHolderGroup = inputHolder.GetComponent<VerticalLayoutGroup>();
|
||||||
|
inputHolderGroup.childForceExpandHeight = false;
|
||||||
|
inputHolderGroup.childControlHeight = true;
|
||||||
|
inputHolderGroup.childForceExpandWidth = false;
|
||||||
|
inputHolderGroup.childControlWidth = true;
|
||||||
|
|
||||||
|
var inputObj = UIFactory.CreateTMPInput(inputHolder, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
|
||||||
|
var input = inputObj.GetComponent<TMP_InputField>();
|
||||||
|
input.characterValidation = TMP_InputField.CharacterValidation.Decimal;
|
||||||
|
|
||||||
|
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
||||||
|
inputLayout.minHeight = 25;
|
||||||
|
inputLayout.flexibleHeight = 0;
|
||||||
|
inputLayout.minWidth = 90;
|
||||||
|
inputLayout.flexibleWidth = 50;
|
||||||
|
|
||||||
|
editor.inputs[(int)vectorValue] = input;
|
||||||
|
|
||||||
|
// apply button
|
||||||
|
|
||||||
|
var applyBtnObj = UIFactory.CreateButton(rowObject);
|
||||||
|
var applyBtn = applyBtnObj.GetComponent<Button>();
|
||||||
|
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||||
|
applyText.text = "Apply";
|
||||||
|
applyText.fontSize = 14;
|
||||||
|
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||||
|
applyLayout.minWidth = 60;
|
||||||
|
applyLayout.minHeight = 25;
|
||||||
|
|
||||||
|
#if MONO
|
||||||
|
applyBtn.onClick.AddListener(() => { OnVectorControlInputApplied(type, vectorValue); });
|
||||||
|
#else
|
||||||
|
applyBtn.onClick.AddListener(new Action(() => { OnVectorControlInputApplied(type, vectorValue); }));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return rowObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ConstructBottomButtons(GameObject contentObj)
|
||||||
|
{
|
||||||
|
var bottomRow = UIFactory.CreateHorizontalGroup(contentObj, new Color(1, 1, 1, 0));
|
||||||
|
var bottomGroup = bottomRow.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
bottomGroup.childForceExpandWidth = true;
|
||||||
|
bottomGroup.childControlWidth = true;
|
||||||
|
bottomGroup.spacing = 4;
|
||||||
|
var bottomLayout = bottomRow.AddComponent<LayoutElement>();
|
||||||
|
bottomLayout.minHeight = 25;
|
||||||
|
|
||||||
|
var instantiateBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
|
||||||
|
var instantiateBtn = instantiateBtnObj.GetComponent<Button>();
|
||||||
|
instantiateBtn.onClick.AddListener(InstantiateBtn);
|
||||||
|
var instantiateText = instantiateBtnObj.GetComponentInChildren<Text>();
|
||||||
|
instantiateText.text = "Instantiate";
|
||||||
|
instantiateText.fontSize = 14;
|
||||||
|
var instantiateLayout = instantiateBtnObj.AddComponent<LayoutElement>();
|
||||||
|
instantiateLayout.minWidth = 150;
|
||||||
|
|
||||||
|
void InstantiateBtn()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
if (!go)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var clone = GameObject.Instantiate(go);
|
||||||
|
InspectorManager.Instance.Inspect(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dontDestroyBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
|
||||||
|
var dontDestroyBtn = dontDestroyBtnObj.GetComponent<Button>();
|
||||||
|
dontDestroyBtn.onClick.AddListener(DontDestroyOnLoadBtn);
|
||||||
|
var dontDestroyText = dontDestroyBtnObj.GetComponentInChildren<Text>();
|
||||||
|
dontDestroyText.text = "Set DontDestroyOnLoad";
|
||||||
|
dontDestroyText.fontSize = 14;
|
||||||
|
var dontDestroyLayout = dontDestroyBtnObj.AddComponent<LayoutElement>();
|
||||||
|
dontDestroyLayout.flexibleWidth = 5000;
|
||||||
|
|
||||||
|
void DontDestroyOnLoadBtn()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
if (!go)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GameObject.DontDestroyOnLoad(go);
|
||||||
|
}
|
||||||
|
|
||||||
|
var destroyBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
|
||||||
|
var destroyBtn = destroyBtnObj.GetComponent<Button>();
|
||||||
|
destroyBtn.onClick.AddListener(DestroyBtn);
|
||||||
|
var destroyText = destroyBtnObj.GetComponentInChildren<Text>();
|
||||||
|
destroyText.text = "Destroy";
|
||||||
|
destroyText.fontSize = 14;
|
||||||
|
destroyText.color = Color.red;
|
||||||
|
var destroyLayout = destroyBtnObj.AddComponent<LayoutElement>();
|
||||||
|
destroyLayout.minWidth = 150;
|
||||||
|
|
||||||
|
void DestroyBtn()
|
||||||
|
{
|
||||||
|
var go = GameObjectInspector.ActiveInstance.TargetGO;
|
||||||
|
if (!go)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GameObject.Destroy(go);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ using UnityExplorer.UI.PageModel;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using TMPro;
|
||||||
|
|
||||||
namespace UnityExplorer.Inspectors
|
namespace UnityExplorer.Inspectors
|
||||||
{
|
{
|
||||||
@ -26,6 +27,8 @@ namespace UnityExplorer.Inspectors
|
|||||||
public GameObject m_tabBarContent;
|
public GameObject m_tabBarContent;
|
||||||
public GameObject m_inspectorContent;
|
public GameObject m_inspectorContent;
|
||||||
|
|
||||||
|
private readonly List<Text> testTexts = new List<Text>();
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_currentInspectors.Count; i++)
|
for (int i = 0; i < m_currentInspectors.Count; i++)
|
||||||
@ -35,6 +38,12 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
m_currentInspectors[i].Update();
|
m_currentInspectors[i].Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ======= test ======== //
|
||||||
|
foreach (var text in testTexts)
|
||||||
|
{
|
||||||
|
text.text = Time.time.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Inspect(object obj)
|
public void Inspect(object obj)
|
||||||
@ -129,27 +138,44 @@ namespace UnityExplorer.Inspectors
|
|||||||
public void ConstructInspectorPane()
|
public void ConstructInspectorPane()
|
||||||
{
|
{
|
||||||
var mainObj = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f));
|
var mainObj = UIFactory.CreateVerticalGroup(HomePage.Instance.Content, new Color(72f / 255f, 72f / 255f, 72f / 255f));
|
||||||
LayoutElement rightLayout = mainObj.AddComponent<LayoutElement>();
|
LayoutElement mainLayout = mainObj.AddComponent<LayoutElement>();
|
||||||
rightLayout.flexibleWidth = 999999;
|
mainLayout.preferredHeight = 400;
|
||||||
|
mainLayout.flexibleHeight = 9000;
|
||||||
|
mainLayout.preferredWidth = 620;
|
||||||
|
mainLayout.flexibleWidth = 9000;
|
||||||
|
|
||||||
var rightGroup = mainObj.GetComponent<VerticalLayoutGroup>();
|
var mainGroup = mainObj.GetComponent<VerticalLayoutGroup>();
|
||||||
rightGroup.childForceExpandHeight = true;
|
mainGroup.childForceExpandHeight = true;
|
||||||
rightGroup.childForceExpandWidth = true;
|
mainGroup.childForceExpandWidth = true;
|
||||||
rightGroup.childControlHeight = true;
|
mainGroup.childControlHeight = true;
|
||||||
rightGroup.childControlWidth = true;
|
mainGroup.childControlWidth = true;
|
||||||
rightGroup.spacing = 10;
|
mainGroup.spacing = 2;
|
||||||
rightGroup.padding.left = 8;
|
mainGroup.padding.left = 4;
|
||||||
rightGroup.padding.right = 8;
|
mainGroup.padding.right = 4;
|
||||||
rightGroup.padding.top = 8;
|
mainGroup.padding.top = 4;
|
||||||
rightGroup.padding.bottom = 8;
|
mainGroup.padding.bottom = 4;
|
||||||
|
|
||||||
var inspectorTitle = UIFactory.CreateLabel(mainObj, TextAnchor.UpperLeft);
|
var topRowObj = UIFactory.CreateHorizontalGroup(mainObj, new Color(1, 1, 1, 0));
|
||||||
|
var topRowGroup = topRowObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
topRowGroup.childForceExpandWidth = false;
|
||||||
|
topRowGroup.childControlWidth = true;
|
||||||
|
topRowGroup.childForceExpandHeight = true;
|
||||||
|
topRowGroup.childControlHeight = true;
|
||||||
|
topRowGroup.spacing = 15;
|
||||||
|
|
||||||
|
var inspectorTitle = UIFactory.CreateLabel(topRowObj, TextAnchor.MiddleLeft);
|
||||||
Text title = inspectorTitle.GetComponent<Text>();
|
Text title = inspectorTitle.GetComponent<Text>();
|
||||||
title.text = "Inspector";
|
title.text = "Inspector";
|
||||||
title.fontSize = 20;
|
title.fontSize = 20;
|
||||||
var titleLayout = inspectorTitle.AddComponent<LayoutElement>();
|
var titleLayout = inspectorTitle.AddComponent<LayoutElement>();
|
||||||
titleLayout.minHeight = 30;
|
titleLayout.minHeight = 30;
|
||||||
titleLayout.flexibleHeight = 0;
|
titleLayout.flexibleHeight = 0;
|
||||||
|
titleLayout.minWidth = 90;
|
||||||
|
titleLayout.flexibleWidth = 0;
|
||||||
|
|
||||||
|
ConstructToolbar(topRowObj);
|
||||||
|
|
||||||
|
// inspector tab bar
|
||||||
|
|
||||||
m_tabBarContent = UIFactory.CreateGridGroup(mainObj, new Vector2(185, 20), new Vector2(5, 2), new Color(0.1f, 0.1f, 0.1f, 1));
|
m_tabBarContent = UIFactory.CreateGridGroup(mainObj, new Vector2(185, 20), new Vector2(5, 2), new Color(0.1f, 0.1f, 0.1f, 1));
|
||||||
|
|
||||||
@ -161,14 +187,19 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
// inspector content area
|
// inspector content area
|
||||||
|
|
||||||
m_inspectorContent = UIFactory.CreateVerticalGroup(mainObj, new Color(0.1f, 0.1f, 0.1f, 1.0f));
|
m_inspectorContent = UIFactory.CreateVerticalGroup(mainObj, new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
var inspectorGroup = m_inspectorContent.GetComponent<VerticalLayoutGroup>();
|
||||||
|
inspectorGroup.childForceExpandHeight = true;
|
||||||
|
inspectorGroup.childForceExpandWidth = true;
|
||||||
|
inspectorGroup.childControlHeight = true;
|
||||||
|
inspectorGroup.childControlWidth = true;
|
||||||
|
|
||||||
|
m_inspectorContent = UIFactory.CreateVerticalGroup(mainObj, new Color(0.1f, 0.1f, 0.1f));
|
||||||
var contentGroup = m_inspectorContent.GetComponent<VerticalLayoutGroup>();
|
var contentGroup = m_inspectorContent.GetComponent<VerticalLayoutGroup>();
|
||||||
contentGroup.childForceExpandHeight = true;
|
contentGroup.childForceExpandHeight = true;
|
||||||
contentGroup.childForceExpandWidth = true;
|
contentGroup.childForceExpandWidth = true;
|
||||||
contentGroup.childControlHeight = true;
|
contentGroup.childControlHeight = true;
|
||||||
contentGroup.childControlWidth = true;
|
contentGroup.childControlWidth = true;
|
||||||
contentGroup.spacing = 5;
|
|
||||||
contentGroup.padding.top = 5;
|
contentGroup.padding.top = 5;
|
||||||
contentGroup.padding.left = 5;
|
contentGroup.padding.left = 5;
|
||||||
contentGroup.padding.right = 5;
|
contentGroup.padding.right = 5;
|
||||||
@ -177,8 +208,129 @@ namespace UnityExplorer.Inspectors
|
|||||||
var contentLayout = m_inspectorContent.AddComponent<LayoutElement>();
|
var contentLayout = m_inspectorContent.AddComponent<LayoutElement>();
|
||||||
contentLayout.preferredHeight = 900;
|
contentLayout.preferredHeight = 900;
|
||||||
contentLayout.flexibleHeight = 10000;
|
contentLayout.flexibleHeight = 10000;
|
||||||
|
contentLayout.preferredWidth = 600;
|
||||||
|
contentLayout.flexibleWidth = 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
private static void ConstructToolbar(GameObject topRowObj)
|
||||||
|
{
|
||||||
|
var invisObj = UIFactory.CreateHorizontalGroup(topRowObj, new Color(1, 1, 1, 0));
|
||||||
|
var invisGroup = invisObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
invisGroup.childForceExpandWidth = false;
|
||||||
|
invisGroup.childForceExpandHeight = false;
|
||||||
|
invisGroup.childControlWidth = true;
|
||||||
|
invisGroup.childControlHeight = true;
|
||||||
|
invisGroup.padding.top = 2;
|
||||||
|
invisGroup.padding.bottom = 2;
|
||||||
|
invisGroup.padding.left = 2;
|
||||||
|
invisGroup.padding.right = 2;
|
||||||
|
invisGroup.spacing = 10;
|
||||||
|
|
||||||
|
// time scale group
|
||||||
|
|
||||||
|
var timeGroupObj = UIFactory.CreateHorizontalGroup(invisObj, new Color(1, 1, 1, 0));
|
||||||
|
var timeGroup = timeGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
timeGroup.childForceExpandWidth = false;
|
||||||
|
timeGroup.childControlWidth = true;
|
||||||
|
timeGroup.childForceExpandHeight = false;
|
||||||
|
timeGroup.childControlHeight = true;
|
||||||
|
timeGroup.padding.top = 2;
|
||||||
|
timeGroup.padding.left = 5;
|
||||||
|
timeGroup.padding.right = 2;
|
||||||
|
timeGroup.padding.bottom = 2;
|
||||||
|
timeGroup.spacing = 5;
|
||||||
|
timeGroup.childAlignment = TextAnchor.MiddleCenter;
|
||||||
|
var timeGroupLayout = timeGroupObj.AddComponent<LayoutElement>();
|
||||||
|
timeGroupLayout.minWidth = 100;
|
||||||
|
timeGroupLayout.flexibleWidth = 300;
|
||||||
|
timeGroupLayout.minHeight = 25;
|
||||||
|
timeGroupLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
// time scale title
|
||||||
|
|
||||||
|
var timeTitleObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
|
||||||
|
var timeTitle = timeTitleObj.GetComponent<Text>();
|
||||||
|
timeTitle.text = "Time Scale:";
|
||||||
|
timeTitle.color = new Color(21f / 255f, 192f / 255f, 235f / 255f);
|
||||||
|
var titleLayout = timeTitleObj.AddComponent<LayoutElement>();
|
||||||
|
titleLayout.minHeight = 25;
|
||||||
|
titleLayout.minWidth = 80;
|
||||||
|
titleLayout.flexibleHeight = 0;
|
||||||
|
timeTitle.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
|
||||||
|
// actual active time label
|
||||||
|
|
||||||
|
var timeLabelObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
|
||||||
|
var timeLabelLayout = timeLabelObj.AddComponent<LayoutElement>();
|
||||||
|
timeLabelLayout.minWidth = 40;
|
||||||
|
timeLabelLayout.minHeight = 25;
|
||||||
|
timeLabelLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
// todo make static and update
|
||||||
|
var s_timeText = timeLabelObj.GetComponent<Text>();
|
||||||
|
s_timeText.text = Time.timeScale.ToString("F1");
|
||||||
|
|
||||||
|
// time scale input
|
||||||
|
|
||||||
|
var timeInputObj = UIFactory.CreateTMPInput(timeGroupObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
|
||||||
|
var timeInput = timeInputObj.GetComponent<TMP_InputField>();
|
||||||
|
timeInput.characterValidation = TMP_InputField.CharacterValidation.Decimal;
|
||||||
|
var timeInputLayout = timeInputObj.AddComponent<LayoutElement>();
|
||||||
|
timeInputLayout.minWidth = 90;
|
||||||
|
timeInputLayout.flexibleWidth = 0;
|
||||||
|
timeInputLayout.minHeight = 25;
|
||||||
|
timeInputLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
// time scale apply button
|
||||||
|
|
||||||
|
var applyBtnObj = UIFactory.CreateButton(timeGroupObj);
|
||||||
|
var applyBtn = applyBtnObj.GetComponent<Button>();
|
||||||
|
#if MONO
|
||||||
|
applyBtn.onClick.AddListener(SetTimeScale);
|
||||||
|
#else
|
||||||
|
applyBtn.onClick.AddListener(new Action(SetTimeScale));
|
||||||
|
#endif
|
||||||
|
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||||
|
applyText.text = "Apply";
|
||||||
|
applyText.fontSize = 14;
|
||||||
|
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||||
|
applyLayout.minWidth = 50;
|
||||||
|
applyLayout.minHeight = 25;
|
||||||
|
applyLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
void SetTimeScale()
|
||||||
|
{
|
||||||
|
var scale = float.Parse(timeInput.text);
|
||||||
|
Time.timeScale = scale;
|
||||||
|
s_timeText.text = Time.timeScale.ToString("F1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// inspect under mouse button
|
||||||
|
|
||||||
|
var inspectObj = UIFactory.CreateButton(topRowObj);
|
||||||
|
var inspectLayout = inspectObj.AddComponent<LayoutElement>();
|
||||||
|
inspectLayout.minWidth = 120;
|
||||||
|
inspectLayout.flexibleWidth = 0;
|
||||||
|
var inspectBtn = inspectObj.GetComponent<Button>();
|
||||||
|
var inspectColors = inspectBtn.colors;
|
||||||
|
inspectColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
|
||||||
|
inspectBtn.colors = inspectColors;
|
||||||
|
var inspectText = inspectObj.GetComponentInChildren<Text>();
|
||||||
|
inspectText.text = "Mouse Inspect";
|
||||||
|
inspectText.fontSize = 13;
|
||||||
|
#if MONO
|
||||||
|
inspectBtn.onClick.AddListener(OnInspectMouseClicked);
|
||||||
|
#else
|
||||||
|
inspectBtn.onClick.AddListener(new Action(OnInspectMouseClicked));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void OnInspectMouseClicked()
|
||||||
|
{
|
||||||
|
MouseInspector.StartInspect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
143
src/Inspectors/MouseInspector.cs
Normal file
143
src/Inspectors/MouseInspector.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
|
using UnityExplorer.Input;
|
||||||
|
using UnityExplorer.UI;
|
||||||
|
|
||||||
|
namespace UnityExplorer.Inspectors
|
||||||
|
{
|
||||||
|
public class MouseInspector
|
||||||
|
{
|
||||||
|
public static bool Enabled { get; set; }
|
||||||
|
|
||||||
|
//internal static Text s_objUnderMouseName;
|
||||||
|
internal static Text s_objNameLabel;
|
||||||
|
internal static Text s_objPathLabel;
|
||||||
|
internal static Text s_mousePosLabel;
|
||||||
|
|
||||||
|
private static GameObject s_lastHit;
|
||||||
|
private static Vector3 s_lastMousePos;
|
||||||
|
|
||||||
|
internal static GameObject s_UIContent;
|
||||||
|
|
||||||
|
public static void StartInspect()
|
||||||
|
{
|
||||||
|
Enabled = true;
|
||||||
|
MainMenu.Instance.MainPanel.SetActive(false);
|
||||||
|
s_UIContent.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StopInspect()
|
||||||
|
{
|
||||||
|
Enabled = false;
|
||||||
|
MainMenu.Instance.MainPanel.SetActive(true);
|
||||||
|
s_UIContent.SetActive(false);
|
||||||
|
|
||||||
|
ClearHitData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateInspect()
|
||||||
|
{
|
||||||
|
if (InputManager.GetKeyDown(KeyCode.Escape))
|
||||||
|
{
|
||||||
|
StopInspect();
|
||||||
|
}
|
||||||
|
|
||||||
|
var mousePos = InputManager.MousePosition;
|
||||||
|
|
||||||
|
if (mousePos != s_lastMousePos)
|
||||||
|
{
|
||||||
|
s_lastMousePos = mousePos;
|
||||||
|
|
||||||
|
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
|
||||||
|
|
||||||
|
s_mousePosLabel.text = $"Mouse Position: {((Vector2)InputManager.MousePosition).ToString()}";
|
||||||
|
|
||||||
|
float yFix = mousePos.y < 120 ? 80 : -80;
|
||||||
|
|
||||||
|
s_UIContent.transform.localPosition = new Vector3(inversePos.x, inversePos.y + yFix, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!UnityHelpers.MainCamera)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// actual inspect raycast
|
||||||
|
var ray = UnityHelpers.MainCamera.ScreenPointToRay(mousePos);
|
||||||
|
|
||||||
|
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
|
||||||
|
{
|
||||||
|
var obj = hit.transform.gameObject;
|
||||||
|
|
||||||
|
if (obj != s_lastHit)
|
||||||
|
{
|
||||||
|
s_lastHit = obj;
|
||||||
|
s_objNameLabel.text = $"<b>Hit:</b> <color=cyan>{obj.name}</color>";
|
||||||
|
s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (InputManager.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
StopInspect();
|
||||||
|
InspectorManager.Instance.Inspect(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (s_lastHit)
|
||||||
|
ClearHitData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void ClearHitData()
|
||||||
|
{
|
||||||
|
s_lastHit = null;
|
||||||
|
s_objNameLabel.text = "No hits...";
|
||||||
|
s_objPathLabel.text = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI Construction
|
||||||
|
|
||||||
|
internal static void ConstructUI()
|
||||||
|
{
|
||||||
|
s_UIContent = UIFactory.CreatePanel(UIManager.CanvasRoot, "MouseInspect", out GameObject content);
|
||||||
|
|
||||||
|
s_UIContent.AddComponent<Mask>();
|
||||||
|
|
||||||
|
var baseRect = s_UIContent.GetComponent<RectTransform>();
|
||||||
|
var half = new Vector2(0.5f, 0.5f);
|
||||||
|
baseRect.anchorMin = half;
|
||||||
|
baseRect.anchorMax = half;
|
||||||
|
baseRect.pivot = half;
|
||||||
|
baseRect.sizeDelta = new Vector2(700, 100);
|
||||||
|
|
||||||
|
// Title text
|
||||||
|
|
||||||
|
var titleObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||||
|
var titleText = titleObj.GetComponent<Text>();
|
||||||
|
titleText.text = "<b>Mouse Inspector</b> (press <b>ESC</b> to cancel)";
|
||||||
|
|
||||||
|
var mousePosObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||||
|
s_mousePosLabel = mousePosObj.GetComponent<Text>();
|
||||||
|
s_mousePosLabel.text = "Mouse Position:";
|
||||||
|
|
||||||
|
var hitLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||||
|
s_objNameLabel = hitLabelObj.GetComponent<Text>();
|
||||||
|
s_objNameLabel.text = "No hits...";
|
||||||
|
s_objNameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
|
||||||
|
var pathLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
|
||||||
|
s_objPathLabel = pathLabelObj.GetComponent<Text>();
|
||||||
|
s_objPathLabel.color = Color.grey;
|
||||||
|
s_objPathLabel.fontStyle = FontStyle.Italic;
|
||||||
|
s_objPathLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
|
||||||
|
s_UIContent.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,8 @@ namespace UnityExplorer.Inspectors
|
|||||||
ConstructScenePane();
|
ConstructScenePane();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool Hiding;
|
||||||
|
|
||||||
private const float UPDATE_INTERVAL = 1f;
|
private const float UPDATE_INTERVAL = 1f;
|
||||||
private float m_timeOfLastSceneUpdate;
|
private float m_timeOfLastSceneUpdate;
|
||||||
|
|
||||||
@ -34,10 +36,9 @@ namespace UnityExplorer.Inspectors
|
|||||||
private GameObject m_backButtonObj;
|
private GameObject m_backButtonObj;
|
||||||
|
|
||||||
public PageHandler m_sceneListPageHandler;
|
public PageHandler m_sceneListPageHandler;
|
||||||
|
private GameObject m_sceneListContent;
|
||||||
private GameObject[] m_allSceneListObjects = new GameObject[0];
|
private GameObject[] m_allSceneListObjects = new GameObject[0];
|
||||||
private readonly List<GameObject> m_sceneShortList = new List<GameObject>();
|
private readonly List<GameObject> m_sceneShortList = new List<GameObject>();
|
||||||
private GameObject m_sceneListContent;
|
|
||||||
private readonly List<Text> m_sceneListTexts = new List<Text>();
|
private readonly List<Text> m_sceneListTexts = new List<Text>();
|
||||||
|
|
||||||
public static int DontDestroyHandle => DontDestroyObject.scene.handle;
|
public static int DontDestroyHandle => DontDestroyObject.scene.handle;
|
||||||
@ -63,7 +64,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (Time.realtimeSinceStartup - m_timeOfLastSceneUpdate < UPDATE_INTERVAL)
|
if (Hiding || Time.realtimeSinceStartup - m_timeOfLastSceneUpdate < UPDATE_INTERVAL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -341,11 +342,14 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
m_backButtonObj = UIFactory.CreateButton(scenePathGroupObj);
|
m_backButtonObj = UIFactory.CreateButton(scenePathGroupObj);
|
||||||
Text backButtonText = m_backButtonObj.GetComponentInChildren<Text>();
|
Text backButtonText = m_backButtonObj.GetComponentInChildren<Text>();
|
||||||
backButtonText.text = "<";
|
backButtonText.text = "◄";
|
||||||
LayoutElement backButtonLayout = m_backButtonObj.AddComponent<LayoutElement>();
|
LayoutElement backButtonLayout = m_backButtonObj.AddComponent<LayoutElement>();
|
||||||
backButtonLayout.minWidth = 40;
|
backButtonLayout.minWidth = 40;
|
||||||
backButtonLayout.flexibleWidth = 0;
|
backButtonLayout.flexibleWidth = 0;
|
||||||
Button backButton = m_backButtonObj.GetComponent<Button>();
|
Button backButton = m_backButtonObj.GetComponent<Button>();
|
||||||
|
var colors = backButton.colors;
|
||||||
|
colors.normalColor = new Color(0.12f, 0.12f, 0.12f);
|
||||||
|
backButton.colors = colors;
|
||||||
#if CPP
|
#if CPP
|
||||||
backButton.onClick.AddListener(new Action(() => { SetSceneObjectParent(); }));
|
backButton.onClick.AddListener(new Action(() => { SetSceneObjectParent(); }));
|
||||||
#else
|
#else
|
||||||
@ -403,24 +407,58 @@ namespace UnityExplorer.Inspectors
|
|||||||
inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); });
|
inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); });
|
||||||
#endif
|
#endif
|
||||||
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_sceneListContent, new Color(0.1f, 0.1f, 0.1f));
|
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_sceneListContent, new Color(0.1f, 0.1f, 0.1f));
|
||||||
Scrollbar scroll = scrollObj.transform.Find("Scrollbar Vertical").GetComponent<Scrollbar>();
|
|
||||||
ColorBlock colors = scroll.colors;
|
|
||||||
colors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
|
|
||||||
scroll.colors = colors;
|
|
||||||
|
|
||||||
var horiScroll = scrollObj.transform.Find("Scrollbar Horizontal");
|
|
||||||
horiScroll.gameObject.SetActive(false);
|
|
||||||
|
|
||||||
var scrollRect = scrollObj.GetComponentInChildren<ScrollRect>();
|
|
||||||
scrollRect.horizontalScrollbar = null;
|
|
||||||
|
|
||||||
var sceneGroup = m_sceneListContent.GetComponent<VerticalLayoutGroup>();
|
|
||||||
sceneGroup.childControlHeight = true;
|
|
||||||
sceneGroup.spacing = 2;
|
|
||||||
|
|
||||||
m_sceneListPageHandler = new PageHandler();
|
m_sceneListPageHandler = new PageHandler();
|
||||||
m_sceneListPageHandler.ConstructUI(leftPane);
|
m_sceneListPageHandler.ConstructUI(leftPane);
|
||||||
m_sceneListPageHandler.OnPageChanged += OnSceneListPageTurn;
|
m_sceneListPageHandler.OnPageChanged += OnSceneListPageTurn;
|
||||||
|
|
||||||
|
// hide button
|
||||||
|
|
||||||
|
var hideButtonObj = UIFactory.CreateButton(leftPane);
|
||||||
|
var hideBtn = hideButtonObj.GetComponent<Button>();
|
||||||
|
|
||||||
|
var hideColors = hideBtn.colors;
|
||||||
|
hideColors.normalColor = new Color(0.15f, 0.15f, 0.15f);
|
||||||
|
hideBtn.colors = hideColors;
|
||||||
|
var hideText = hideButtonObj.GetComponentInChildren<Text>();
|
||||||
|
hideText.text = "Hide Scene Explorer";
|
||||||
|
hideText.fontSize = 13;
|
||||||
|
var hideLayout = hideButtonObj.AddComponent<LayoutElement>();
|
||||||
|
hideLayout.minWidth = 20;
|
||||||
|
hideLayout.minHeight = 20;
|
||||||
|
#if MONO
|
||||||
|
hideBtn.onClick.AddListener(OnHide);
|
||||||
|
#else
|
||||||
|
hideBtn.onClick.AddListener(new Action(OnHide));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void OnHide()
|
||||||
|
{
|
||||||
|
if (!Hiding)
|
||||||
|
{
|
||||||
|
Hiding = true;
|
||||||
|
|
||||||
|
hideText.text = "►";
|
||||||
|
leftLayout.minWidth = 20;
|
||||||
|
titleObj.SetActive(false);
|
||||||
|
sceneDropdownObj.SetActive(false);
|
||||||
|
scenePathGroupObj.SetActive(false);
|
||||||
|
scrollObj.SetActive(false);
|
||||||
|
m_sceneListPageHandler.Hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Hiding = false;
|
||||||
|
|
||||||
|
hideText.text = "Hide Scene Explorer";
|
||||||
|
leftLayout.minWidth = 350;
|
||||||
|
titleObj.SetActive(true);
|
||||||
|
sceneDropdownObj.SetActive(true);
|
||||||
|
scenePathGroupObj.SetActive(true);
|
||||||
|
scrollObj.SetActive(true);
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddObjectListButton()
|
private void AddObjectListButton()
|
||||||
@ -443,7 +481,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
|
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
|
||||||
mainBtnLayout.minHeight = 25;
|
mainBtnLayout.minHeight = 25;
|
||||||
mainBtnLayout.flexibleHeight = 0;
|
mainBtnLayout.flexibleHeight = 0;
|
||||||
mainBtnLayout.minWidth = 240;
|
mainBtnLayout.minWidth = 230;
|
||||||
mainBtnLayout.flexibleWidth = 0;
|
mainBtnLayout.flexibleWidth = 0;
|
||||||
Button mainBtn = mainButtonObj.GetComponent<Button>();
|
Button mainBtn = mainButtonObj.GetComponent<Button>();
|
||||||
ColorBlock mainColors = mainBtn.colors;
|
ColorBlock mainColors = mainBtn.colors;
|
||||||
|
@ -6,12 +6,18 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
namespace UnityExplorer.UI.PageModel
|
namespace UnityExplorer.UI.PageModel
|
||||||
{
|
{
|
||||||
|
// Probably do this after I've made the CacheObjectBase / InteractiveValue classes.
|
||||||
|
// Might not use CacheObject, but InteractiveValue would be useful here.
|
||||||
|
|
||||||
|
// Maybe InteractiveValue could have an OnSetValue event, which CacheObject and this class can subscribe to separately.
|
||||||
|
|
||||||
public class OptionsPage : MainMenu.Page
|
public class OptionsPage : MainMenu.Page
|
||||||
{
|
{
|
||||||
public override string Name => "Options / Misc";
|
public override string Name => "Options";
|
||||||
|
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
|
ConstructUI();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,5 +25,54 @@ namespace UnityExplorer.UI.PageModel
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
|
internal void ConstructUI()
|
||||||
|
{
|
||||||
|
GameObject parent = MainMenu.Instance.PageViewport;
|
||||||
|
|
||||||
|
Content = UIFactory.CreateHorizontalGroup(parent);
|
||||||
|
var mainGroup = Content.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
mainGroup.padding.left = 4;
|
||||||
|
mainGroup.padding.right = 4;
|
||||||
|
mainGroup.padding.top = 4;
|
||||||
|
mainGroup.padding.bottom = 4;
|
||||||
|
mainGroup.spacing = 5;
|
||||||
|
mainGroup.childForceExpandHeight = true;
|
||||||
|
mainGroup.childForceExpandWidth = true;
|
||||||
|
mainGroup.childControlHeight = true;
|
||||||
|
mainGroup.childControlWidth = true;
|
||||||
|
|
||||||
|
ConstructTopArea();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ConstructTopArea()
|
||||||
|
{
|
||||||
|
var topAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.15f, 0.15f, 0.15f));
|
||||||
|
var topGroup = topAreaObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
topGroup.childForceExpandHeight = false;
|
||||||
|
topGroup.childControlHeight = true;
|
||||||
|
topGroup.childForceExpandWidth = true;
|
||||||
|
topGroup.childControlWidth = true;
|
||||||
|
topGroup.padding.top = 5;
|
||||||
|
topGroup.padding.left = 5;
|
||||||
|
topGroup.padding.right = 5;
|
||||||
|
topGroup.padding.bottom = 5;
|
||||||
|
topGroup.spacing = 5;
|
||||||
|
|
||||||
|
GameObject titleObj = UIFactory.CreateLabel(Content, TextAnchor.UpperLeft);
|
||||||
|
Text titleLabel = titleObj.GetComponent<Text>();
|
||||||
|
titleLabel.text = "Options";
|
||||||
|
titleLabel.fontSize = 20;
|
||||||
|
LayoutElement titleLayout = titleObj.AddComponent<LayoutElement>();
|
||||||
|
titleLayout.minHeight = 30;
|
||||||
|
titleLayout.flexibleHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
|
using UnityExplorer.Inspectors;
|
||||||
|
using UnityExplorer.UI.Shared;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.PageModel
|
namespace UnityExplorer.UI.PageModel
|
||||||
{
|
{
|
||||||
@ -10,14 +13,226 @@ namespace UnityExplorer.UI.PageModel
|
|||||||
{
|
{
|
||||||
public override string Name => "Search";
|
public override string Name => "Search";
|
||||||
|
|
||||||
|
internal object[] m_results;
|
||||||
|
internal readonly List<object> m_resultShortList = new List<object>();
|
||||||
|
|
||||||
|
private int m_lastCount;
|
||||||
|
public PageHandler m_resultListPageHandler;
|
||||||
|
private GameObject m_resultListContent;
|
||||||
|
private readonly List<Text> m_resultListTexts = new List<Text>();
|
||||||
|
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
|
ConstructUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
|
//RefreshResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void OnSearchClicked()
|
||||||
|
{
|
||||||
|
m_results = Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object));
|
||||||
|
|
||||||
|
RefreshResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnResultPageTurn()
|
||||||
|
{
|
||||||
|
RefreshResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshResultList()
|
||||||
|
{
|
||||||
|
m_resultListPageHandler.ListCount = m_results.Length;
|
||||||
|
|
||||||
|
int newCount = 0;
|
||||||
|
|
||||||
|
foreach (var itemIndex in m_resultListPageHandler)
|
||||||
|
{
|
||||||
|
newCount++;
|
||||||
|
|
||||||
|
// normalized index starting from 0
|
||||||
|
var i = itemIndex - m_resultListPageHandler.StartIndex;
|
||||||
|
|
||||||
|
if (itemIndex >= m_results.Length)
|
||||||
|
{
|
||||||
|
if (i > m_lastCount || i >= m_resultListTexts.Count)
|
||||||
|
break;
|
||||||
|
|
||||||
|
GameObject label = m_resultListTexts[i].transform.parent.parent.gameObject;
|
||||||
|
if (label.activeSelf)
|
||||||
|
label.SetActive(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var obj = m_results[itemIndex];
|
||||||
|
|
||||||
|
if (obj == null || obj is UnityEngine.Object uObj && !uObj)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i >= m_resultShortList.Count)
|
||||||
|
{
|
||||||
|
m_resultShortList.Add(obj);
|
||||||
|
AddResultButton();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_resultShortList[i] = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = m_resultListTexts[i];
|
||||||
|
|
||||||
|
var name = $"<color={SyntaxColors.Class_Instance}>{ReflectionHelpers.GetActualType(obj).Name}</color>"
|
||||||
|
+ $" ({obj.ToString()})";
|
||||||
|
|
||||||
|
text.text = name;
|
||||||
|
|
||||||
|
var label = text.transform.parent.parent.gameObject;
|
||||||
|
if (!label.activeSelf)
|
||||||
|
label.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastCount = newCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
|
internal void ConstructUI()
|
||||||
|
{
|
||||||
|
GameObject parent = MainMenu.Instance.PageViewport;
|
||||||
|
|
||||||
|
Content = UIFactory.CreateVerticalGroup(parent);
|
||||||
|
var mainGroup = Content.GetComponent<VerticalLayoutGroup>();
|
||||||
|
mainGroup.padding.left = 4;
|
||||||
|
mainGroup.padding.right = 4;
|
||||||
|
mainGroup.padding.top = 4;
|
||||||
|
mainGroup.padding.bottom = 4;
|
||||||
|
mainGroup.spacing = 5;
|
||||||
|
mainGroup.childForceExpandHeight = true;
|
||||||
|
mainGroup.childForceExpandWidth = true;
|
||||||
|
mainGroup.childControlHeight = true;
|
||||||
|
mainGroup.childControlWidth = true;
|
||||||
|
|
||||||
|
ConstructTopArea();
|
||||||
|
|
||||||
|
ConstructResultsArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ConstructTopArea()
|
||||||
|
{
|
||||||
|
var topAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.15f, 0.15f, 0.15f));
|
||||||
|
var topGroup = topAreaObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
topGroup.childForceExpandHeight = false;
|
||||||
|
topGroup.childControlHeight = true;
|
||||||
|
topGroup.childForceExpandWidth = true;
|
||||||
|
topGroup.childControlWidth = true;
|
||||||
|
topGroup.padding.top = 5;
|
||||||
|
topGroup.padding.left = 5;
|
||||||
|
topGroup.padding.right = 5;
|
||||||
|
topGroup.padding.bottom = 5;
|
||||||
|
topGroup.spacing = 5;
|
||||||
|
|
||||||
|
GameObject titleObj = UIFactory.CreateLabel(topAreaObj, TextAnchor.UpperLeft);
|
||||||
|
Text titleLabel = titleObj.GetComponent<Text>();
|
||||||
|
titleLabel.text = "Search";
|
||||||
|
titleLabel.fontSize = 20;
|
||||||
|
LayoutElement titleLayout = titleObj.AddComponent<LayoutElement>();
|
||||||
|
titleLayout.minHeight = 30;
|
||||||
|
titleLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
|
// top area options
|
||||||
|
|
||||||
|
var tempObj = UIFactory.CreateLabel(topAreaObj, TextAnchor.MiddleLeft);
|
||||||
|
var tempText = tempObj.GetComponent<Text>();
|
||||||
|
tempText.text = "TODO Options / Filters";
|
||||||
|
|
||||||
|
var testBtnObj = UIFactory.CreateButton(topAreaObj);
|
||||||
|
var testText = testBtnObj.GetComponentInChildren<Text>();
|
||||||
|
testText.text = "Search";
|
||||||
|
LayoutElement searchBtnLayout = testBtnObj.AddComponent<LayoutElement>();
|
||||||
|
searchBtnLayout.minHeight = 30;
|
||||||
|
searchBtnLayout.flexibleHeight = 0;
|
||||||
|
var testBtn = testBtnObj.GetComponent<Button>();
|
||||||
|
#if MONO
|
||||||
|
testBtn.onClick.AddListener(OnSearchClicked);
|
||||||
|
#else
|
||||||
|
testBtn.onClick.AddListener(new Action(OnSearchClicked));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ConstructResultsArea()
|
||||||
|
{
|
||||||
|
// Result group holder (NOT actual result list content)
|
||||||
|
|
||||||
|
var resultGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
var resultGroup = resultGroupObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
resultGroup.childForceExpandHeight = false;
|
||||||
|
resultGroup.childForceExpandWidth = true;
|
||||||
|
resultGroup.childControlHeight = true;
|
||||||
|
resultGroup.childControlWidth = true;
|
||||||
|
resultGroup.spacing = 5;
|
||||||
|
resultGroup.padding.top = 5;
|
||||||
|
resultGroup.padding.right = 5;
|
||||||
|
resultGroup.padding.left = 5;
|
||||||
|
resultGroup.padding.bottom = 5;
|
||||||
|
|
||||||
|
m_resultListPageHandler = new PageHandler();
|
||||||
|
m_resultListPageHandler.ConstructUI(resultGroupObj);
|
||||||
|
m_resultListPageHandler.OnPageChanged += OnResultPageTurn;
|
||||||
|
|
||||||
|
GameObject scrollObj = UIFactory.CreateScrollView(resultGroupObj, out m_resultListContent, new Color(0.15f, 0.15f, 0.15f));
|
||||||
|
|
||||||
|
// actual result list content
|
||||||
|
var contentGroup = m_resultListContent.GetComponent<VerticalLayoutGroup>();
|
||||||
|
contentGroup.spacing = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void AddResultButton()
|
||||||
|
{
|
||||||
|
int thisIndex = m_resultListTexts.Count();
|
||||||
|
|
||||||
|
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(m_resultListContent, new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
btnGroup.childForceExpandWidth = true;
|
||||||
|
btnGroup.childControlWidth = true;
|
||||||
|
btnGroup.childForceExpandHeight = false;
|
||||||
|
btnGroup.childControlHeight = true;
|
||||||
|
btnGroup.padding.top = 3;
|
||||||
|
btnGroup.padding.left = 3;
|
||||||
|
btnGroup.padding.right = 3;
|
||||||
|
btnGroup.padding.bottom = 3;
|
||||||
|
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
|
||||||
|
btnLayout.flexibleWidth = 320;
|
||||||
|
btnLayout.minHeight = 25;
|
||||||
|
btnLayout.flexibleHeight = 0;
|
||||||
|
btnGroupObj.AddComponent<Mask>();
|
||||||
|
|
||||||
|
GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj);
|
||||||
|
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
|
||||||
|
mainBtnLayout.minHeight = 25;
|
||||||
|
mainBtnLayout.flexibleHeight = 0;
|
||||||
|
mainBtnLayout.minWidth = 230;
|
||||||
|
mainBtnLayout.flexibleWidth = 0;
|
||||||
|
Button mainBtn = mainButtonObj.GetComponent<Button>();
|
||||||
|
ColorBlock mainColors = mainBtn.colors;
|
||||||
|
mainColors.normalColor = new Color(0.1f, 0.1f, 0.1f);
|
||||||
|
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||||
|
mainBtn.colors = mainColors;
|
||||||
|
#if CPP
|
||||||
|
mainBtn.onClick.AddListener(new Action(() => { SceneListObjectClicked(thisIndex); }));
|
||||||
|
#else
|
||||||
|
mainBtn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_resultShortList[thisIndex]); });
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Text mainText = mainButtonObj.GetComponentInChildren<Text>();
|
||||||
|
mainText.alignment = TextAnchor.MiddleLeft;
|
||||||
|
mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
|
m_resultListTexts.Add(mainText);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ namespace UnityExplorer.UI
|
|||||||
public void OnEndDrag()
|
public void OnEndDrag()
|
||||||
{
|
{
|
||||||
WasDragging = false;
|
WasDragging = false;
|
||||||
UpdateResizeCache();
|
//UpdateResizeCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -131,6 +131,8 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
private const int RESIZE_THICKNESS = 10;
|
private const int RESIZE_THICKNESS = 10;
|
||||||
|
|
||||||
|
private readonly Vector2 minResize = new Vector2(733, 542);
|
||||||
|
|
||||||
private bool WasResizing { get; set; }
|
private bool WasResizing { get; set; }
|
||||||
private ResizeTypes m_currentResizeType = ResizeTypes.NONE;
|
private ResizeTypes m_currentResizeType = ResizeTypes.NONE;
|
||||||
private Vector2 m_lastResizePos;
|
private Vector2 m_lastResizePos;
|
||||||
@ -287,35 +289,40 @@ namespace UnityExplorer.UI
|
|||||||
{
|
{
|
||||||
Vector3 mousePos = InputManager.MousePosition;
|
Vector3 mousePos = InputManager.MousePosition;
|
||||||
Vector2 diff = m_lastResizePos - (Vector2)mousePos;
|
Vector2 diff = m_lastResizePos - (Vector2)mousePos;
|
||||||
|
|
||||||
|
if ((Vector2)mousePos == m_lastResizePos)
|
||||||
|
return;
|
||||||
|
|
||||||
m_lastResizePos = mousePos;
|
m_lastResizePos = mousePos;
|
||||||
|
|
||||||
float diffX = (float)((decimal)diff.x / Screen.width);
|
float diffX = (float)((decimal)diff.x / Screen.width);
|
||||||
float diffY = (float)((decimal)diff.y / Screen.height);
|
float diffY = (float)((decimal)diff.y / Screen.height);
|
||||||
|
|
||||||
|
Vector2 anchorMin = Panel.anchorMin;
|
||||||
|
Vector2 anchorMax = Panel.anchorMax;
|
||||||
|
|
||||||
if (m_currentResizeType.HasFlag(ResizeTypes.Left))
|
if (m_currentResizeType.HasFlag(ResizeTypes.Left))
|
||||||
{
|
anchorMin.x -= diffX;
|
||||||
Vector2 anch = Panel.anchorMin;
|
|
||||||
anch.x -= diffX;
|
|
||||||
Panel.anchorMin = anch;
|
|
||||||
}
|
|
||||||
else if (m_currentResizeType.HasFlag(ResizeTypes.Right))
|
else if (m_currentResizeType.HasFlag(ResizeTypes.Right))
|
||||||
{
|
anchorMax.x -= diffX;
|
||||||
Vector2 anch = Panel.anchorMax;
|
|
||||||
anch.x -= diffX;
|
|
||||||
Panel.anchorMax = anch;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_currentResizeType.HasFlag(ResizeTypes.Top))
|
if (m_currentResizeType.HasFlag(ResizeTypes.Top))
|
||||||
{
|
anchorMax.y -= diffY;
|
||||||
Vector2 anch = Panel.anchorMax;
|
|
||||||
anch.y -= diffY;
|
|
||||||
Panel.anchorMax = anch;
|
|
||||||
}
|
|
||||||
else if (m_currentResizeType.HasFlag(ResizeTypes.Bottom))
|
else if (m_currentResizeType.HasFlag(ResizeTypes.Bottom))
|
||||||
|
anchorMin.y -= diffY;
|
||||||
|
|
||||||
|
var newWidth = (anchorMax.x - anchorMin.x) * Screen.width;
|
||||||
|
var newHeight = (anchorMax.y - anchorMin.y) * Screen.height;
|
||||||
|
|
||||||
|
if (newWidth >= minResize.x)
|
||||||
{
|
{
|
||||||
Vector2 anch = Panel.anchorMin;
|
Panel.anchorMin = new Vector2(anchorMin.x, Panel.anchorMin.y);
|
||||||
anch.y -= diffY;
|
Panel.anchorMax = new Vector2(anchorMax.x, Panel.anchorMax.y);
|
||||||
Panel.anchorMin = anch;
|
}
|
||||||
|
if (newHeight >= minResize.y)
|
||||||
|
{
|
||||||
|
Panel.anchorMin = new Vector2(Panel.anchorMin.x, anchorMin.y);
|
||||||
|
Panel.anchorMax = new Vector2(Panel.anchorMax.x, anchorMax.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,17 +149,17 @@ namespace UnityExplorer.UI.Shared
|
|||||||
Image image = m_pageUIHolder.GetComponent<Image>();
|
Image image = m_pageUIHolder.GetComponent<Image>();
|
||||||
image.color = new Color(0f, 0f, 0f, 0f);
|
image.color = new Color(0f, 0f, 0f, 0f);
|
||||||
|
|
||||||
HorizontalLayoutGroup parentGroup = m_pageUIHolder.GetComponent<HorizontalLayoutGroup>();
|
HorizontalLayoutGroup mainGroup = m_pageUIHolder.GetComponent<HorizontalLayoutGroup>();
|
||||||
parentGroup.childForceExpandHeight = true;
|
mainGroup.childForceExpandHeight = true;
|
||||||
parentGroup.childForceExpandWidth = false;
|
mainGroup.childForceExpandWidth = false;
|
||||||
parentGroup.childControlWidth = true;
|
mainGroup.childControlWidth = true;
|
||||||
parentGroup.childControlHeight = true;
|
mainGroup.childControlHeight = true;
|
||||||
|
|
||||||
LayoutElement parentLayout = m_pageUIHolder.AddComponent<LayoutElement>();
|
LayoutElement mainLayout = m_pageUIHolder.AddComponent<LayoutElement>();
|
||||||
parentLayout.minHeight = 20;
|
mainLayout.minHeight = 20;
|
||||||
parentLayout.flexibleHeight = 0;
|
mainLayout.flexibleHeight = 0;
|
||||||
parentLayout.minWidth = 200;
|
mainLayout.minWidth = 100;
|
||||||
parentLayout.flexibleWidth = 30;
|
mainLayout.flexibleWidth = 30;
|
||||||
|
|
||||||
GameObject leftBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
GameObject leftBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
||||||
Button leftBtn = leftBtnObj.GetComponent<Button>();
|
Button leftBtn = leftBtnObj.GetComponent<Button>();
|
||||||
@ -169,19 +169,19 @@ namespace UnityExplorer.UI.Shared
|
|||||||
leftBtn.onClick.AddListener(() => { TurnPage(Turn.Left); });
|
leftBtn.onClick.AddListener(() => { TurnPage(Turn.Left); });
|
||||||
#endif
|
#endif
|
||||||
Text leftBtnText = leftBtnObj.GetComponentInChildren<Text>();
|
Text leftBtnText = leftBtnObj.GetComponentInChildren<Text>();
|
||||||
leftBtnText.text = "<";
|
leftBtnText.text = "◄";
|
||||||
LayoutElement leftBtnLayout = leftBtnObj.AddComponent<LayoutElement>();
|
LayoutElement leftBtnLayout = leftBtnObj.AddComponent<LayoutElement>();
|
||||||
leftBtnLayout.flexibleHeight = 0;
|
leftBtnLayout.flexibleHeight = 0;
|
||||||
leftBtnLayout.flexibleWidth = 0;
|
leftBtnLayout.flexibleWidth = 0;
|
||||||
leftBtnLayout.minWidth = 40;
|
leftBtnLayout.minWidth = 30;
|
||||||
leftBtnLayout.minHeight = 20;
|
leftBtnLayout.minHeight = 20;
|
||||||
|
|
||||||
GameObject labelObj = UIFactory.CreateLabel(m_pageUIHolder, TextAnchor.MiddleCenter);
|
GameObject labelObj = UIFactory.CreateLabel(m_pageUIHolder, TextAnchor.MiddleCenter);
|
||||||
m_currentPageLabel = labelObj.GetComponent<Text>();
|
m_currentPageLabel = labelObj.GetComponent<Text>();
|
||||||
m_currentPageLabel.text = "Page 1 / TODO";
|
m_currentPageLabel.text = "Page 1 / TODO";
|
||||||
LayoutElement textLayout = labelObj.AddComponent<LayoutElement>();
|
LayoutElement textLayout = labelObj.AddComponent<LayoutElement>();
|
||||||
textLayout.flexibleWidth = 1.5f;
|
textLayout.minWidth = 60f;
|
||||||
textLayout.preferredWidth = 120;
|
textLayout.flexibleWidth = 5000f;
|
||||||
|
|
||||||
GameObject rightBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
GameObject rightBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
||||||
Button rightBtn = rightBtnObj.GetComponent<Button>();
|
Button rightBtn = rightBtnObj.GetComponent<Button>();
|
||||||
@ -191,11 +191,11 @@ namespace UnityExplorer.UI.Shared
|
|||||||
rightBtn.onClick.AddListener(() => { TurnPage(Turn.Right); });
|
rightBtn.onClick.AddListener(() => { TurnPage(Turn.Right); });
|
||||||
#endif
|
#endif
|
||||||
Text rightBtnText = rightBtnObj.GetComponentInChildren<Text>();
|
Text rightBtnText = rightBtnObj.GetComponentInChildren<Text>();
|
||||||
rightBtnText.text = ">";
|
rightBtnText.text = "►";
|
||||||
LayoutElement rightBtnLayout = rightBtnObj.AddComponent<LayoutElement>();
|
LayoutElement rightBtnLayout = rightBtnObj.AddComponent<LayoutElement>();
|
||||||
rightBtnLayout.flexibleHeight = 0;
|
rightBtnLayout.flexibleHeight = 0;
|
||||||
rightBtnLayout.flexibleWidth = 0;
|
rightBtnLayout.flexibleWidth = 0;
|
||||||
rightBtnLayout.minWidth = 40;
|
rightBtnLayout.minWidth = 30;
|
||||||
rightBtnLayout.minHeight = 20;
|
rightBtnLayout.minHeight = 20;
|
||||||
|
|
||||||
ListCount = 0;
|
ListCount = 0;
|
||||||
|
103
src/UI/Shared/SliderScrollbar.cs
Normal file
103
src/UI/Shared/SliderScrollbar.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityExplorer;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
|
|
||||||
|
// Basically just to fix an issue with Scrollbars, instead we use a Slider as the scrollbar.
|
||||||
|
// This class contains only what is needed to update and manage one after creation.
|
||||||
|
public class SliderScrollbar
|
||||||
|
{
|
||||||
|
internal static readonly List<SliderScrollbar> Instances = new List<SliderScrollbar>();
|
||||||
|
|
||||||
|
internal readonly Scrollbar m_scrollbar;
|
||||||
|
internal readonly Slider m_slider;
|
||||||
|
|
||||||
|
public SliderScrollbar(Scrollbar scrollbar, Slider slider)
|
||||||
|
{
|
||||||
|
Instances.Add(this);
|
||||||
|
|
||||||
|
this.m_scrollbar = scrollbar;
|
||||||
|
this.m_slider = slider;
|
||||||
|
|
||||||
|
#if MONO
|
||||||
|
this.m_scrollbar.onValueChanged.AddListener(this.OnScrollbarValueChanged);
|
||||||
|
this.m_slider.onValueChanged.AddListener(this.OnSliderValueChanged);
|
||||||
|
#else
|
||||||
|
this.m_scrollbar.onValueChanged.AddListener(new Action<float>(this.OnScrollbarValueChanged));
|
||||||
|
this.m_slider.onValueChanged.AddListener(new Action<float>(this.OnSliderValueChanged));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this.RefreshVisibility();
|
||||||
|
this.m_slider.Set(1f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Update()
|
||||||
|
{
|
||||||
|
this.RefreshVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void RefreshVisibility()
|
||||||
|
{
|
||||||
|
if (this.m_slider && this.m_scrollbar)
|
||||||
|
{
|
||||||
|
bool shouldShow = !Mathf.Approximately(this.m_scrollbar.size, 1);
|
||||||
|
var obj = this.m_slider.handleRect.gameObject;
|
||||||
|
|
||||||
|
if (obj.activeSelf != shouldShow)
|
||||||
|
{
|
||||||
|
obj.SetActive(shouldShow);
|
||||||
|
|
||||||
|
if (shouldShow)
|
||||||
|
this.m_slider.Set(this.m_scrollbar.value, false);
|
||||||
|
else
|
||||||
|
m_slider.Set(1f, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnScrollbarValueChanged(float _value)
|
||||||
|
{
|
||||||
|
//this.RefreshVisibility();
|
||||||
|
if (this.m_slider && this.m_slider.value != _value)
|
||||||
|
{
|
||||||
|
this.m_slider.Set(_value, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSliderValueChanged(float _value)
|
||||||
|
{
|
||||||
|
if (this.m_scrollbar)
|
||||||
|
{
|
||||||
|
this.m_scrollbar.value = _value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if MONO
|
||||||
|
public static class SliderExtensions
|
||||||
|
{
|
||||||
|
// il2cpp can just use the orig method directly (forced public)
|
||||||
|
|
||||||
|
private static MethodInfo m_setMethod;
|
||||||
|
private static MethodInfo SetMethod
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (m_setMethod == null)
|
||||||
|
{
|
||||||
|
m_setMethod = typeof(Slider).GetMethod("Set", ReflectionHelpers.CommonFlags, null, new[] { typeof(float), typeof(bool) }, null);
|
||||||
|
}
|
||||||
|
return m_setMethod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Set(this Slider slider, float value, bool invokeCallback)
|
||||||
|
{
|
||||||
|
SetMethod.Invoke(slider, new object[] { value, invokeCallback });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
@ -222,7 +222,7 @@ namespace UnityExplorer.UI
|
|||||||
return labelObj;
|
return labelObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameObject CreateButton(GameObject parent)
|
public static GameObject CreateButton(GameObject parent, Color normalColor = default)
|
||||||
{
|
{
|
||||||
GameObject buttonObj = CreateUIObject("Button", parent, thinSize);
|
GameObject buttonObj = CreateUIObject("Button", parent, thinSize);
|
||||||
|
|
||||||
@ -236,6 +236,14 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
SetDefaultColorTransitionValues(buttonObj.AddComponent<Button>());
|
SetDefaultColorTransitionValues(buttonObj.AddComponent<Button>());
|
||||||
|
|
||||||
|
if (normalColor != default)
|
||||||
|
{
|
||||||
|
var btn = buttonObj.GetComponent<Button>();
|
||||||
|
var colors = btn.colors;
|
||||||
|
colors.normalColor = normalColor;
|
||||||
|
btn.colors = colors;
|
||||||
|
}
|
||||||
|
|
||||||
Text text = textObj.AddComponent<Text>();
|
Text text = textObj.AddComponent<Text>();
|
||||||
text.text = "Button";
|
text.text = "Button";
|
||||||
SetDefaultTextValues(text);
|
SetDefaultTextValues(text);
|
||||||
@ -249,6 +257,74 @@ namespace UnityExplorer.UI
|
|||||||
return buttonObj;
|
return buttonObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public static GameObject CreateSlider(GameObject parent)
|
||||||
|
//{
|
||||||
|
// GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
|
||||||
|
|
||||||
|
// GameObject bgObj = CreateUIObject("Background", sliderObj);
|
||||||
|
// GameObject fillAreaObj = CreateUIObject("Fill Area", sliderObj);
|
||||||
|
// GameObject fillObj = CreateUIObject("Fill", fillAreaObj);
|
||||||
|
// GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
|
||||||
|
// GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
|
||||||
|
|
||||||
|
// Image bgImage = bgObj.AddComponent<Image>();
|
||||||
|
// bgImage.type = Image.Type.Sliced;
|
||||||
|
// bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
||||||
|
|
||||||
|
// RectTransform bgRect = bgObj.GetComponent<RectTransform>();
|
||||||
|
// bgRect.anchorMin = new Vector2(0f, dynamic ? 0f : 0.25f);
|
||||||
|
// bgRect.anchorMax = new Vector2(1f, dynamic ? 1f : 0.75f);
|
||||||
|
// bgRect.sizeDelta = new Vector2(0f, 0f);
|
||||||
|
|
||||||
|
// RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
|
||||||
|
// fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
|
||||||
|
// fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
|
||||||
|
// fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
|
||||||
|
// fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
|
||||||
|
|
||||||
|
// Image fillImage = fillObj.AddComponent<Image>();
|
||||||
|
// fillImage.type = Image.Type.Sliced;
|
||||||
|
// fillImage.color = dynamic ? Color.clear : new Color(0.3f, 0.3f, 0.3f, 1.0f);
|
||||||
|
|
||||||
|
// fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
|
||||||
|
|
||||||
|
// RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
|
||||||
|
// handleSlideRect.anchorMin = new Vector2(0f, 0f);
|
||||||
|
// handleSlideRect.anchorMax = new Vector2(1f, 1f);
|
||||||
|
// handleSlideRect.offsetMin = new Vector2(15f, 20f);
|
||||||
|
// handleSlideRect.offsetMax = new Vector2(-15f, 0f);
|
||||||
|
// handleSlideRect.sizeDelta = new Vector2(dynamic ? -30f : -20f, 0f);
|
||||||
|
|
||||||
|
// Image handleImage = handleObj.AddComponent<Image>();
|
||||||
|
// handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
|
||||||
|
// var handleRect = handleObj.GetComponent<RectTransform>();
|
||||||
|
// handleRect.sizeDelta = new Vector2(dynamic ? 25f : 20f, dynamic ? 25f : 0f);
|
||||||
|
|
||||||
|
// if (dynamic)
|
||||||
|
// {
|
||||||
|
// handleRect.offsetMin = new Vector2(-15f, -20f);
|
||||||
|
// handleRect.offsetMax = Vector2.zero;
|
||||||
|
|
||||||
|
// var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
|
||||||
|
// sliderBarLayout.minWidth = 25;
|
||||||
|
// sliderBarLayout.flexibleWidth = 0;
|
||||||
|
// sliderBarLayout.minHeight = 25;
|
||||||
|
// sliderBarLayout.flexibleHeight = 5000;
|
||||||
|
|
||||||
|
// bgRect.offsetMax = new Vector2(-15f, 0f);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Slider slider = sliderObj.AddComponent<Slider>();
|
||||||
|
// slider.fillRect = fillObj.GetComponent<RectTransform>();
|
||||||
|
// slider.handleRect = handleObj.GetComponent<RectTransform>();
|
||||||
|
// slider.targetGraphic = handleImage;
|
||||||
|
// slider.direction = dynamic ? Slider.Direction.BottomToTop : Slider.Direction.LeftToRight;
|
||||||
|
// SetDefaultColorTransitionValues(slider);
|
||||||
|
|
||||||
|
// return sliderObj;
|
||||||
|
//}
|
||||||
|
|
||||||
public static GameObject CreateSlider(GameObject parent)
|
public static GameObject CreateSlider(GameObject parent)
|
||||||
{
|
{
|
||||||
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
|
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
|
||||||
@ -611,14 +687,14 @@ namespace UnityExplorer.UI
|
|||||||
dropdown.captionText = labelText;
|
dropdown.captionText = labelText;
|
||||||
dropdown.itemText = itemLabelText;
|
dropdown.itemText = itemLabelText;
|
||||||
itemLabelText.text = "1";
|
itemLabelText.text = "1";
|
||||||
dropdown.options.Add(new Dropdown.OptionData
|
//dropdown.options.Add(new Dropdown.OptionData
|
||||||
{
|
//{
|
||||||
text = "2"
|
// text = "2"
|
||||||
});
|
//});
|
||||||
dropdown.options.Add(new Dropdown.OptionData
|
//dropdown.options.Add(new Dropdown.OptionData
|
||||||
{
|
//{
|
||||||
text = "3"
|
// text = "3"
|
||||||
});
|
//});
|
||||||
|
|
||||||
dropdown.RefreshShownValue();
|
dropdown.RefreshShownValue();
|
||||||
|
|
||||||
@ -670,91 +746,245 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
|
public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
|
||||||
{
|
{
|
||||||
GameObject scrollObj = CreateUIObject("Scroll View", parent);
|
GameObject mainObj = CreateUIObject("DynamicScrollView", parent);
|
||||||
|
|
||||||
LayoutElement mainLayout = scrollObj.AddComponent<LayoutElement>();
|
var mainLayout = mainObj.AddComponent<LayoutElement>();
|
||||||
mainLayout.flexibleWidth = 999;
|
mainLayout.minWidth = 100;
|
||||||
mainLayout.flexibleHeight = 999;
|
mainLayout.minHeight = 100;
|
||||||
mainLayout.preferredHeight = 200;
|
mainLayout.flexibleWidth = 5000;
|
||||||
mainLayout.preferredWidth = 200;
|
mainLayout.flexibleHeight = 5000;
|
||||||
|
|
||||||
GameObject viewportObj = CreateUIObject("Viewport", scrollObj);
|
Image mainImage = mainObj.AddComponent<Image>();
|
||||||
|
mainImage.type = Image.Type.Filled;
|
||||||
|
mainImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
|
||||||
|
|
||||||
VerticalLayoutGroup viewportGroup = viewportObj.AddComponent<VerticalLayoutGroup>();
|
GameObject viewportObj = CreateUIObject("Viewport", mainObj);
|
||||||
viewportGroup.childControlHeight = true;
|
|
||||||
viewportGroup.childControlWidth = true;
|
|
||||||
viewportGroup.childForceExpandHeight = true;
|
|
||||||
viewportGroup.childForceExpandWidth = true;
|
|
||||||
|
|
||||||
content = CreateUIObject("Content", viewportObj);
|
var viewportRect = viewportObj.GetComponent<RectTransform>();
|
||||||
|
|
||||||
VerticalLayoutGroup contentGroup = content.AddComponent<VerticalLayoutGroup>();
|
|
||||||
contentGroup.padding.left = 5;
|
|
||||||
contentGroup.padding.right = 5;
|
|
||||||
contentGroup.padding.top = 5;
|
|
||||||
contentGroup.padding.bottom = 5;
|
|
||||||
contentGroup.childControlHeight = false;
|
|
||||||
contentGroup.childControlWidth = true;
|
|
||||||
contentGroup.childForceExpandHeight = false;
|
|
||||||
contentGroup.childForceExpandWidth = true;
|
|
||||||
|
|
||||||
GameObject horiScroll = CreateScrollbar(scrollObj);
|
|
||||||
horiScroll.name = "Scrollbar Horizontal";
|
|
||||||
SetParentAndAlign(horiScroll, scrollObj);
|
|
||||||
|
|
||||||
RectTransform horiRect = horiScroll.GetComponent<RectTransform>();
|
|
||||||
horiRect.anchorMin = Vector2.zero;
|
|
||||||
horiRect.anchorMax = Vector2.right;
|
|
||||||
horiRect.pivot = Vector2.zero;
|
|
||||||
horiRect.sizeDelta = new Vector2(0f, horiRect.sizeDelta.y);
|
|
||||||
|
|
||||||
GameObject vertScroll = CreateScrollbar(scrollObj);
|
|
||||||
vertScroll.name = "Scrollbar Vertical";
|
|
||||||
SetParentAndAlign(vertScroll, scrollObj);
|
|
||||||
vertScroll.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
|
|
||||||
|
|
||||||
RectTransform vertRect = vertScroll.GetComponent<RectTransform>();
|
|
||||||
vertRect.anchorMin = Vector2.right;
|
|
||||||
vertRect.anchorMax = Vector2.one;
|
|
||||||
vertRect.pivot = Vector2.one;
|
|
||||||
vertRect.sizeDelta = new Vector2(vertRect.sizeDelta.x, 0f);
|
|
||||||
|
|
||||||
RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
|
|
||||||
viewportRect.anchorMin = Vector2.zero;
|
viewportRect.anchorMin = Vector2.zero;
|
||||||
viewportRect.anchorMax = Vector2.one;
|
viewportRect.anchorMax = Vector2.one;
|
||||||
viewportRect.sizeDelta = Vector2.zero;
|
viewportRect.pivot = new Vector2(0.0f, 1.0f);
|
||||||
viewportRect.pivot = Vector2.up;
|
viewportRect.sizeDelta = new Vector2(-15.0f, 0.0f);
|
||||||
|
viewportRect.offsetMax = new Vector2(-20.0f, 0.0f);
|
||||||
|
|
||||||
RectTransform contentRect = content.GetComponent<RectTransform>();
|
viewportObj.AddComponent<Image>().color = Color.white;
|
||||||
contentRect.anchorMin = Vector2.up;
|
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
|
||||||
contentRect.anchorMax = Vector2.one;
|
|
||||||
contentRect.pivot = Vector2.up;
|
|
||||||
|
|
||||||
ScrollRect scrollRect = scrollObj.AddComponent<ScrollRect>();
|
content = CreateUIObject("Content", viewportObj);
|
||||||
scrollRect.content = contentRect;
|
var contentRect = content.GetComponent<RectTransform>();
|
||||||
scrollRect.viewport = viewportRect;
|
contentRect.anchorMin = new Vector2(0.0f, 1.0f);
|
||||||
scrollRect.horizontalScrollbar = horiScroll.GetComponent<Scrollbar>();
|
contentRect.anchorMax = new Vector2(1.0f, 1.0f);
|
||||||
scrollRect.verticalScrollbar = vertScroll.GetComponent<Scrollbar>();
|
contentRect.pivot = new Vector2(0.0f, 1.0f);
|
||||||
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
contentRect.sizeDelta = new Vector2(5f, 0f);
|
||||||
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
contentRect.offsetMax = new Vector2(0f, 0f);
|
||||||
scrollRect.horizontalScrollbarSpacing = -3f;
|
var contentFitter = content.AddComponent<ContentSizeFitter>();
|
||||||
scrollRect.verticalScrollbarSpacing = -3f;
|
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||||
|
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||||
|
|
||||||
|
var contentLayout = content.AddComponent<VerticalLayoutGroup>();
|
||||||
|
contentLayout.childForceExpandHeight = true;
|
||||||
|
contentLayout.childControlHeight = true;
|
||||||
|
contentLayout.childForceExpandWidth = true;
|
||||||
|
contentLayout.childControlWidth = true;
|
||||||
|
contentLayout.padding.left = 5;
|
||||||
|
contentLayout.padding.right = 5;
|
||||||
|
contentLayout.padding.top = 5;
|
||||||
|
contentLayout.padding.bottom = 5;
|
||||||
|
contentLayout.spacing = 5;
|
||||||
|
|
||||||
|
GameObject scrollBar = CreateUIObject("DynamicScrollbar", mainObj);
|
||||||
|
|
||||||
|
var scrollbarLayout = scrollBar.AddComponent<VerticalLayoutGroup>();
|
||||||
|
scrollbarLayout.childForceExpandHeight = true;
|
||||||
|
scrollbarLayout.childControlHeight = true;
|
||||||
|
|
||||||
|
RectTransform scrollBarRect = scrollBar.GetComponent<RectTransform>();
|
||||||
|
scrollBarRect.anchorMin = new Vector2(1.0f, 0.0f);
|
||||||
|
scrollBarRect.anchorMax = new Vector2(1.0f, 1.0f);
|
||||||
|
scrollBarRect.sizeDelta = new Vector2(15.0f, 0.0f);
|
||||||
|
scrollBarRect.offsetMin = new Vector2(-15.0f, 0.0f);
|
||||||
|
|
||||||
|
GameObject hiddenBar = CreateScrollbar(scrollBar);
|
||||||
|
var hiddenScroll = hiddenBar.GetComponent<Scrollbar>();
|
||||||
|
hiddenScroll.SetDirection(Scrollbar.Direction.BottomToTop, true);
|
||||||
|
|
||||||
|
for (int i = 0; i < hiddenBar.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
var child = hiddenBar.transform.GetChild(i);
|
||||||
|
child.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateScrollSlider(scrollBar, out Slider scrollSlider);
|
||||||
|
|
||||||
|
// Back to the main scrollview ScrollRect, setting it up now that we have all references.
|
||||||
|
|
||||||
|
var scrollRect = mainObj.AddComponent<ScrollRect>();
|
||||||
|
scrollRect.horizontal = false;
|
||||||
|
scrollRect.vertical = true;
|
||||||
|
scrollRect.verticalScrollbar = hiddenScroll;
|
||||||
|
scrollRect.movementType = ScrollRect.MovementType.Clamped;
|
||||||
scrollRect.scrollSensitivity = 25;
|
scrollRect.scrollSensitivity = 25;
|
||||||
|
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
||||||
|
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.Permanent;
|
||||||
|
|
||||||
Image scrollImage = scrollObj.AddComponent<Image>();
|
scrollRect.viewport = viewportRect;
|
||||||
scrollImage.type = Image.Type.Filled;
|
scrollRect.content = contentRect;
|
||||||
|
|
||||||
scrollImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
|
// Create a custom DynamicScrollbar module
|
||||||
|
new SliderScrollbar(hiddenScroll, scrollSlider);
|
||||||
|
|
||||||
Image viewportImage = viewportObj.AddComponent<Image>();
|
return mainObj;
|
||||||
//viewportImage.sprite = Theme.mask;
|
|
||||||
viewportImage.type = Image.Type.Sliced;
|
|
||||||
viewportImage.color = new Color(1, 1, 1, 1);
|
|
||||||
|
|
||||||
Mask mask = viewportObj.AddComponent<Mask>();
|
|
||||||
mask.showMaskGraphic = false;
|
|
||||||
|
|
||||||
return scrollObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GameObject CreateScrollSlider(GameObject parent, out Slider slider)
|
||||||
|
{
|
||||||
|
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
|
||||||
|
|
||||||
|
GameObject bgObj = CreateUIObject("Background", sliderObj);
|
||||||
|
GameObject fillAreaObj = CreateUIObject("Fill Area", sliderObj);
|
||||||
|
GameObject fillObj = CreateUIObject("Fill", fillAreaObj);
|
||||||
|
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
|
||||||
|
GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
|
||||||
|
|
||||||
|
Image bgImage = bgObj.AddComponent<Image>();
|
||||||
|
bgImage.type = Image.Type.Sliced;
|
||||||
|
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
|
||||||
|
|
||||||
|
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
|
||||||
|
bgRect.anchorMin = Vector2.zero;
|
||||||
|
bgRect.anchorMax = Vector2.one;
|
||||||
|
bgRect.sizeDelta = Vector2.zero;
|
||||||
|
bgRect.offsetMax = new Vector2(-10f, 0f);
|
||||||
|
|
||||||
|
RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
|
||||||
|
fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
|
||||||
|
fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
|
||||||
|
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
|
||||||
|
fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
|
||||||
|
|
||||||
|
Image fillImage = fillObj.AddComponent<Image>();
|
||||||
|
fillImage.type = Image.Type.Sliced;
|
||||||
|
fillImage.color = Color.clear;
|
||||||
|
|
||||||
|
fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
|
||||||
|
|
||||||
|
RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
|
||||||
|
handleSlideRect.anchorMin = new Vector2(0f, 0f);
|
||||||
|
handleSlideRect.anchorMax = new Vector2(1f, 1f);
|
||||||
|
handleSlideRect.offsetMin = new Vector2(15f, 25f);
|
||||||
|
handleSlideRect.offsetMax = new Vector2(-15f, 0f);
|
||||||
|
handleSlideRect.sizeDelta = new Vector2(-30f, -25f);
|
||||||
|
|
||||||
|
Image handleImage = handleObj.AddComponent<Image>();
|
||||||
|
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
|
||||||
|
var handleRect = handleObj.GetComponent<RectTransform>();
|
||||||
|
handleRect.sizeDelta = new Vector2(15f, 25f);
|
||||||
|
handleRect.offsetMin = new Vector2(-13f, -23f);
|
||||||
|
handleRect.offsetMax = new Vector2(3f, -2f);
|
||||||
|
|
||||||
|
var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
|
||||||
|
sliderBarLayout.minWidth = 25;
|
||||||
|
sliderBarLayout.flexibleWidth = 0;
|
||||||
|
sliderBarLayout.minHeight = 25;
|
||||||
|
sliderBarLayout.flexibleHeight = 5000;
|
||||||
|
|
||||||
|
slider = sliderObj.AddComponent<Slider>();
|
||||||
|
slider.fillRect = fillObj.GetComponent<RectTransform>();
|
||||||
|
slider.handleRect = handleObj.GetComponent<RectTransform>();
|
||||||
|
slider.targetGraphic = handleImage;
|
||||||
|
slider.direction = Slider.Direction.BottomToTop;
|
||||||
|
SetDefaultColorTransitionValues(slider);
|
||||||
|
|
||||||
|
return sliderObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
|
||||||
|
//{
|
||||||
|
// GameObject scrollObj = CreateUIObject("Scroll View", parent);
|
||||||
|
|
||||||
|
// LayoutElement mainLayout = scrollObj.AddComponent<LayoutElement>();
|
||||||
|
// mainLayout.flexibleWidth = 999;
|
||||||
|
// mainLayout.flexibleHeight = 999;
|
||||||
|
// mainLayout.preferredHeight = 200;
|
||||||
|
// mainLayout.preferredWidth = 200;
|
||||||
|
|
||||||
|
// GameObject viewportObj = CreateUIObject("Viewport", scrollObj);
|
||||||
|
|
||||||
|
// VerticalLayoutGroup viewportGroup = viewportObj.AddComponent<VerticalLayoutGroup>();
|
||||||
|
// viewportGroup.childControlHeight = true;
|
||||||
|
// viewportGroup.childControlWidth = true;
|
||||||
|
// viewportGroup.childForceExpandHeight = true;
|
||||||
|
// viewportGroup.childForceExpandWidth = true;
|
||||||
|
|
||||||
|
// content = CreateUIObject("Content", viewportObj);
|
||||||
|
|
||||||
|
// VerticalLayoutGroup contentGroup = content.AddComponent<VerticalLayoutGroup>();
|
||||||
|
// contentGroup.padding.left = 5;
|
||||||
|
// contentGroup.padding.right = 5;
|
||||||
|
// contentGroup.padding.top = 5;
|
||||||
|
// contentGroup.padding.bottom = 5;
|
||||||
|
// contentGroup.childControlHeight = false;
|
||||||
|
// contentGroup.childControlWidth = true;
|
||||||
|
// contentGroup.childForceExpandHeight = false;
|
||||||
|
// contentGroup.childForceExpandWidth = true;
|
||||||
|
|
||||||
|
// GameObject horiScroll = CreateScrollbar(scrollObj);
|
||||||
|
// horiScroll.name = "Scrollbar Horizontal";
|
||||||
|
// SetParentAndAlign(horiScroll, scrollObj);
|
||||||
|
|
||||||
|
// RectTransform horiRect = horiScroll.GetComponent<RectTransform>();
|
||||||
|
// horiRect.anchorMin = Vector2.zero;
|
||||||
|
// horiRect.anchorMax = Vector2.right;
|
||||||
|
// horiRect.pivot = Vector2.zero;
|
||||||
|
// horiRect.sizeDelta = new Vector2(0f, horiRect.sizeDelta.y);
|
||||||
|
|
||||||
|
// GameObject vertScroll = CreateScrollbar(scrollObj);
|
||||||
|
// vertScroll.name = "Scrollbar Vertical";
|
||||||
|
// SetParentAndAlign(vertScroll, scrollObj);
|
||||||
|
// vertScroll.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
|
||||||
|
|
||||||
|
// RectTransform vertRect = vertScroll.GetComponent<RectTransform>();
|
||||||
|
// vertRect.anchorMin = Vector2.right;
|
||||||
|
// vertRect.anchorMax = Vector2.one;
|
||||||
|
// vertRect.pivot = Vector2.one;
|
||||||
|
// vertRect.sizeDelta = new Vector2(vertRect.sizeDelta.x, 0f);
|
||||||
|
|
||||||
|
// RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
|
||||||
|
// viewportRect.anchorMin = Vector2.zero;
|
||||||
|
// viewportRect.anchorMax = Vector2.one;
|
||||||
|
// viewportRect.sizeDelta = Vector2.zero;
|
||||||
|
// viewportRect.pivot = Vector2.up;
|
||||||
|
|
||||||
|
// RectTransform contentRect = content.GetComponent<RectTransform>();
|
||||||
|
// contentRect.anchorMin = Vector2.up;
|
||||||
|
// contentRect.anchorMax = Vector2.one;
|
||||||
|
// contentRect.pivot = Vector2.up;
|
||||||
|
|
||||||
|
// ScrollRect scrollRect = scrollObj.AddComponent<ScrollRect>();
|
||||||
|
// scrollRect.content = contentRect;
|
||||||
|
// scrollRect.viewport = viewportRect;
|
||||||
|
// scrollRect.horizontalScrollbar = horiScroll.GetComponent<Scrollbar>();
|
||||||
|
// scrollRect.verticalScrollbar = vertScroll.GetComponent<Scrollbar>();
|
||||||
|
// scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
||||||
|
// scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
||||||
|
// scrollRect.horizontalScrollbarSpacing = -3f;
|
||||||
|
// scrollRect.verticalScrollbarSpacing = -3f;
|
||||||
|
// scrollRect.scrollSensitivity = 25;
|
||||||
|
|
||||||
|
// Image scrollImage = scrollObj.AddComponent<Image>();
|
||||||
|
// scrollImage.type = Image.Type.Filled;
|
||||||
|
// scrollImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
|
||||||
|
|
||||||
|
// Image viewportImage = viewportObj.AddComponent<Image>();
|
||||||
|
// //viewportImage.sprite = Theme.mask;
|
||||||
|
// viewportImage.type = Image.Type.Sliced;
|
||||||
|
// viewportImage.color = new Color(1, 1, 1, 1);
|
||||||
|
|
||||||
|
// Mask mask = viewportObj.AddComponent<Mask>();
|
||||||
|
// mask.showMaskGraphic = false;
|
||||||
|
|
||||||
|
// return scrollObj;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ namespace UnityExplorer.UI
|
|||||||
// Create submodules
|
// Create submodules
|
||||||
new MainMenu();
|
new MainMenu();
|
||||||
|
|
||||||
|
MouseInspector.ConstructUI();
|
||||||
|
|
||||||
// Force refresh of anchors
|
// Force refresh of anchors
|
||||||
Canvas.ForceUpdateCanvases();
|
Canvas.ForceUpdateCanvases();
|
||||||
|
|
||||||
@ -89,6 +91,14 @@ namespace UnityExplorer.UI
|
|||||||
{
|
{
|
||||||
PanelDragger.Instance.Update();
|
PanelDragger.Instance.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var slider in SliderScrollbar.Instances)
|
||||||
|
{
|
||||||
|
if (slider.m_slider.gameObject.activeInHierarchy)
|
||||||
|
{
|
||||||
|
slider.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnSceneChange()
|
public static void OnSceneChange()
|
||||||
|
@ -327,13 +327,14 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Inspectors\CacheObject\CacheEnumerated.cs" />
|
<Compile Include="Inspectors\MouseInspector.cs" />
|
||||||
<Compile Include="Inspectors\CacheObject\CacheFactory.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheEnumerated.cs" />
|
||||||
<Compile Include="Inspectors\CacheObject\CacheField.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheFactory.cs" />
|
||||||
<Compile Include="Inspectors\CacheObject\CacheMember.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheField.cs" />
|
||||||
<Compile Include="Inspectors\CacheObject\CacheMethod.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheMember.cs" />
|
||||||
<Compile Include="Inspectors\CacheObject\CacheProperty.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheMethod.cs" />
|
||||||
<Compile Include="Inspectors\CacheObject\CacheObjectBase.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheProperty.cs" />
|
||||||
|
<Compile Include="Inspectors\ReflectionInspector\CacheObject\CacheObjectBase.cs" />
|
||||||
<Compile Include="Helpers\Texture2DHelpers.cs" />
|
<Compile Include="Helpers\Texture2DHelpers.cs" />
|
||||||
<Compile Include="Config\ModConfig.cs" />
|
<Compile Include="Config\ModConfig.cs" />
|
||||||
<Compile Include="ExplorerCore.cs" />
|
<Compile Include="ExplorerCore.cs" />
|
||||||
@ -341,6 +342,9 @@
|
|||||||
<Compile Include="ExplorerMelonMod.cs" />
|
<Compile Include="ExplorerMelonMod.cs" />
|
||||||
<Compile Include="Helpers\ReflectionHelpers.cs" />
|
<Compile Include="Helpers\ReflectionHelpers.cs" />
|
||||||
<Compile Include="Helpers\UnityHelpers.cs" />
|
<Compile Include="Helpers\UnityHelpers.cs" />
|
||||||
|
<Compile Include="Inspectors\GOInspector\ChildList.cs" />
|
||||||
|
<Compile Include="Inspectors\GOInspector\ComponentList.cs" />
|
||||||
|
<Compile Include="Inspectors\GOInspector\GameObjectControls.cs" />
|
||||||
<Compile Include="UI\ForceUnlockCursor.cs" />
|
<Compile Include="UI\ForceUnlockCursor.cs" />
|
||||||
<Compile Include="Input\IHandleInput.cs" />
|
<Compile Include="Input\IHandleInput.cs" />
|
||||||
<Compile Include="Tests\Tests.cs" />
|
<Compile Include="Tests\Tests.cs" />
|
||||||
@ -369,13 +373,14 @@
|
|||||||
<Compile Include="UI\PageModel\HomePage.cs" />
|
<Compile Include="UI\PageModel\HomePage.cs" />
|
||||||
<Compile Include="Inspectors\GameObjectInspector.cs" />
|
<Compile Include="Inspectors\GameObjectInspector.cs" />
|
||||||
<Compile Include="Inspectors\InspectorBase.cs" />
|
<Compile Include="Inspectors\InspectorBase.cs" />
|
||||||
<Compile Include="Inspectors\InstanceInspector.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\InstanceInspector.cs" />
|
||||||
<Compile Include="Inspectors\StaticInspector.cs" />
|
<Compile Include="Inspectors\ReflectionInspector\StaticInspector.cs" />
|
||||||
<Compile Include="UI\PageModel\OptionsPage.cs" />
|
<Compile Include="UI\PageModel\OptionsPage.cs" />
|
||||||
<Compile Include="Inspectors\SceneExplorer.cs" />
|
<Compile Include="Inspectors\SceneExplorer.cs" />
|
||||||
<Compile Include="UI\PageModel\SearchPage.cs" />
|
<Compile Include="UI\PageModel\SearchPage.cs" />
|
||||||
<Compile Include="UI\PanelDragger.cs" />
|
<Compile Include="UI\PanelDragger.cs" />
|
||||||
<Compile Include="UI\InteractiveValue\InteractiveValue.cs" />
|
<Compile Include="UI\InteractiveValue\InteractiveValue.cs" />
|
||||||
|
<Compile Include="UI\Shared\SliderScrollbar.cs" />
|
||||||
<Compile Include="UI\Shared\PageHandler.cs" />
|
<Compile Include="UI\Shared\PageHandler.cs" />
|
||||||
<Compile Include="UI\Shared\SyntaxColors.cs" />
|
<Compile Include="UI\Shared\SyntaxColors.cs" />
|
||||||
<Compile Include="UI\UIManager.cs" />
|
<Compile Include="UI\UIManager.cs" />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Mono.CSharp;
|
||||||
using UnityExplorer.Helpers;
|
using UnityExplorer.Helpers;
|
||||||
#if CPP
|
#if CPP
|
||||||
using UnhollowerBaseLib;
|
using UnhollowerBaseLib;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user