Removed TextMeshPro dependency, using only vanilla UI now. Also fixes for games which dont ship with Default UI Shader.

This commit is contained in:
sinaioutlander
2020-11-10 20:18:14 +11:00
parent 6766a8cf4c
commit f87b06989d
23 changed files with 337 additions and 598 deletions

View File

@ -4,7 +4,7 @@ using System.Linq;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
using UnityExplorer.Unstrip;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Inspectors.GameObjects;
@ -36,10 +36,10 @@ namespace UnityExplorer.Inspectors
}
private static string m_lastName;
public static TMP_InputField m_nameInput;
public static InputField m_nameInput;
private static string m_lastPath;
public static TMP_InputField m_pathInput;
public static InputField m_pathInput;
private static RectTransform m_pathInputRect;
private static GameObject m_pathGroupObj;
private static Text m_hiddenPathText;
@ -271,7 +271,7 @@ namespace UnityExplorer.Inspectors
m_hiddenPathText = pathHiddenTextObj.GetComponent<Text>();
m_hiddenPathText.color = Color.clear;
m_hiddenPathText.fontSize = 14;
m_hiddenPathText.lineSpacing = 1.5f;
//m_hiddenPathText.lineSpacing = 1.5f;
m_hiddenPathText.raycastTarget = false;
var hiddenFitter = pathHiddenTextObj.AddComponent<ContentSizeFitter>();
hiddenFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
@ -286,10 +286,10 @@ namespace UnityExplorer.Inspectors
hiddenGroup.childForceExpandHeight = true;
hiddenGroup.childControlHeight = true;
var pathInputObj = UIFactory.CreateTMPInput(pathHiddenTextObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var pathInputObj = UIFactory.CreateInputField(pathHiddenTextObj);
var pathInputRect = pathInputObj.GetComponent<RectTransform>();
pathInputRect.sizeDelta = new Vector2(pathInputRect.sizeDelta.x, 25);
m_pathInput = pathInputObj.GetComponent<TMP_InputField>();
m_pathInput = pathInputObj.GetComponent<InputField>();
m_pathInput.text = TargetGO.transform.GetTransformPath();
m_pathInput.readOnly = true;
var pathInputLayout = pathInputObj.AddComponent<LayoutElement>();
@ -301,7 +301,7 @@ namespace UnityExplorer.Inspectors
textRect.offsetMin = new Vector2(3, 3);
textRect.offsetMax = new Vector2(3, 3);
m_pathInput.textComponent.color = new Color(0.75f, 0.75f, 0.75f);
m_pathInput.textComponent.lineSpacing = 1.5f;
//m_pathInput.textComponent.lineSpacing = 1.5f;
m_pathInputRect = m_pathInput.GetComponent<RectTransform>();
m_hiddenPathRect = m_hiddenPathText.GetComponent<RectTransform>();
@ -321,8 +321,8 @@ namespace UnityExplorer.Inspectors
nameLayout.minHeight = 25;
nameLayout.flexibleHeight = 0;
var nameTextObj = UIFactory.CreateTMPLabel(nameRowObj, TextAlignmentOptions.Midline);
var nameTextText = nameTextObj.GetComponent<TextMeshProUGUI>();
var nameTextObj = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleCenter);
var nameTextText = nameTextObj.GetComponent<Text>();
nameTextText.text = "Name:";
nameTextText.fontSize = 14;
nameTextText.color = Color.grey;
@ -332,12 +332,12 @@ namespace UnityExplorer.Inspectors
nameTextLayout.minWidth = 55;
nameTextLayout.flexibleWidth = 0;
var nameInputObj = UIFactory.CreateTMPInput(nameRowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var nameInputObj = UIFactory.CreateInputField(nameRowObj);
var nameInputRect = nameInputObj.GetComponent<RectTransform>();
nameInputRect.sizeDelta = new Vector2(nameInputRect.sizeDelta.x, 25);
m_nameInput = nameInputObj.GetComponent<TMP_InputField>();
m_nameInput = nameInputObj.GetComponent<InputField>();
m_nameInput.text = TargetGO.name;
m_nameInput.lineType = TMP_InputField.LineType.SingleLine;
m_nameInput.lineType = InputField.LineType.SingleLine;
var applyNameBtnObj = UIFactory.CreateButton(nameRowObj);
var applyNameBtn = applyNameBtnObj.GetComponent<Button>();

View File

@ -4,7 +4,7 @@ using System.Linq;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
using UnityExplorer.UI.Shared;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Input;

View File

@ -5,7 +5,7 @@ using UnityExplorer.Helpers;
using UnityExplorer.UI;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Input;

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
using TMPro;
//using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Input;
@ -20,7 +20,7 @@ namespace UnityExplorer.Inspectors.GameObjects
Instance = this;
}
private static TMP_InputField s_setParentInput;
private static InputField s_setParentInput;
private static ControlEditor s_positionControl;
private static ControlEditor s_localPosControl;
@ -31,9 +31,9 @@ namespace UnityExplorer.Inspectors.GameObjects
internal struct ControlEditor
{
public TMP_InputField fullValue;
public InputField fullValue;
public Slider[] sliders;
public TMP_InputField[] inputs;
public InputField[] inputs;
public Text[] values;
}
@ -185,7 +185,7 @@ namespace UnityExplorer.Inspectors.GameObjects
// get relevant input for controltype + value
TMP_InputField[] inputs = null;
InputField[] inputs = null;
switch (controlType)
{
case ControlType.position:
@ -197,7 +197,7 @@ namespace UnityExplorer.Inspectors.GameObjects
case ControlType.localScale:
inputs = s_scaleControl.inputs; break;
}
TMP_InputField input = inputs[(int)vectorValue];
InputField input = inputs[(int)vectorValue];
float val = float.Parse(input.text);
@ -357,9 +357,9 @@ namespace UnityExplorer.Inspectors.GameObjects
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>();
var setParentInputObj = UIFactory.CreateInputField(setParentGroupObj);
s_setParentInput = setParentInputObj.GetComponent<InputField>();
var placeholderInput = s_setParentInput.placeholder.GetComponent<Text>();
placeholderInput.text = "Enter a GameObject name or path...";
var setParentInputLayout = setParentInputObj.AddComponent<LayoutElement>();
setParentInputLayout.minHeight = 25;
@ -421,11 +421,11 @@ namespace UnityExplorer.Inspectors.GameObjects
// readonly value input
var valueInputObj = UIFactory.CreateTMPInput(topBarObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var valueInput = valueInputObj.GetComponent<TMP_InputField>();
var valueInputObj = UIFactory.CreateInputField(topBarObj);
var valueInput = valueInputObj.GetComponent<InputField>();
valueInput.readOnly = true;
valueInput.richText = true;
valueInput.isRichTextEditingAllowed = true;
//valueInput.richText = true;
//valueInput.isRichTextEditingAllowed = true;
var valueInputLayout = valueInputObj.AddComponent<LayoutElement>();
valueInputLayout.minHeight = 25;
valueInputLayout.flexibleHeight = 0;
@ -435,7 +435,7 @@ namespace UnityExplorer.Inspectors.GameObjects
editor.fullValue = valueInput;
editor.sliders = new Slider[3];
editor.inputs = new TMP_InputField[3];
editor.inputs = new InputField[3];
editor.values = new Text[3];
var xRow = ConstructEditorRow(parent, editor, type, VectorValue.x);
@ -540,9 +540,9 @@ namespace UnityExplorer.Inspectors.GameObjects
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 inputObj = UIFactory.CreateInputField(inputHolder);
var input = inputObj.GetComponent<InputField>();
input.characterValidation = InputField.CharacterValidation.Decimal;
var inputLayout = inputObj.AddComponent<LayoutElement>();
inputLayout.minHeight = 25;

View File

@ -7,7 +7,7 @@ using UnityExplorer.UI.PageModel;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using TMPro;
//using TMPro;
using UnityExplorer.Inspectors.Reflection;
namespace UnityExplorer.Inspectors
@ -277,9 +277,9 @@ namespace UnityExplorer.Inspectors
// 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 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;

View File

@ -54,12 +54,22 @@ namespace UnityExplorer.Inspectors.Reflection
{
var pType = param.ParameterType;
if (pType.IsByRef && pType.HasElementType)
if (pType.IsByRef && !pType.IsPrimitive && pType != typeof(string))
{
pType = pType.GetElementType();
if (pType.IsArray || pType.Name.Contains("Array"))
return false;
try
{
pType = pType.GetElementType();
}
catch
{
return false;
}
}
if (pType.IsPrimitive || pType == typeof(string))
if (pType != null && (pType.IsPrimitive || pType == typeof(string)))
{
continue;
}

View File

@ -172,7 +172,7 @@ namespace UnityExplorer.Inspectors.Reflection
}
else if (MemInfo is PropertyInfo pi)
{
if (pi.GetAccessors()[0].IsStatic)
if (pi.GetAccessors(true)[0].IsStatic)
{
isStatic = true;
memberColor = SyntaxColors.Prop_Static;

View File

@ -9,7 +9,7 @@ using UnityExplorer.UI.Shared;
using System.Reflection;
using UnityExplorer.UI;
using UnityEngine.UI;
using TMPro;
//using TMPro;
namespace UnityExplorer.Inspectors
{
@ -23,9 +23,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 CacheMember[] m_membersShortlist;
// UI members
@ -36,16 +36,20 @@ namespace UnityExplorer.Inspectors
set => m_content = value;
}
internal PageHandler m_pageHandler;
//internal PageHandler m_pageHandler;
// Blacklists
private static readonly HashSet<string> s_typeAndMemberBlacklist = new HashSet<string>
{
// these cause a crash
"Type.DeclaringMethod",
"Rigidbody2D.Cast",
"Collider2D.Cast",
"Collider2D.Raycast",
};
private static readonly HashSet<string> s_methodStartsWithBlacklist = new HashSet<string>
{
// these are redundant
"get_",
"set_",
};
@ -136,7 +140,8 @@ namespace UnityExplorer.Inspectors
// check blacklisted members
var sig = $"{member.DeclaringType.Name}.{member.Name}";
if (s_typeAndMemberBlacklist.Any(it => it == sig))
if (s_typeAndMemberBlacklist.Any(it => sig.Contains(it)))
continue;
if (s_methodStartsWithBlacklist.Any(it => member.Name.StartsWith(it)))
@ -144,7 +149,14 @@ namespace UnityExplorer.Inspectors
if (mi != null)
{
AppendParams(mi.GetParameters());
try
{
AppendParams(mi.GetParameters());
}
catch (Exception e)
{
ExplorerCore.Log(e);
}
}
else if (pi != null)
{
@ -194,7 +206,7 @@ namespace UnityExplorer.Inspectors
m_allMembers = list.ToArray();
ExplorerCore.Log("Cached " + m_allMembers.Length + " members");
// ExplorerCore.Log("Cached " + m_allMembers.Length + " members");
}
#region UI CONSTRUCTION
@ -243,8 +255,8 @@ namespace UnityExplorer.Inspectors
typeLabelTextLayout.flexibleWidth = 0;
typeLabelTextLayout.minHeight = 25;
var typeLabelInputObj = UIFactory.CreateTMPInput(typeRowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var typeLabelInput = typeLabelInputObj.GetComponent<TMP_InputField>();
var typeLabelInputObj = UIFactory.CreateInputField(typeRowObj);
var typeLabelInput = typeLabelInputObj.GetComponent<InputField>();
typeLabelInput.readOnly = true;
var typeLabelLayout = typeLabelInputObj.AddComponent<LayoutElement>();
typeLabelLayout.minWidth = 150;