DebugConsole save log on quit, some work on CacheObjects, fix missing-material issue on games without default UI Shader

This commit is contained in:
sinaioutlander
2020-11-12 20:31:08 +11:00
parent 668c8f7c3f
commit dc449d4a1e
17 changed files with 336 additions and 248 deletions

View File

@ -167,7 +167,7 @@ namespace UnityExplorer.Inspectors
titleLayout.minHeight = 30;
titleLayout.flexibleHeight = 0;
titleLayout.minWidth = 90;
titleLayout.flexibleWidth = 0;
titleLayout.flexibleWidth = 20000;
ConstructToolbar(topRowObj);
@ -222,84 +222,84 @@ namespace UnityExplorer.Inspectors
invisGroup.padding.right = 2;
invisGroup.spacing = 10;
// time scale group
// // 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;
// 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
// // 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;
// 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
// // 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;
// 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");
// // todo make static and update
// var s_timeText = timeLabelObj.GetComponent<Text>();
// s_timeText.text = Time.timeScale.ToString("F1");
// time scale input
// // time scale input
var timeInputObj = UIFactory.CreateInputField(timeGroupObj);
var timeInput = timeInputObj.GetComponent<InputField>();
timeInput.characterValidation = InputField.CharacterValidation.Decimal;
var timeInputLayout = timeInputObj.AddComponent<LayoutElement>();
timeInputLayout.minWidth = 90;
timeInputLayout.flexibleWidth = 0;
timeInputLayout.minHeight = 25;
timeInputLayout.flexibleHeight = 0;
// var timeInputObj = UIFactory.CreateInputField(timeGroupObj);
// var timeInput = timeInputObj.GetComponent<InputField>();
// timeInput.characterValidation = InputField.CharacterValidation.Decimal;
// var timeInputLayout = timeInputObj.AddComponent<LayoutElement>();
// timeInputLayout.minWidth = 90;
// timeInputLayout.flexibleWidth = 0;
// timeInputLayout.minHeight = 25;
// timeInputLayout.flexibleHeight = 0;
// time scale apply button
// // 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;
// 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");
}
// void SetTimeScale()
// {
// var scale = float.Parse(timeInput.text);
// Time.timeScale = scale;
// s_timeText.text = Time.timeScale.ToString("F1");
// }
// inspect under mouse button

View File

