mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-15 13:57:31 +08:00
Lots of fixes, everything basically done except Reflection Inspector
This commit is contained in:
parent
70a1570441
commit
e4d38af4f5
@ -5,7 +5,7 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
|
||||
namespace UnityExplorer.Console
|
||||
{
|
||||
@ -132,44 +132,22 @@ namespace UnityExplorer.Console
|
||||
try
|
||||
{
|
||||
var editor = ConsolePage.Instance.m_codeEditor;
|
||||
|
||||
var textGen = editor.InputText.cachedTextGenerator;
|
||||
|
||||
//if (textGen.characters.Count < 1)
|
||||
// return;
|
||||
|
||||
int caretPos = editor.InputField.caretPosition;
|
||||
|
||||
if (caretPos >= 1)
|
||||
caretPos--;
|
||||
|
||||
if (caretPos < 0 || caretPos == m_lastCaretPos)
|
||||
if (caretPos == m_lastCaretPos)
|
||||
return;
|
||||
|
||||
m_lastCaretPos = caretPos;
|
||||
|
||||
if (caretPos >= 1)
|
||||
caretPos--;
|
||||
|
||||
var pos = textGen.characters[caretPos].cursorPos;
|
||||
|
||||
// todo this calculation isnt the right one to use. It's wrong if we hide the Debug Console.
|
||||
pos = editor.InputField.transform.TransformPoint(pos);
|
||||
|
||||
var posOffset = MainMenu.Instance.MainPanel.transform.position;
|
||||
|
||||
pos = (Vector2)posOffset + pos + new Vector2(25, 35);
|
||||
|
||||
//// 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 + 10, pos.y - 20, 0);
|
||||
}
|
||||
catch //(Exception e)
|
||||
{
|
||||
|
@ -27,8 +27,8 @@ namespace UnityExplorer.Console
|
||||
private int currentIndex;
|
||||
private int currentLookaheadIndex;
|
||||
|
||||
public char Current { get; private set; } = ' ';
|
||||
public char Previous { get; private set; } = ' ';
|
||||
public char Current { get; private set; }
|
||||
public char Previous { get; private set; }
|
||||
|
||||
public bool EndOfStream => currentLookaheadIndex >= inputString.Length;
|
||||
|
||||
|
@ -7,9 +7,10 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI.Shared;
|
||||
#if CPP
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityExplorer.Helpers;
|
||||
@ -26,11 +27,9 @@ namespace UnityExplorer.Console
|
||||
public Text InputText { get; internal set; }
|
||||
public int CurrentIndent { get; private set; }
|
||||
|
||||
private Text inputHighlightText;
|
||||
private Image background;
|
||||
private Image scrollbar;
|
||||
|
||||
public string HighlightedText => inputHighlightText.text;
|
||||
private Text inputHighlightText;
|
||||
|
||||
private readonly CSharpLexer highlightLexer;
|
||||
private readonly StringBuilder sbHighlight;
|
||||
|
||||
@ -68,7 +67,6 @@ The following helper methods are available:
|
||||
|
||||
ConstructUI();
|
||||
|
||||
// subscribe to text input changing
|
||||
#if CPP
|
||||
InputField.onValueChanged.AddListener(new Action<string>((string s) => { OnInputChanged(s); }));
|
||||
#else
|
||||
@ -364,51 +362,20 @@ The following helper methods are available:
|
||||
|
||||
#region CONSOLE INPUT
|
||||
|
||||
var consoleBase = UIFactory.CreateUIObject("CodeEditor", ConsolePage.Instance.Content);
|
||||
int fontSize = 16;
|
||||
|
||||
var consoleLayout = consoleBase.AddComponent<LayoutElement>();
|
||||
consoleLayout.preferredHeight = 500;
|
||||
consoleLayout.flexibleHeight = 50;
|
||||
var inputObj = UIFactory.CreateSrollInputField(ConsolePage.Instance.Content, out InputFieldScroller consoleScroll, fontSize);
|
||||
|
||||
consoleBase.AddComponent<RectMask2D>();
|
||||
|
||||
var mainRect = consoleBase.GetComponent<RectTransform>();
|
||||
mainRect.pivot = Vector2.one * 0.5f;
|
||||
mainRect.anchorMin = Vector2.zero;
|
||||
mainRect.anchorMax = Vector2.one;
|
||||
mainRect.offsetMin = Vector2.zero;
|
||||
mainRect.offsetMax = Vector2.zero;
|
||||
|
||||
var mainBg = UIFactory.CreateUIObject("MainBackground", consoleBase);
|
||||
|
||||
var mainBgRect = mainBg.GetComponent<RectTransform>();
|
||||
mainBgRect.pivot = new Vector2(0, 1);
|
||||
mainBgRect.anchorMin = Vector2.zero;
|
||||
mainBgRect.anchorMax = Vector2.one;
|
||||
mainBgRect.offsetMin = Vector2.zero;
|
||||
mainBgRect.offsetMax = Vector2.zero;
|
||||
|
||||
var mainBgImage = mainBg.AddGraphic<Image>();
|
||||
|
||||
var inputObj = UIFactory.CreateInputField(consoleBase, 14, 0);
|
||||
|
||||
var inputField = inputObj.GetComponent<InputField>();
|
||||
//inputField.richText = false;
|
||||
//inputField.restoreOriginalTextOnEscape = false;
|
||||
|
||||
var inputRect = inputObj.GetComponent<RectTransform>();
|
||||
inputRect.pivot = new Vector2(0, 1);
|
||||
inputRect.anchorMin = Vector2.zero;
|
||||
inputRect.anchorMax = Vector2.one;
|
||||
inputRect.offsetMin = new Vector2(20, 0);
|
||||
inputRect.offsetMax = new Vector2(14, 0);
|
||||
var inputField = consoleScroll.inputField;
|
||||
|
||||
var mainTextObj = inputField.textComponent.gameObject;
|
||||
|
||||
var mainTextInput = mainTextObj.GetComponent<Text>();
|
||||
var mainTextInput = inputField.textComponent;
|
||||
mainTextInput.supportRichText = false;
|
||||
mainTextInput.color = new Color(1, 1, 1, 0.5f);
|
||||
|
||||
var placeHolderText = inputField.placeholder.GetComponent<Text>();
|
||||
placeHolderText.text = STARTUP_TEXT;
|
||||
placeHolderText.fontSize = fontSize;
|
||||
|
||||
var highlightTextObj = UIFactory.CreateUIObject("HighlightText", mainTextObj.gameObject);
|
||||
var highlightTextRect = highlightTextObj.GetComponent<RectTransform>();
|
||||
@ -420,25 +387,7 @@ The following helper methods are available:
|
||||
|
||||
var highlightTextInput = highlightTextObj.AddGraphic<Text>();
|
||||
highlightTextInput.supportRichText = true;
|
||||
|
||||
var scroll = UIFactory.CreateScrollbar(consoleBase);
|
||||
|
||||
var scrollRect = scroll.GetComponent<RectTransform>();
|
||||
scrollRect.anchorMin = new Vector2(1, 0);
|
||||
scrollRect.anchorMax = new Vector2(1, 1);
|
||||
scrollRect.pivot = new Vector2(0.5f, 1);
|
||||
scrollRect.offsetMin = new Vector2(-25f, 0);
|
||||
|
||||
var scroller = scroll.GetComponent<Scrollbar>();
|
||||
scroller.direction = Scrollbar.Direction.TopToBottom;
|
||||
var scrollColors = scroller.colors;
|
||||
scrollColors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
|
||||
scroller.colors = scrollColors;
|
||||
|
||||
var scrollImage = scroll.GetComponent<Image>();
|
||||
|
||||
inputField.GetComponentInChildren<RectMask2D>().enabled = false;
|
||||
inputObj.GetComponent<Image>().enabled = false;
|
||||
highlightTextInput.fontSize = fontSize;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -475,9 +424,10 @@ The following helper methods are available:
|
||||
|
||||
#endregion
|
||||
|
||||
mainTextInput.supportRichText = false;
|
||||
//mainTextInput.supportRichText = false;
|
||||
|
||||
mainTextInput.font = UIManager.ConsoleFont;
|
||||
placeHolderText.font = UIManager.ConsoleFont;
|
||||
highlightTextInput.font = UIManager.ConsoleFont;
|
||||
|
||||
// reset this after formatting finalized
|
||||
@ -492,15 +442,6 @@ The following helper methods are available:
|
||||
|
||||
this.InputText = mainTextInput;
|
||||
this.inputHighlightText = highlightTextInput;
|
||||
this.background = mainBgImage;
|
||||
this.scrollbar = scrollImage;
|
||||
|
||||
// set some colors
|
||||
InputField.caretColor = Color.white;
|
||||
InputText.color = new Color(1, 1, 1, 0.51f);
|
||||
inputHighlightText.color = Color.white;
|
||||
background.color = new Color32(37, 37, 37, 255);
|
||||
scrollbar.color = new Color32(45, 50, 50, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Mono.CSharp;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Console
|
||||
|
@ -2,7 +2,7 @@
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Inspectors;
|
||||
using System.IO;
|
||||
|
@ -63,7 +63,7 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
if (!TargetGO)
|
||||
{
|
||||
ExplorerCore.LogWarning("GameObjectInspector cctor: Target GameObject is null!");
|
||||
ExplorerCore.LogWarning("Target GameObject is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -292,6 +292,7 @@ namespace UnityExplorer.Inspectors
|
||||
m_pathInput = pathInputObj.GetComponent<InputField>();
|
||||
m_pathInput.text = TargetGO.transform.GetTransformPath();
|
||||
m_pathInput.readOnly = true;
|
||||
m_pathInput.lineType = InputField.LineType.MultiLineNewline;
|
||||
var pathInputLayout = pathInputObj.AddComponent<LayoutElement>();
|
||||
pathInputLayout.minHeight = 25;
|
||||
pathInputLayout.flexibleHeight = 75;
|
||||
@ -337,7 +338,6 @@ namespace UnityExplorer.Inspectors
|
||||
nameInputRect.sizeDelta = new Vector2(nameInputRect.sizeDelta.x, 25);
|
||||
m_nameInput = nameInputObj.GetComponent<InputField>();
|
||||
m_nameInput.text = TargetGO.name;
|
||||
m_nameInput.lineType = InputField.LineType.SingleLine;
|
||||
|
||||
var applyNameBtnObj = UIFactory.CreateButton(nameRowObj);
|
||||
var applyNameBtn = applyNameBtnObj.GetComponent<Button>();
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
@ -24,7 +24,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
public static CacheMember GetCacheObject(MemberInfo member, object declaringInstance)
|
||||
public static CacheMember GetCacheObject(MemberInfo member, object declaringInstance, GameObject parentUIContent)
|
||||
{
|
||||
CacheMember ret;
|
||||
|
||||
@ -45,6 +45,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
return null;
|
||||
}
|
||||
|
||||
ret.m_parentContent = parentUIContent;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -19,23 +19,17 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
public override void UpdateReflection()
|
||||
{
|
||||
//if (IValue is InteractiveDictionary iDict)
|
||||
//{
|
||||
// if (!iDict.EnsureDictionaryIsSupported())
|
||||
// {
|
||||
// ReflectionException = "Not supported due to TypeInitializationException";
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
try
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
IValue.Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance);
|
||||
|
||||
base.UpdateValue();
|
||||
//base.UpdateValue();
|
||||
|
||||
m_evaluated = true;
|
||||
ReflectionException = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -3,12 +3,16 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
public class CacheMember : CacheObjectBase
|
||||
public abstract class CacheMember : CacheObjectBase
|
||||
{
|
||||
public MemberInfo MemInfo { get; set; }
|
||||
public Type DeclaringType { get; set; }
|
||||
@ -18,6 +22,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public override bool HasParameters => m_arguments != null && m_arguments.Length > 0;
|
||||
public override bool IsMember => true;
|
||||
public override bool HasEvaluated => m_evaluated;
|
||||
|
||||
public string RichTextName => m_richTextName ?? GetRichTextName();
|
||||
private string m_richTextName;
|
||||
@ -39,21 +44,25 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
DeclaringInstance = declaringInstance;
|
||||
}
|
||||
|
||||
//public virtual void InitMember(MemberInfo member, object declaringInstance)
|
||||
//{
|
||||
// MemInfo = member;
|
||||
// DeclaringInstance = declaringInstance;
|
||||
// DeclaringType = member.DeclaringType;
|
||||
//}
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
#if CPP
|
||||
if (!IsReflectionSupported())
|
||||
this.ReflectionException = "Type not supported with Reflection!";
|
||||
else
|
||||
UpdateReflection();
|
||||
#else
|
||||
UpdateReflection();
|
||||
#endif
|
||||
|
||||
base.UpdateValue();
|
||||
}
|
||||
|
||||
public abstract void UpdateReflection();
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
// ...
|
||||
// no implementation for base class
|
||||
}
|
||||
|
||||
public object[] ParseArguments()
|
||||
@ -114,25 +123,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public static bool HasDefaultValue(ParameterInfo arg) => arg.DefaultValue != DBNull.Value;
|
||||
|
||||
//public void DrawArgsInput()
|
||||
//{
|
||||
// for (int i = 0; i < this.m_arguments.Length; i++)
|
||||
// {
|
||||
// var name = this.m_arguments[i].Name;
|
||||
// var input = this.m_argumentInput[i];
|
||||
// var type = this.m_arguments[i].ParameterType.Name;
|
||||
|
||||
// var label = $"<color={SyntaxColors.Class_Instance}>{type}</color> ";
|
||||
// label += $"<color={SyntaxColors.Local}>{name}</color>";
|
||||
// if (HasDefaultValue(this.m_arguments[i]))
|
||||
// {
|
||||
// label = $"<i>[{label} = {this.m_arguments[i].DefaultValue ?? "null"}]</i>";
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
private bool GetCanWrite()
|
||||
{
|
||||
if (MemInfo is FieldInfo fi)
|
||||
@ -218,5 +208,78 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
return m_richTextName;
|
||||
}
|
||||
|
||||
#if CPP
|
||||
internal bool IsReflectionSupported()
|
||||
{
|
||||
try
|
||||
{
|
||||
var baseType = this.IValue.ValueType;
|
||||
|
||||
var gArgs = baseType.GetGenericArguments();
|
||||
if (gArgs.Length < 1)
|
||||
return true;
|
||||
|
||||
foreach (var arg in gArgs)
|
||||
{
|
||||
if (!Check(arg))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
bool Check(Type type)
|
||||
{
|
||||
if (!typeof(Il2CppSystem.Object).IsAssignableFrom(type))
|
||||
return true;
|
||||
|
||||
var ptr = (IntPtr)typeof(Il2CppClassPointerStore<>)
|
||||
.MakeGenericType(type)
|
||||
.GetField("NativeClassPtr")
|
||||
.GetValue(null);
|
||||
|
||||
if (ptr == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
return Il2CppSystem.Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is Il2CppSystem.Type;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
|
||||
|
||||
internal override void ConstructUI()
|
||||
{
|
||||
base.ConstructUI();
|
||||
|
||||
//var refreshBtnObj = UIFactory.CreateButton(topRowObj, new Color(0.3f, 0.3f, 0.3f));
|
||||
//var btnLayout = refreshBtnObj.AddComponent<LayoutElement>();
|
||||
//btnLayout.minWidth = 30;
|
||||
//btnLayout.minHeight = 20;
|
||||
//btnLayout.flexibleWidth = 0;
|
||||
//var refreshTxt = refreshBtnObj.GetComponentInChildren<Text>();
|
||||
//refreshTxt.text = "⟳";
|
||||
//refreshTxt.fontSize = 16;
|
||||
//var refreshBtn = refreshBtnObj.GetComponent<Button>();
|
||||
//refreshBtn.onClick.AddListener(() => { ExplorerCore.Log("todo Update!"); });
|
||||
|
||||
var labelObj = UIFactory.CreateLabel(m_topContent, TextAnchor.MiddleLeft);
|
||||
var labellayout = labelObj.AddComponent<LayoutElement>();
|
||||
labellayout.minWidth = 225;
|
||||
labellayout.flexibleWidth = 0;
|
||||
|
||||
var label = labelObj.GetComponent<Text>();
|
||||
label.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
label.text = this.RichTextName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,11 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
// CacheMethod cannot UpdateValue directly. Need to Evaluate.
|
||||
}
|
||||
|
||||
public override void UpdateReflection()
|
||||
{
|
||||
// CacheMethod cannot UpdateValue directly. Need to Evaluate.
|
||||
}
|
||||
|
||||
public void Evaluate()
|
||||
{
|
||||
MethodInfo mi;
|
||||
@ -61,6 +66,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
||||
m_evaluated = true;
|
||||
m_isEvaluating = false;
|
||||
ReflectionException = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -122,77 +128,5 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
// ==== GUI DRAW ====
|
||||
|
||||
//public override void Draw(Rect window, float width)
|
||||
//{
|
||||
// base.Draw(window, width);
|
||||
//}
|
||||
|
||||
public void DrawValue(Rect window, float width)
|
||||
{
|
||||
string typeLabel = $"<color={SyntaxColors.Class_Instance}>{IValue.ValueType.FullName}</color>";
|
||||
|
||||
if (m_evaluated)
|
||||
{
|
||||
if (m_cachedReturnValue != null)
|
||||
{
|
||||
//m_cachedReturnValue.IValue.DrawValue(window, width);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label($"null ({typeLabel})", new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> ({typeLabel})", new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
|
||||
//public void DrawGenericArgsInput()
|
||||
//{
|
||||
// GUILayout.Label($"<b><color=orange>Generic Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
|
||||
// for (int i = 0; i < this.GenericArgs.Length; i++)
|
||||
// {
|
||||
// string types = "";
|
||||
// if (this.GenericConstraints[i].Length > 0)
|
||||
// {
|
||||
// foreach (var constraint in this.GenericConstraints[i])
|
||||
// {
|
||||
// if (types != "") types += ", ";
|
||||
|
||||
// string type;
|
||||
|
||||
// if (constraint == null)
|
||||
// type = "Any";
|
||||
// else
|
||||
// type = constraint.ToString();
|
||||
|
||||
// types += $"<color={Syntax.Class_Instance}>{type}</color>";
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// types = $"<color={Syntax.Class_Instance}>Any</color>";
|
||||
// }
|
||||
// var input = this.GenericArgInput[i];
|
||||
|
||||
// GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
// GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
// GUILayout.Label(
|
||||
// $"<color={Syntax.StructGreen}>{this.GenericArgs[i].Name}</color>",
|
||||
// new GUILayoutOption[] { GUILayout.Width(15) }
|
||||
// );
|
||||
// this.GenericArgInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||
// GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
// GUILayout.Label(types, new GUILayoutOption[0]);
|
||||
|
||||
// GUILayout.EndHorizontal();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using UnityEngine;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
@ -16,9 +17,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
public virtual bool CanWrite => false;
|
||||
public virtual bool HasParameters => false;
|
||||
public virtual bool IsMember => false;
|
||||
|
||||
//public bool IsStaticClassSearchResult { get; set; }
|
||||
|
||||
public virtual bool HasEvaluated => true;
|
||||
|
||||
// TODO
|
||||
public virtual void InitValue(object value, Type valueType)
|
||||
@ -28,85 +27,30 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
return;
|
||||
}
|
||||
|
||||
//ExplorerCore.Log("Initializing InteractiveValue of type " + valueType.FullName);
|
||||
|
||||
// InteractiveValue interactive;
|
||||
|
||||
//if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
||||
//{
|
||||
// interactive = new InteractiveGameObject();
|
||||
//}
|
||||
//else if (valueType == typeof(Texture2D))
|
||||
//{
|
||||
// interactive = new InteractiveTexture2D();
|
||||
//}
|
||||
//else if (valueType == typeof(Texture))
|
||||
//{
|
||||
// interactive = new InteractiveTexture();
|
||||
//}
|
||||
//else if (valueType == typeof(Sprite))
|
||||
//{
|
||||
// interactive = new InteractiveSprite();
|
||||
//}
|
||||
//else if (valueType.IsPrimitive || valueType == typeof(string))
|
||||
//{
|
||||
// interactive = new InteractivePrimitive();
|
||||
//}
|
||||
//else if (valueType.IsEnum)
|
||||
//{
|
||||
// if (valueType.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] attributes && attributes.Length > 0)
|
||||
// {
|
||||
// interactive = new InteractiveFlags();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// interactive = new InteractiveEnum();
|
||||
// }
|
||||
//}
|
||||
//else if (valueType == typeof(Vector2) || valueType == typeof(Vector3) || valueType == typeof(Vector4))
|
||||
//{
|
||||
// interactive = new InteractiveVector();
|
||||
//}
|
||||
//else if (valueType == typeof(Quaternion))
|
||||
//{
|
||||
// interactive = new InteractiveQuaternion();
|
||||
//}
|
||||
//else if (valueType == typeof(Color))
|
||||
//{
|
||||
// interactive = new InteractiveColor();
|
||||
//}
|
||||
//else if (valueType == typeof(Rect))
|
||||
//{
|
||||
// interactive = new InteractiveRect();
|
||||
//}
|
||||
//// must check this before IsEnumerable
|
||||
//else if (ReflectionHelpers.IsDictionary(valueType))
|
||||
//{
|
||||
// interactive = new InteractiveDictionary();
|
||||
//}
|
||||
//else if (ReflectionHelpers.IsEnumerable(valueType))
|
||||
//{
|
||||
// interactive = new InteractiveEnumerable();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// interactive = new InteractiveValue();
|
||||
//}
|
||||
|
||||
//interactive.Value = obj;
|
||||
//interactive.ValueType = valueType;
|
||||
|
||||
//this.IValue = interactive;
|
||||
//this.IValue.OwnerCacheObject = this;
|
||||
|
||||
//UpdateValue();
|
||||
|
||||
//this.IValue.Init();
|
||||
// TEMP
|
||||
IValue = new InteractiveValue
|
||||
{
|
||||
OwnerCacheObject = this,
|
||||
ValueType = ReflectionHelpers.GetActualType(value) ?? valueType,
|
||||
};
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
public virtual void Draw(Rect window, float width)
|
||||
public virtual void Enable()
|
||||
{
|
||||
// IValue.Draw(window, width);
|
||||
if (!m_constructedUI)
|
||||
{
|
||||
ConstructUI();
|
||||
IValue.ConstructUI(m_topContent);
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
m_mainContent.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void Disable()
|
||||
{
|
||||
m_mainContent.SetActive(false);
|
||||
}
|
||||
|
||||
public virtual void UpdateValue()
|
||||
@ -115,5 +59,57 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
}
|
||||
|
||||
public virtual void SetValue() => throw new NotImplementedException();
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal bool m_constructedUI;
|
||||
internal GameObject m_parentContent;
|
||||
internal GameObject m_mainContent;
|
||||
internal GameObject m_topContent;
|
||||
//internal GameObject m_subContent;
|
||||
|
||||
// Make base UI holder for CacheObject, this doesnt actually display anything.
|
||||
internal virtual void ConstructUI()
|
||||
{
|
||||
m_constructedUI = true;
|
||||
|
||||
m_mainContent = UIFactory.CreateVerticalGroup(m_parentContent, new Color(0.1f, 0.1f, 0.1f));
|
||||
var rowGroup = m_mainContent.GetComponent<VerticalLayoutGroup>();
|
||||
rowGroup.childForceExpandWidth = true;
|
||||
rowGroup.childControlWidth = true;
|
||||
rowGroup.childForceExpandHeight = false;
|
||||
rowGroup.childControlHeight = true;
|
||||
var rowLayout = m_mainContent.AddComponent<LayoutElement>();
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleHeight = 0;
|
||||
rowLayout.minWidth = 200;
|
||||
rowLayout.flexibleWidth = 5000;
|
||||
|
||||
m_topContent = UIFactory.CreateHorizontalGroup(m_mainContent, new Color(1, 1, 1, 0));
|
||||
var topLayout = m_topContent.AddComponent<LayoutElement>();
|
||||
topLayout.minHeight = 25;
|
||||
topLayout.flexibleHeight = 0;
|
||||
var topGroup = m_topContent.GetComponent<HorizontalLayoutGroup>();
|
||||
topGroup.childForceExpandHeight = false;
|
||||
topGroup.childForceExpandWidth = true;
|
||||
topGroup.childControlHeight = true;
|
||||
topGroup.childControlWidth = true;
|
||||
topGroup.spacing = 4;
|
||||
|
||||
//m_subContent = UIFactory.CreateHorizontalGroup(m_parentContent, new Color(1, 1, 1, 0));
|
||||
//var subGroup = m_subContent.GetComponent<HorizontalLayoutGroup>();
|
||||
//subGroup.childForceExpandWidth = true;
|
||||
//subGroup.childControlWidth = true;
|
||||
//var subLayout = m_subContent.AddComponent<LayoutElement>();
|
||||
//subLayout.minHeight = 25;
|
||||
//subLayout.flexibleHeight = 500;
|
||||
//subLayout.minWidth = 125;
|
||||
//subLayout.flexibleWidth = 9000;
|
||||
|
||||
//m_subContent.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
public override void UpdateValue()
|
||||
public override void UpdateReflection()
|
||||
{
|
||||
if (HasParameters && !m_isEvaluating)
|
||||
{
|
||||
@ -30,15 +30,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
return;
|
||||
}
|
||||
|
||||
//if (IValue is InteractiveDictionary iDict)
|
||||
//{
|
||||
// if (!iDict.EnsureDictionaryIsSupported())
|
||||
// {
|
||||
// ReflectionException = "Not supported due to TypeInitializationException";
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
try
|
||||
{
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
@ -49,18 +40,17 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
IValue.Value = pi.GetValue(target, ParseArguments());
|
||||
|
||||
base.UpdateValue();
|
||||
//base.UpdateValue();
|
||||
|
||||
m_evaluated = true;
|
||||
ReflectionException = null;
|
||||
}
|
||||
else // create a dummy value for Write-Only properties.
|
||||
{
|
||||
if (IValue.ValueType == typeof(string))
|
||||
{
|
||||
IValue.Value = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
IValue.Value = Activator.CreateInstance(IValue.ValueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -3,7 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
|
||||
namespace UnityExplorer.Inspectors.Reflection
|
||||
@ -28,11 +30,26 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public virtual void UpdateValue()
|
||||
{
|
||||
GetButtonLabel();
|
||||
if (!m_text)
|
||||
return;
|
||||
|
||||
if (OwnerCacheObject is CacheMember ownerMember && !string.IsNullOrEmpty(ownerMember.ReflectionException))
|
||||
{
|
||||
m_text.text = "<color=red>" + ownerMember.ReflectionException + "</color>";
|
||||
return;
|
||||
}
|
||||
|
||||
if (Value == null)
|
||||
{
|
||||
m_text.text = "<color=red>null</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
GetButtonLabel();
|
||||
m_text.text = ButtonLabel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private MethodInfo GetToStringMethod()
|
||||
{
|
||||
try
|
||||
@ -52,7 +69,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public string GetButtonLabel()
|
||||
{
|
||||
if (Value == null) return null;
|
||||
if (Value == null) return "";
|
||||
|
||||
var valueType = ReflectionHelpers.GetActualType(Value);
|
||||
|
||||
@ -100,5 +117,35 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
return m_btnLabel = label;
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_UIContent;
|
||||
internal Text m_text;
|
||||
|
||||
public void ConstructUI(GameObject parent)
|
||||
{
|
||||
// TEMPORARY
|
||||
m_UIContent = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
|
||||
var mainLayout = m_UIContent.AddComponent<LayoutElement>();
|
||||
mainLayout.minWidth = 100;
|
||||
mainLayout.flexibleWidth = 5000;
|
||||
mainLayout.minHeight = 25;
|
||||
m_text = m_UIContent.GetComponent<Text>();
|
||||
|
||||
if (OwnerCacheObject != null)
|
||||
{
|
||||
if (!OwnerCacheObject.HasEvaluated)
|
||||
{
|
||||
m_text.text = "Not yet evaluated";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_text.text = ButtonLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,14 @@ using UnityExplorer.UI.Shared;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.UI;
|
||||
using UnityEngine.UI;
|
||||
//using TMPro;
|
||||
using UnityExplorer.Config;
|
||||
|
||||
namespace UnityExplorer.Inspectors
|
||||
{
|
||||
// TODO:
|
||||
// - Filters
|
||||
// - Helper tools for Target object (for UnityEngine.Objects, Components, Textures, and maybe a general ToString helper)
|
||||
|
||||
public class ReflectionInspector : InspectorBase
|
||||
{
|
||||
public override string TabLabel => m_targetTypeShortName;
|
||||
@ -23,9 +27,9 @@ namespace UnityExplorer.Inspectors
|
||||
// all cached members of the target
|
||||
internal CacheMember[] m_allMembers;
|
||||
// filtered members based on current filters
|
||||
//internal CacheMember[] m_membersFiltered;
|
||||
internal CacheMember[] m_membersFiltered;
|
||||
// actual shortlist of displayed members
|
||||
//internal CacheMember[] m_membersShortlist;
|
||||
internal readonly CacheMember[] m_displayedMembers = new CacheMember[ModConfig.Instance.Default_Page_Limit];
|
||||
|
||||
// UI members
|
||||
|
||||
@ -36,8 +40,10 @@ namespace UnityExplorer.Inspectors
|
||||
set => m_content = value;
|
||||
}
|
||||
|
||||
//internal PageHandler m_pageHandler;
|
||||
|
||||
internal PageHandler m_pageHandler;
|
||||
internal SliderScrollbar m_sliderScroller;
|
||||
internal GameObject m_scrollContent;
|
||||
|
||||
// Blacklists
|
||||
private static readonly HashSet<string> s_typeAndMemberBlacklist = new HashSet<string>
|
||||
{
|
||||
@ -65,9 +71,11 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
m_targetTypeShortName = m_targetType.Name;
|
||||
|
||||
ConstructUI();
|
||||
|
||||
CacheMembers(m_targetType);
|
||||
|
||||
ConstructUI();
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
// Methods
|
||||
@ -87,6 +95,50 @@ namespace UnityExplorer.Inspectors
|
||||
GameObject.Destroy(this.Content);
|
||||
}
|
||||
|
||||
private void OnPageTurned()
|
||||
{
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
public void RefreshDisplay()
|
||||
{
|
||||
// TODO TEMP
|
||||
m_membersFiltered = m_allMembers;
|
||||
|
||||
var members = m_membersFiltered;
|
||||
|
||||
m_pageHandler.ListCount = members.Length;
|
||||
|
||||
int newCount = 0;
|
||||
|
||||
// disable current members
|
||||
for (int i = 0; i < m_displayedMembers.Length; i++)
|
||||
{
|
||||
var mem = m_displayedMembers[i];
|
||||
if (mem != null)
|
||||
mem.Disable();
|
||||
}
|
||||
|
||||
foreach (var itemIndex in m_pageHandler)
|
||||
{
|
||||
newCount++;
|
||||
|
||||
// normalized index starting from 0
|
||||
var i = itemIndex - m_pageHandler.StartIndex;
|
||||
|
||||
if (itemIndex >= members.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
CacheMember member = members[itemIndex];
|
||||
|
||||
member.Enable();
|
||||
|
||||
m_displayedMembers[i] = member;
|
||||
}
|
||||
}
|
||||
|
||||
public void CacheMembers(Type type)
|
||||
{
|
||||
var list = new List<CacheMember>();
|
||||
@ -175,7 +227,7 @@ namespace UnityExplorer.Inspectors
|
||||
{
|
||||
//ExplorerCore.Log($"Trying to cache member {sig}...");
|
||||
|
||||
var cached = CacheFactory.GetCacheObject(member, target);
|
||||
var cached = CacheFactory.GetCacheObject(member, target, m_scrollContent);
|
||||
|
||||
if (cached != null)
|
||||
{
|
||||
@ -271,28 +323,14 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
internal void ConstructMemberList()
|
||||
{
|
||||
// TEMPORARY
|
||||
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.12f, 0.12f, 0.12f));
|
||||
|
||||
var scrollobj = UIFactory.CreateScrollView(Content, out GameObject scrollContent, out SliderScrollbar scroller, new Color(0.1f, 0.1f, 0.1f));
|
||||
var scrollGroup = m_scrollContent.GetComponent<VerticalLayoutGroup>();
|
||||
scrollGroup.spacing = 3;
|
||||
|
||||
foreach (var member in this.m_allMembers)
|
||||
{
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(scrollContent, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childForceExpandWidth = true;
|
||||
rowGroup.childControlWidth = true;
|
||||
var rowLayout = rowObj.AddComponent<LayoutElement>();
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleHeight = 0;
|
||||
rowLayout.minWidth = 125;
|
||||
rowLayout.flexibleWidth = 9000;
|
||||
|
||||
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
|
||||
var label = labelObj.GetComponent<Text>();
|
||||
label.text = member.RichTextName;
|
||||
|
||||
}
|
||||
m_pageHandler = new PageHandler(m_sliderScroller);
|
||||
m_pageHandler.ConstructUI(Content);
|
||||
m_pageHandler.OnPageChanged += OnPageTurned;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityExplorer.Console;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using UnityExplorer.Config;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
@ -56,7 +56,6 @@ namespace UnityExplorer.UI
|
||||
|
||||
Pages.Add(new HomePage());
|
||||
Pages.Add(new SearchPage());
|
||||
// TODO remove page on games where it failed to init?
|
||||
Pages.Add(new ConsolePage());
|
||||
Pages.Add(new OptionsPage());
|
||||
|
||||
@ -65,14 +64,35 @@ namespace UnityExplorer.UI
|
||||
foreach (Page page in Pages)
|
||||
{
|
||||
page.Init();
|
||||
page.Content?.SetActive(false);
|
||||
}
|
||||
|
||||
SetPage(Pages[0]);
|
||||
// hide menu until each page has init layout (bit of a hack)
|
||||
initPos = MainPanel.transform.position;
|
||||
MainPanel.transform.position = new Vector3(9999, 9999);
|
||||
}
|
||||
|
||||
internal Vector3 initPos;
|
||||
internal bool pageLayoutInit;
|
||||
internal int layoutInitIndex;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!pageLayoutInit)
|
||||
{
|
||||
if (layoutInitIndex < Pages.Count)
|
||||
{
|
||||
SetPage(Pages[layoutInitIndex]);
|
||||
layoutInitIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pageLayoutInit = true;
|
||||
MainPanel.transform.position = initPos;
|
||||
SetPage(Pages[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_activePage?.Update();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityExplorer.Console;
|
||||
|
||||
namespace UnityExplorer.UI.PageModel
|
||||
namespace UnityExplorer.UI.Modules
|
||||
{
|
||||
public class ConsolePage : MainMenu.Page
|
||||
{
|
||||
@ -25,11 +25,15 @@ namespace UnityExplorer.UI.PageModel
|
||||
public static readonly string[] DefaultUsing = new string[]
|
||||
{
|
||||
"System",
|
||||
"UnityEngine",
|
||||
"System.Linq",
|
||||
"System.Collections",
|
||||
"System.Collections.Generic",
|
||||
"System.Reflection"
|
||||
"System.Reflection",
|
||||
"UnityEngine",
|
||||
#if CPP
|
||||
"UnhollowerBaseLib",
|
||||
"UnhollowerRuntimeLib",
|
||||
#endif
|
||||
};
|
||||
|
||||
public override void Init()
|
||||
@ -42,21 +46,14 @@ namespace UnityExplorer.UI.PageModel
|
||||
|
||||
AutoCompleter.Init();
|
||||
|
||||
try
|
||||
{
|
||||
ResetConsole();
|
||||
ResetConsole();
|
||||
|
||||
// Make sure compiler is supported on this platform
|
||||
m_evaluator.Compile("");
|
||||
// Make sure compiler is supported on this platform
|
||||
m_evaluator.Compile("");
|
||||
|
||||
foreach (string use in DefaultUsing)
|
||||
{
|
||||
AddUsing(use);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
foreach (string use in DefaultUsing)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Exception setting up Console: {e.GetType()}, {e.Message}\r\n{e.StackTrace}");
|
||||
AddUsing(use);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
@ -5,8 +5,9 @@ using UnityExplorer.Unstrip;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.UI.Shared;
|
||||
|
||||
namespace UnityExplorer.UI.PageModel
|
||||
namespace UnityExplorer.UI.Modules
|
||||
{
|
||||
public class DebugConsole
|
||||
{
|
||||
@ -98,51 +99,49 @@ namespace UnityExplorer.UI.PageModel
|
||||
logAreaLayout.preferredHeight = 190;
|
||||
logAreaLayout.flexibleHeight = 0;
|
||||
|
||||
var inputObj = UIFactory.CreateInputField(logAreaObj, 14, 0, 1);
|
||||
//var inputObj = UIFactory.CreateInputField(logAreaObj, 14, 0, 1);
|
||||
|
||||
var mainInputGroup = inputObj.GetComponent<VerticalLayoutGroup>();
|
||||
mainInputGroup.padding.left = 8;
|
||||
mainInputGroup.padding.right = 8;
|
||||
mainInputGroup.padding.top = 5;
|
||||
mainInputGroup.padding.bottom = 5;
|
||||
//var mainInputGroup = inputObj.GetComponent<VerticalLayoutGroup>();
|
||||
//mainInputGroup.padding.left = 8;
|
||||
//mainInputGroup.padding.right = 8;
|
||||
//mainInputGroup.padding.top = 5;
|
||||
//mainInputGroup.padding.bottom = 5;
|
||||
|
||||
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
||||
inputLayout.preferredWidth = 500;
|
||||
inputLayout.flexibleWidth = 9999;
|
||||
//var inputLayout = inputObj.AddComponent<LayoutElement>();
|
||||
//inputLayout.preferredWidth = 500;
|
||||
//inputLayout.flexibleWidth = 9999;
|
||||
|
||||
var inputImage = inputObj.GetComponent<Image>();
|
||||
inputImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
|
||||
//var inputImage = inputObj.GetComponent<Image>();
|
||||
//inputImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
|
||||
|
||||
var scroll = UIFactory.CreateScrollbar(logAreaObj);
|
||||
//var scroll = UIFactory.CreateScrollbar(logAreaObj);
|
||||
|
||||
var scrollLayout = scroll.AddComponent<LayoutElement>();
|
||||
scrollLayout.preferredWidth = 25;
|
||||
scrollLayout.flexibleWidth = 0;
|
||||
//var scrollLayout = scroll.AddComponent<LayoutElement>();
|
||||
//scrollLayout.preferredWidth = 25;
|
||||
//scrollLayout.flexibleWidth = 0;
|
||||
|
||||
var scroller = scroll.GetComponent<Scrollbar>();
|
||||
scroller.direction = Scrollbar.Direction.TopToBottom;
|
||||
var scrollColors = scroller.colors;
|
||||
scrollColors.normalColor = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
scroller.colors = scrollColors;
|
||||
//var scroller = scroll.GetComponent<Scrollbar>();
|
||||
//scroller.direction = Scrollbar.Direction.TopToBottom;
|
||||
//var scrollColors = scroller.colors;
|
||||
//scrollColors.normalColor = new Color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
//scroller.colors = scrollColors;
|
||||
|
||||
var tmpInput = inputObj.GetComponent<InputField>();
|
||||
//tmpInput.scrollSensitivity = 15;
|
||||
//tmpInput.verticalScrollbar = scroller;
|
||||
tmpInput.readOnly = true;
|
||||
//var tmpInput = inputObj.GetComponent<InputField>();
|
||||
//tmpInput.readOnly = true;
|
||||
|
||||
if (UIManager.ConsoleFont != null)
|
||||
{
|
||||
tmpInput.textComponent.font = UIManager.ConsoleFont;
|
||||
#if MONO
|
||||
(tmpInput.placeholder as Text).font = UIManager.ConsoleFont;
|
||||
#else
|
||||
tmpInput.placeholder.TryCast<Text>().font = UIManager.ConsoleFont;
|
||||
#endif
|
||||
}
|
||||
//if (UIManager.ConsoleFont)
|
||||
//{
|
||||
// tmpInput.textComponent.font = UIManager.ConsoleFont;
|
||||
//}
|
||||
|
||||
tmpInput.readOnly = true;
|
||||
//tmpInput.readOnly = true;
|
||||
|
||||
m_textInput = inputObj.GetComponent<InputField>();
|
||||
var inputScrollerObj = UIFactory.CreateSrollInputField(logAreaObj, out InputFieldScroller inputScroll, 14, new Color(0.05f, 0.05f, 0.05f));
|
||||
|
||||
inputScroll.inputField.textComponent.font = UIManager.ConsoleFont;
|
||||
inputScroll.inputField.readOnly = true;
|
||||
|
||||
m_textInput = inputScroll.inputField;
|
||||
|
||||
#endregion
|
||||
|
@ -5,7 +5,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.PageModel
|
||||
namespace UnityExplorer.UI.Modules
|
||||
{
|
||||
public class HomePage : MainMenu.Page
|
||||
{
|
@ -8,7 +8,7 @@ using UnityExplorer.Config;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Unstrip;
|
||||
|
||||
namespace UnityExplorer.UI.PageModel
|
||||
namespace UnityExplorer.UI.Modules
|
||||
{
|
||||
public class OptionsPage : MainMenu.Page
|
||||
{
|
@ -13,7 +13,7 @@ using UnityExplorer.Unstrip;
|
||||
using UnhollowerRuntimeLib;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.UI.PageModel
|
||||
namespace UnityExplorer.UI.Modules
|
||||
{
|
||||
internal enum SearchContext
|
||||
{
|
108
src/UI/Shared/InputFieldScroller.cs
Normal file
108
src/UI/Shared/InputFieldScroller.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
using UnityExplorer.Helpers;
|
||||
|
||||
namespace UnityExplorer.UI.Shared
|
||||
{
|
||||
// To fix an issue with Input Fields and allow them to go inside a ScrollRect nicely.
|
||||
|
||||
public class InputFieldScroller
|
||||
{
|
||||
public static readonly List<InputFieldScroller> Instances = new List<InputFieldScroller>();
|
||||
|
||||
internal SliderScrollbar sliderScroller;
|
||||
internal InputField inputField;
|
||||
|
||||
internal RectTransform inputRect;
|
||||
internal LayoutElement layoutElement;
|
||||
internal VerticalLayoutGroup parentLayoutGroup;
|
||||
|
||||
internal static CanvasScaler canvasScaler;
|
||||
|
||||
public InputFieldScroller(SliderScrollbar sliderScroller, InputField inputField)
|
||||
{
|
||||
Instances.Add(this);
|
||||
|
||||
this.sliderScroller = sliderScroller;
|
||||
this.inputField = inputField;
|
||||
|
||||
#if MONO
|
||||
inputField.onValueChanged.AddListener(OnTextChanged);
|
||||
#else
|
||||
inputField.onValueChanged.AddListener(new Action<string>(OnTextChanged));
|
||||
#endif
|
||||
|
||||
inputRect = inputField.GetComponent<RectTransform>();
|
||||
layoutElement = inputField.gameObject.AddComponent<LayoutElement>();
|
||||
parentLayoutGroup = inputField.transform.parent.GetComponent<VerticalLayoutGroup>();
|
||||
|
||||
layoutElement.minHeight = 25;
|
||||
layoutElement.minWidth = 100;
|
||||
|
||||
if (!canvasScaler)
|
||||
canvasScaler = UIManager.CanvasRoot.GetComponent<CanvasScaler>();
|
||||
}
|
||||
|
||||
internal string m_lastText;
|
||||
internal bool m_updateWanted;
|
||||
|
||||
// only done once, to fix height on creation.
|
||||
internal bool heightInitAfterLayout;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!heightInitAfterLayout)
|
||||
{
|
||||
heightInitAfterLayout = true;
|
||||
var height = sliderScroller.m_scrollRect.parent.parent.GetComponent<RectTransform>().rect.height;
|
||||
layoutElement.preferredHeight = height;
|
||||
}
|
||||
|
||||
if (m_updateWanted && inputField.gameObject.activeInHierarchy)
|
||||
{
|
||||
m_updateWanted = false;
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnTextChanged(string text)
|
||||
{
|
||||
m_lastText = text;
|
||||
m_updateWanted = true;
|
||||
}
|
||||
|
||||
internal void RefreshUI()
|
||||
{
|
||||
var curInputRect = inputField.textComponent.rectTransform.rect;
|
||||
var scaleFactor = canvasScaler.scaleFactor;
|
||||
|
||||
// Current text settings
|
||||
var texGenSettings = inputField.textComponent.GetGenerationSettings(curInputRect.size);
|
||||
texGenSettings.generateOutOfBounds = false;
|
||||
texGenSettings.scaleFactor = scaleFactor;
|
||||
|
||||
// Preferred text rect height
|
||||
var textGen = inputField.textComponent.cachedTextGeneratorForLayout;
|
||||
float preferredHeight = (textGen.GetPreferredHeight(m_lastText, texGenSettings) / scaleFactor) + 10;
|
||||
|
||||
// Default text rect height (fit to scroll parent or expand to fit text)
|
||||
float minHeight = Mathf.Max(preferredHeight, sliderScroller.m_scrollRect.rect.height - 25);
|
||||
|
||||
layoutElement.preferredHeight = minHeight;
|
||||
|
||||
if (inputField.caretPosition == inputField.text.Length
|
||||
&& inputField.text.Length > 0
|
||||
&& inputField.text[inputField.text.Length - 1] == '\n')
|
||||
{
|
||||
sliderScroller.m_slider.value = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ public class SliderScrollbar
|
||||
|
||||
internal readonly Scrollbar m_scrollbar;
|
||||
internal readonly Slider m_slider;
|
||||
internal readonly RectTransform m_scrollRect;
|
||||
|
||||
public SliderScrollbar(Scrollbar scrollbar, Slider slider)
|
||||
{
|
||||
@ -22,6 +23,7 @@ public class SliderScrollbar
|
||||
|
||||
this.m_scrollbar = scrollbar;
|
||||
this.m_slider = slider;
|
||||
this.m_scrollRect = scrollbar.transform.parent.GetComponent<RectTransform>();
|
||||
|
||||
#if MONO
|
||||
this.m_scrollbar.onValueChanged.AddListener(this.OnScrollbarValueChanged);
|
||||
@ -73,7 +75,7 @@ public class SliderScrollbar
|
||||
public void OnScrollbarValueChanged(float _value)
|
||||
{
|
||||
if (this.m_slider.value != _value)
|
||||
this.m_slider.Set(_value, false);
|
||||
this.m_slider.Set(_value, false);
|
||||
}
|
||||
|
||||
public void OnSliderValueChanged(float _value)
|
||||
|
@ -2,6 +2,7 @@
|
||||
//using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Shared;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
{
|
||||
@ -402,21 +403,40 @@ namespace UnityExplorer.UI
|
||||
return toggleObj;
|
||||
}
|
||||
|
||||
public static GameObject CreateSrollInputField(GameObject parent, out InputFieldScroller inputScroll, int fontSize = 14, Color color = default)
|
||||
{
|
||||
if (color == default)
|
||||
color = new Color(0.15f, 0.15f, 0.15f);
|
||||
|
||||
var mainObj = CreateScrollView(parent, out GameObject scrollContent, out SliderScrollbar scroller, color);
|
||||
|
||||
var inputObj = CreateInputField(scrollContent, fontSize, 0);
|
||||
|
||||
var inputField = inputObj.GetComponent<InputField>();
|
||||
inputField.lineType = InputField.LineType.MultiLineNewline;
|
||||
inputField.targetGraphic.color = color;
|
||||
|
||||
inputScroll = new InputFieldScroller(scroller, inputField);
|
||||
|
||||
return mainObj;
|
||||
}
|
||||
|
||||
public static GameObject CreateInputField(GameObject parent, int fontSize = 14, int alignment = 3, int wrap = 0)
|
||||
{
|
||||
GameObject mainObj = CreateUIObject("InputField", parent);
|
||||
|
||||
Image mainImage = mainObj.AddGraphic<Image>();
|
||||
mainImage.type = Image.Type.Sliced;
|
||||
mainImage.color = new Color(38f / 255f, 38f / 255f, 38f / 255f, 1.0f);
|
||||
mainImage.color = new Color(0.15f, 0.15f, 0.15f);
|
||||
|
||||
InputField mainInput = mainObj.AddComponent<InputField>();
|
||||
Navigation nav = mainInput.navigation;
|
||||
nav.mode = Navigation.Mode.None;
|
||||
mainInput.navigation = nav;
|
||||
mainInput.lineType = InputField.LineType.MultiLineNewline;
|
||||
mainInput.lineType = InputField.LineType.SingleLine;
|
||||
mainInput.interactable = true;
|
||||
mainInput.transition = Selectable.Transition.ColorTint;
|
||||
mainInput.targetGraphic = mainImage;
|
||||
|
||||
ColorBlock mainColors = mainInput.colors;
|
||||
mainColors.normalColor = new Color(1, 1, 1, 1);
|
||||
@ -458,8 +478,8 @@ namespace UnityExplorer.UI
|
||||
placeHolderRect.offsetMax = Vector2.zero;
|
||||
|
||||
LayoutElement placeholderLayout = placeHolderObj.AddComponent<LayoutElement>();
|
||||
placeholderLayout.preferredWidth = 990;
|
||||
placeholderLayout.flexibleWidth = 500;
|
||||
placeholderLayout.minWidth = 500;
|
||||
placeholderLayout.flexibleWidth = 5000;
|
||||
|
||||
mainInput.placeholder = placeholderText;
|
||||
|
||||
@ -479,8 +499,8 @@ namespace UnityExplorer.UI
|
||||
inputTextRect.offsetMax = Vector2.zero;
|
||||
|
||||
LayoutElement inputTextLayout = inputTextObj.AddComponent<LayoutElement>();
|
||||
inputTextLayout.preferredWidth = 990;
|
||||
inputTextLayout.flexibleWidth = 500;
|
||||
inputTextLayout.minWidth = 500;
|
||||
inputTextLayout.flexibleWidth = 5000;
|
||||
|
||||
mainInput.textComponent = inputText;
|
||||
|
||||
@ -671,19 +691,19 @@ namespace UnityExplorer.UI
|
||||
contentLayout.padding.bottom = 5;
|
||||
contentLayout.spacing = 5;
|
||||
|
||||
GameObject scrollBar = CreateUIObject("DynamicScrollbar", mainObj);
|
||||
GameObject scrollBarObj = CreateUIObject("DynamicScrollbar", mainObj);
|
||||
|
||||
var scrollbarLayout = scrollBar.AddComponent<VerticalLayoutGroup>();
|
||||
var scrollbarLayout = scrollBarObj.AddComponent<VerticalLayoutGroup>();
|
||||
scrollbarLayout.childForceExpandHeight = true;
|
||||
scrollbarLayout.childControlHeight = true;
|
||||
|
||||
RectTransform scrollBarRect = scrollBar.GetComponent<RectTransform>();
|
||||
RectTransform scrollBarRect = scrollBarObj.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);
|
||||
GameObject hiddenBar = CreateScrollbar(scrollBarObj);
|
||||
var hiddenScroll = hiddenBar.GetComponent<Scrollbar>();
|
||||
hiddenScroll.SetDirection(Scrollbar.Direction.BottomToTop, true);
|
||||
|
||||
@ -693,7 +713,7 @@ namespace UnityExplorer.UI
|
||||
child.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
SliderScrollbar.CreateSliderScrollbar(scrollBar, out Slider scrollSlider);
|
||||
SliderScrollbar.CreateSliderScrollbar(scrollBarObj, out Slider scrollSlider);
|
||||
|
||||
// Back to the main scrollview ScrollRect, setting it up now that we have all references.
|
||||
|
||||
|
@ -2,11 +2,12 @@
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Inspectors;
|
||||
using UnityExplorer.UI.PageModel;
|
||||
using UnityExplorer.UI.Modules;
|
||||
using System.IO;
|
||||
//using TMPro;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI.Shared;
|
||||
#if CPP
|
||||
using UnityExplorer.Unstrip;
|
||||
#endif
|
||||
@ -22,7 +23,6 @@ namespace UnityExplorer.UI
|
||||
internal static Material UIMaterial { get; private set; }
|
||||
internal static Sprite ResizeCursor { get; private set; }
|
||||
internal static Font ConsoleFont { get; private set; }
|
||||
internal static Font DefaultFont { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
@ -31,11 +31,12 @@ namespace UnityExplorer.UI
|
||||
{
|
||||
var bundle = AssetBundle.LoadFromFile(bundlePath);
|
||||
|
||||
UIMaterial = bundle.LoadAsset<Material>("UIMaterial");
|
||||
// Fix for games which don't ship with 'UI/Default' shader.
|
||||
Graphic.defaultGraphicMaterial.shader = bundle.LoadAsset<Shader>("DefaultUI");
|
||||
|
||||
ResizeCursor = bundle.LoadAsset<Sprite>("cursor");
|
||||
|
||||
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
|
||||
DefaultFont = bundle.LoadAsset<Font>("CONSOLA");
|
||||
|
||||
ExplorerCore.Log("Loaded UI bundle");
|
||||
}
|
||||
@ -54,8 +55,8 @@ namespace UnityExplorer.UI
|
||||
|
||||
// Force refresh of anchors
|
||||
Canvas.ForceUpdateCanvases();
|
||||
CanvasRoot.SetActive(false);
|
||||
CanvasRoot.SetActive(true);
|
||||
//CanvasRoot.SetActive(false);
|
||||
//CanvasRoot.SetActive(true);
|
||||
}
|
||||
|
||||
public static void SetEventSystem()
|
||||
@ -109,6 +110,16 @@ namespace UnityExplorer.UI
|
||||
else
|
||||
slider.Update();
|
||||
}
|
||||
|
||||
for (int i = 0; i < InputFieldScroller.Instances.Count; i++)
|
||||
{
|
||||
var input = InputFieldScroller.Instances[i];
|
||||
|
||||
if (input.sliderScroller.CheckDestroyed())
|
||||
i--;
|
||||
else
|
||||
input.Update();
|
||||
}
|
||||
}
|
||||
|
||||
private static GameObject CreateRootCanvas()
|
||||
|
@ -348,11 +348,11 @@
|
||||
<Compile Include="Input\InputSystem.cs" />
|
||||
<Compile Include="Input\LegacyInput.cs" />
|
||||
<Compile Include="Input\NoInput.cs" />
|
||||
<Compile Include="UI\PageModel\DebugConsole.cs" />
|
||||
<Compile Include="UI\Modules\DebugConsole.cs" />
|
||||
<Compile Include="Inspectors\InspectorManager.cs" />
|
||||
<Compile Include="Inspectors\ReflectionInspector.cs" />
|
||||
<Compile Include="UI\MainMenu.cs" />
|
||||
<Compile Include="UI\PageModel\ConsolePage.cs" />
|
||||
<Compile Include="UI\Modules\ConsolePage.cs" />
|
||||
<Compile Include="Console\AutoCompleter.cs" />
|
||||
<Compile Include="Console\CodeEditor.cs" />
|
||||
<Compile Include="Console\Lexer\CommentMatch.cs" />
|
||||
@ -365,16 +365,17 @@
|
||||
<Compile Include="Console\Suggestion.cs" />
|
||||
<Compile Include="Console\ScriptEvaluator.cs" />
|
||||
<Compile Include="Console\ScriptInteraction.cs" />
|
||||
<Compile Include="UI\PageModel\HomePage.cs" />
|
||||
<Compile Include="UI\Modules\HomePage.cs" />
|
||||
<Compile Include="Inspectors\GameObjectInspector.cs" />
|
||||
<Compile Include="Inspectors\InspectorBase.cs" />
|
||||
<Compile Include="Inspectors\Reflection\InstanceInspector.cs" />
|
||||
<Compile Include="Inspectors\Reflection\StaticInspector.cs" />
|
||||
<Compile Include="UI\PageModel\OptionsPage.cs" />
|
||||
<Compile Include="UI\Modules\OptionsPage.cs" />
|
||||
<Compile Include="Inspectors\SceneExplorer.cs" />
|
||||
<Compile Include="UI\PageModel\SearchPage.cs" />
|
||||
<Compile Include="UI\Modules\SearchPage.cs" />
|
||||
<Compile Include="UI\PanelDragger.cs" />
|
||||
<Compile Include="Inspectors\Reflection\InteractiveValue\InteractiveValue.cs" />
|
||||
<Compile Include="UI\Shared\InputFieldScroller.cs" />
|
||||
<Compile Include="UI\Shared\SliderScrollbar.cs" />
|
||||
<Compile Include="UI\Shared\PageHandler.cs" />
|
||||
<Compile Include="UI\Shared\SyntaxColors.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user