@ -20,9 +20,12 @@ namespace UnityExplorer.Inspectors.Reflection
public object DeclaringInstance { get; set; }
public virtual bool IsStatic { get; private set; }
public override bool HasParameters => m_arguments != null && m_arguments.Length > 0;
public override bool IsMember => true;
public override bool HasParameters => ParamCount > 0;
public virtual int ParamCount => m_arguments.Length;
public override bool HasEvaluated => m_evaluated;
public string RichTextName => m_richTextName ?? GetRichTextName();
@ -47,28 +50,24 @@ namespace UnityExplorer.Inspectors.Reflection
public override void UpdateValue()
{
if (HasParameters && !m_isEvaluating)
{
// need to enter args first
return;
}
try
if (!HasParameters || m_isEvaluating)
{
try
{
#if CPP
if (!IsReflectionSupported())
throw new Exception("Type not supported with Reflection");
if (!IsReflectionSupported())
throw new Exception("Type not supported with Reflection");
#endif
UpdateReflection();
UpdateReflection();
#if CPP
if (IValue.Value != null)
IValue.Value = IValue.Value.Il2CppCast(ReflectionHelpers.GetActualType(IValue.Value));
if (IValue.Value != null)
IValue.Value = IValue.Value.Il2CppCast(ReflectionHelpers.GetActualType(IValue.Value));
#endif
}
catch (Exception e)
{
ReflectionException = ReflectionHelpers.ExceptionToString(e, true);
}
catch (Exception e)
{
ReflectionException = ReflectionHelpers.ExceptionToString(e, true);
}
}
base.UpdateValue();
@ -227,7 +226,7 @@ namespace UnityExplorer.Inspectors.Reflection
internal RectTransform m_topRowRect;
internal LayoutElement m_leftLayout;
internal LayoutElement m_rightLayout;
//internal GameObject m_subGroup;
internal GameObject m_subContent;
internal override void ConstructUI()
{
@ -272,7 +271,7 @@ namespace UnityExplorer.Inspectors.Reflection
leftRect.offsetMax = Vector2.zero;
leftRect.sizeDelta = Vector2.zero;
m_leftLayout = labelObj.AddComponent<LayoutElement>();
m_leftLayout.preferredWidth = 225;
m_leftLayout.preferredWidth = 125;
m_leftLayout.minHeight = 25;
m_leftLayout.flexibleHeight = 100;
var labelFitter = labelObj.AddComponent<ContentSizeFitter>();
@ -284,50 +283,78 @@ namespace UnityExplorer.Inspectors.Reflection
// right group
m_rightGroup = UIFactory.CreateHorizontalGroup(topGroupObj, new Color(1, 1, 1, 0));
m_rightGroup = UIFactory.CreateVerticalGroup(topGroupObj, new Color(1, 1, 1, 0));
m_rightLayout = m_rightGroup.AddComponent<LayoutElement>();
m_rightLayout.minHeight = 25;
m_rightLayout.flexibleHeight = 480;
m_rightLayout.minWidth = 300;
m_rightLayout.minWidth = 125;
m_rightLayout.flexibleWidth = 5000;
var rightGroup = m_rightGroup.GetComponent<HorizontalLayoutGroup>();
rightGroup.childForceExpandHeight = false;
rightGroup.childForceExpandWidth = true;
var rightGroup = m_rightGroup.GetComponent<VerticalLayoutGroup>();
rightGroup.childForceExpandHeight = true;
rightGroup.childForceExpandWidth = false;
rightGroup.childControlHeight = true;
rightGroup.childControlWidth = true;
rightGroup.spacing = 4;
// todo check for HasParameters, etc
if (!HasParameters && IsMember)
// evaluate button
if (this is CacheMethod || HasParameters)
{
//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 color = HasParameters ? new Color(0.4f, 0.4f, 0.4f) : new Color(0.3f, 0.6f, 0.3f);
var evalButtonObj = UIFactory.CreateButton(m_rightGroup, color);
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
evalLayout.minWidth = 100;
evalLayout.minHeight = 22;
evalLayout.flexibleWidth = 0;
var evalText = evalButtonObj.GetComponentInChildren<Text>();
evalText.text = HasParameters
? $"Evaluate ({ParamCount})"
: "Evaluate";
var evalButton = evalButtonObj.GetComponent<Button>();
var colors = evalButton.colors;
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
evalButton.colors = colors;
#if CPP
evalButton.onClick.AddListener(new Action(OnMainEvaluateButton));
#else
evalButton.onClick.AddListener(OnMainEvaluateButton);
#endif
void OnMainEvaluateButton()
{
if (HasParameters)
{
// todo show parameter input
ExplorerCore.Log("TODO params");
}
else
{
// method with no parameters
(this as CacheMethod).Evaluate();
}
}
}
IValue.ConstructUI(m_rightGroup);
// subcontent
// todo subcontent
// todo check if IValue actually has subcontent
//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 = 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 = 50;
subLayout.flexibleHeight = 500;
subLayout.minWidth = 125;
subLayout.flexibleWidth = 9000;
//m_subContent.SetActive(false);
m_subContent.SetActive(false);
// Construct InteractiveValue UI
IValue.ConstructUI(m_rightGroup, m_subContent);
}
#endregion

View File

@ -10,12 +10,14 @@ namespace UnityExplorer.Inspectors.Reflection
{
public class CacheMethod : CacheMember
{
private CacheObjectBase m_cachedReturnValue;
//private CacheObjectBase m_cachedReturnValue;
public override bool HasParameters => base.HasParameters || GenericArgs.Length > 0;
public override bool IsStatic => (MemInfo as MethodInfo).IsStatic;
public override int ParamCount => base.ParamCount + m_genericArgInput.Length;
public Type[] GenericArgs { get; private set; }
public Type[][] GenericConstraints { get; private set; }
@ -38,7 +40,7 @@ namespace UnityExplorer.Inspectors.Reflection
public override void UpdateValue()
{
// CacheMethod cannot UpdateValue directly. Need to Evaluate.
base.UpdateValue();
}
public override void UpdateReflection()
@ -74,17 +76,20 @@ namespace UnityExplorer.Inspectors.Reflection
ReflectionException = ReflectionHelpers.ExceptionToString(e);
}
if (ret != null)
{
//m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
IValue.Value = ret;
IValue.UpdateValue();
//m_cachedReturnValue = CacheFactory.GetCacheObject(ret);
m_cachedReturnValue.UpdateValue();
}
else
{
m_cachedReturnValue = null;
}
//if (ret != null)
//{
// //m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
// //m_cachedReturnValue = CacheFactory.GetCacheObject(ret);
// // m_cachedReturnValue.UpdateValue();
//}
//else
//{
// m_cachedReturnValue = null;
//}
}
private MethodInfo MakeGenericMethodFromInput()

View File

@ -1,4 +1,5 @@
using System;
using UnityEngine;
using UnityExplorer.Helpers;
namespace UnityExplorer.Inspectors.Reflection
@ -9,17 +10,16 @@ namespace UnityExplorer.Inspectors.Reflection
public InstanceInspector(object target) : base(target)
{
// needed?
}
public override void Update()
public void ConstructInstanceHelpers(GameObject parent)
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
}
// todo
}
public void ConstructInstanceFilters(GameObject parent)
{
// todo
}
}

View File

@ -19,6 +19,9 @@ namespace UnityExplorer.Inspectors.Reflection
public object Value { get; set; }
public Type ValueType;
// might not need
public virtual bool HasSubContent => false;
public string RichTextValue => m_richValue ?? GetRichTextValue();
internal string m_richValue;
internal string m_richValueType;
@ -69,7 +72,6 @@ namespace UnityExplorer.Inspectors.Reflection
return m_toStringMethod;
}
public string GetRichTextValue()
{
if (Value != null)
@ -77,14 +79,15 @@ namespace UnityExplorer.Inspectors.Reflection
m_richValueType = UISyntaxHighlight.GetHighlight(ValueType, true);
if (OwnerCacheObject is CacheMember cm && !cm.HasEvaluated)
return $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
if (Value == null) return $"<color=grey>null</color> ({m_richValueType})";
string label;
if (ValueType == typeof(TextAsset))
if (ValueType == typeof(TextAsset) && Value is TextAsset textAsset)
{
var textAsset = Value as TextAsset;
label = textAsset.text;
if (label.Length > 10)
@ -128,8 +131,9 @@ namespace UnityExplorer.Inspectors.Reflection
internal GameObject m_UIContent;
internal Text m_text;
internal GameObject m_subContentParent;
public void ConstructUI(GameObject parent)
public virtual void ConstructUI(GameObject parent, GameObject subGroup)
{
m_UIContent = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
var mainLayout = m_UIContent.AddComponent<LayoutElement>();
@ -138,8 +142,7 @@ namespace UnityExplorer.Inspectors.Reflection
mainLayout.minHeight = 25;
m_text = m_UIContent.GetComponent<Text>();
GetRichTextValue();
m_text.text = $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
m_subContentParent = subGroup;
}
#endregion

View File

@ -8,19 +8,7 @@ namespace UnityExplorer.Inspectors.Reflection
public StaticInspector(Type type) : base(type)
{
// TODO
}
public override void Update()
{
base.Update();
if (m_pendingDestroy || InspectorManager.Instance.m_activeInspector != this)
{
return;
}
// todo
// needed?
}
}
}

View File

@ -158,7 +158,7 @@ namespace UnityExplorer.Inspectors
RefreshDisplay();
}
public void RefreshDisplay(bool fast = false)
public void RefreshDisplay()
{
// temp because not doing filtering yet
m_membersFiltered = m_allMembers;
@ -166,17 +166,14 @@ namespace UnityExplorer.Inspectors
var members = m_membersFiltered;
m_pageHandler.ListCount = members.Length;
if (!fast)
// disable current members
for (int i = 0; i < m_displayedMembers.Length; i++)
{
// disable current members
for (int i = 0; i < m_displayedMembers.Length; i++)
{
var mem = m_displayedMembers[i];
if (mem != null)
mem.Disable();
else
break;
}
var mem = m_displayedMembers[i];
if (mem != null)
mem.Disable();
else
break;
}
if (members.Length < 1)
@ -188,7 +185,6 @@ namespace UnityExplorer.Inspectors
break;
CacheMember member = members[itemIndex];
m_displayedMembers[itemIndex - m_pageHandler.StartIndex] = member;
member.Enable();
}
@ -211,7 +207,7 @@ namespace UnityExplorer.Inspectors
labelWidth = width;
}
float valueWidth = m_scrollContentRect.rect.width - labelWidth - 10;
float valueWidth = m_scrollContentRect.rect.width - labelWidth - 20;
foreach (var cache in m_displayedMembers)
{
@ -382,6 +378,7 @@ namespace UnityExplorer.Inspectors
var typeLabel = UIFactory.CreateLabel(typeRowObj, TextAnchor.MiddleLeft);
var typeLabelText = typeLabel.GetComponent<Text>();
typeLabelText.text = "Type:";
typeLabelText.horizontalOverflow = HorizontalWrapMode.Overflow;
var typeLabelTextLayout = typeLabel.AddComponent<LayoutElement>();
typeLabelTextLayout.minWidth = 60;
typeLabelTextLayout.flexibleWidth = 0;
@ -395,15 +392,40 @@ namespace UnityExplorer.Inspectors
typeLabelLayout.flexibleWidth = 5000;
typeLabelInput.text = UISyntaxHighlight.GetHighlight(m_targetType, true);
// Helper tools
if (this is InstanceInspector ii)
{
ii.ConstructInstanceHelpers(Content);
}
}
internal void ConstructFilterArea()
{
var filterAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
var filterLayout = filterAreaObj.AddComponent<LayoutElement>();
filterLayout.minHeight = 25;
var filterGroup = filterAreaObj.GetComponent<VerticalLayoutGroup>();
filterGroup.childForceExpandWidth = true;
filterGroup.childForceExpandHeight = false;
filterGroup.childControlWidth = true;
filterGroup.childControlHeight = true;
// name filter
// todo instance inspector has extra filters
// todo instance inspector "helper tools"
// membertype filter
// Instance filters
if (this is InstanceInspector ii)
{
ii.ConstructInstanceFilters(filterAreaObj);
}
}
internal void ConstructMemberList()