mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
finishing off interactive values
This commit is contained in:
parent
7920c54761
commit
8e2e2abef4
@ -45,25 +45,110 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
|
|
||||||
public void ConstructInstanceHelpers()
|
public void ConstructInstanceHelpers()
|
||||||
{
|
{
|
||||||
// On second thought, I'm not sure about this, seems unnecessary (and bloaty)
|
// WIP
|
||||||
// I might do the Texture2D helper (view/save image) but idk about anything else.
|
|
||||||
|
//if (m_targetType == typeof(Texture2D))
|
||||||
|
// ConstructTextureHelper();
|
||||||
|
|
||||||
|
// todo other helpers
|
||||||
|
|
||||||
//if (typeof(Component).IsAssignableFrom(m_targetType))
|
//if (typeof(Component).IsAssignableFrom(m_targetType))
|
||||||
//{
|
//{
|
||||||
// // component helpers (ref GO)
|
|
||||||
// var tempObj = UIFactory.CreateLabel(Content, TextAnchor.MiddleLeft);
|
|
||||||
// var text = tempObj.GetComponent<Text>();
|
|
||||||
// text.text = "TODO comp helpers";
|
|
||||||
//}
|
//}
|
||||||
//else if (typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
|
//else if (typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
|
||||||
//{
|
//{
|
||||||
// // unityengine.object helpers (name, instantiate, destroy?)
|
|
||||||
// var tempObj = UIFactory.CreateLabel(Content, TextAnchor.MiddleLeft);
|
|
||||||
// var text = tempObj.GetComponent<Text>();
|
|
||||||
// text.text = "TODO unity object helpers";
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//internal bool showingTextureHelper;
|
||||||
|
//internal bool constructedTextureViewer;
|
||||||
|
|
||||||
|
//internal void ConstructTextureHelper()
|
||||||
|
//{
|
||||||
|
// var rowObj = UIFactory.CreateHorizontalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
// var rowLayout = rowObj.AddComponent<LayoutElement>();
|
||||||
|
// rowLayout.minHeight = 25;
|
||||||
|
// rowLayout.flexibleHeight = 0;
|
||||||
|
// var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
// rowGroup.childForceExpandHeight = true;
|
||||||
|
// rowGroup.childForceExpandWidth = false;
|
||||||
|
// rowGroup.padding.top = 3;
|
||||||
|
// rowGroup.padding.left = 3;
|
||||||
|
// rowGroup.padding.bottom = 3;
|
||||||
|
// rowGroup.padding.right = 3;
|
||||||
|
// rowGroup.spacing = 5;
|
||||||
|
|
||||||
|
// var showBtnObj = UIFactory.CreateButton(rowObj, new Color(0.2f, 0.2f, 0.2f));
|
||||||
|
// var showBtnLayout = showBtnObj.AddComponent<LayoutElement>();
|
||||||
|
// showBtnLayout.minWidth = 50;
|
||||||
|
// showBtnLayout.flexibleWidth = 0;
|
||||||
|
// var showText = showBtnObj.GetComponentInChildren<Text>();
|
||||||
|
// showText.text = "Show";
|
||||||
|
// var showBtn = showBtnObj.GetComponent<Button>();
|
||||||
|
|
||||||
|
// var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||||
|
// var labelText = labelObj.GetComponent<Text>();
|
||||||
|
// labelText.text = "Texture Viewer";
|
||||||
|
|
||||||
|
// var textureViewerObj = UIFactory.CreateScrollView(Content, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
|
||||||
|
// var viewerGroup = scrollContent.GetComponent<VerticalLayoutGroup>();
|
||||||
|
// viewerGroup.childForceExpandHeight = false;
|
||||||
|
// viewerGroup.childForceExpandWidth = false;
|
||||||
|
// viewerGroup.childControlHeight = true;
|
||||||
|
// viewerGroup.childControlWidth = true;
|
||||||
|
// var mainLayout = textureViewerObj.GetComponent<LayoutElement>();
|
||||||
|
// mainLayout.flexibleHeight = -1;
|
||||||
|
// mainLayout.flexibleWidth = 2000;
|
||||||
|
// mainLayout.minHeight = 25;
|
||||||
|
|
||||||
|
// textureViewerObj.SetActive(false);
|
||||||
|
|
||||||
|
// showBtn.onClick.AddListener(() =>
|
||||||
|
// {
|
||||||
|
// showingTextureHelper = !showingTextureHelper;
|
||||||
|
|
||||||
|
// if (showingTextureHelper)
|
||||||
|
// {
|
||||||
|
// if (!constructedTextureViewer)
|
||||||
|
// ConstructTextureViewerArea(scrollContent);
|
||||||
|
|
||||||
|
// showText.text = "Hide";
|
||||||
|
// textureViewerObj.SetActive(true);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// showText.text = "Show";
|
||||||
|
// textureViewerObj.SetActive(false);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
|
//internal void ConstructTextureViewerArea(GameObject parent)
|
||||||
|
//{
|
||||||
|
// constructedTextureViewer = true;
|
||||||
|
|
||||||
|
// var tex = Target as Texture2D;
|
||||||
|
|
||||||
|
// if (!tex)
|
||||||
|
// {
|
||||||
|
// ExplorerCore.LogWarning("Could not cast the target instance to Texture2D!");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var imageObj = UIFactory.CreateUIObject("TextureViewerImage", parent, new Vector2(1, 1));
|
||||||
|
// var image = imageObj.AddComponent<Image>();
|
||||||
|
// var sprite = UIManager.CreateSprite(tex);
|
||||||
|
// image.sprite = sprite;
|
||||||
|
|
||||||
|
// var fitter = imageObj.AddComponent<ContentSizeFitter>();
|
||||||
|
// fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||||
|
// //fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||||
|
|
||||||
|
// var imageLayout = imageObj.AddComponent<LayoutElement>();
|
||||||
|
// imageLayout.preferredHeight = sprite.rect.height;
|
||||||
|
// imageLayout.preferredWidth = sprite.rect.width;
|
||||||
|
//}
|
||||||
|
|
||||||
public void ConstructInstanceFilters(GameObject parent)
|
public void ConstructInstanceFilters(GameObject parent)
|
||||||
{
|
{
|
||||||
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||||
|
@ -24,10 +24,29 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
|
|
||||||
internal KeyValuePair<int,string>[] m_values = new KeyValuePair<int, string>[0];
|
internal KeyValuePair<int,string>[] m_values = new KeyValuePair<int, string>[0];
|
||||||
|
|
||||||
|
internal Type m_lastEnumType;
|
||||||
|
|
||||||
internal void GetNames()
|
internal void GetNames()
|
||||||
{
|
{
|
||||||
var type = Value?.GetType() ?? FallbackType;
|
var type = Value?.GetType() ?? FallbackType;
|
||||||
|
|
||||||
|
if (m_lastEnumType == type)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_lastEnumType = type;
|
||||||
|
|
||||||
|
if (m_subContentConstructed)
|
||||||
|
{
|
||||||
|
// changing types, destroy subcontent
|
||||||
|
for (int i = 0; i < m_subContentParent.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
var child = m_subContentParent.transform.GetChild(i);
|
||||||
|
GameObject.Destroy(child.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_subContentConstructed = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!s_enumNamesCache.ContainsKey(type))
|
if (!s_enumNamesCache.ContainsKey(type))
|
||||||
{
|
{
|
||||||
// using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags)
|
// using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags)
|
||||||
@ -52,6 +71,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
|
|
||||||
public override void OnValueUpdated()
|
public override void OnValueUpdated()
|
||||||
{
|
{
|
||||||
|
GetNames();
|
||||||
|
|
||||||
base.OnValueUpdated();
|
base.OnValueUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
|
|
||||||
public override void RefreshUIForValue()
|
public override void RefreshUIForValue()
|
||||||
{
|
{
|
||||||
//base.RefreshUIForValue();
|
|
||||||
|
|
||||||
GetDefaultLabel();
|
GetDefaultLabel();
|
||||||
m_baseLabel.text = DefaultLabel;
|
m_baseLabel.text = DefaultLabel;
|
||||||
|
|
||||||
|
@ -198,6 +198,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
|
|
||||||
public override void RefreshUIForValue()
|
public override void RefreshUIForValue()
|
||||||
{
|
{
|
||||||
|
InitializeStructInfo();
|
||||||
|
|
||||||
base.RefreshUIForValue();
|
base.RefreshUIForValue();
|
||||||
|
|
||||||
if (m_subContentConstructed)
|
if (m_subContentConstructed)
|
||||||
@ -213,8 +215,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region STRUCT INFO HANDLERS
|
|
||||||
|
|
||||||
internal Type m_lastStructType;
|
internal Type m_lastStructType;
|
||||||
|
|
||||||
internal void InitializeStructInfo()
|
internal void InitializeStructInfo()
|
||||||
@ -232,14 +232,19 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
var child = m_subContentParent.transform.GetChild(i);
|
var child = m_subContentParent.transform.GetChild(i);
|
||||||
GameObject.Destroy(child.gameObject);
|
GameObject.Destroy(child.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_UIConstructed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lastStructType = type;
|
m_lastStructType = type;
|
||||||
|
|
||||||
StructInfo = StructInfoFactory.Create(type);
|
StructInfo = StructInfoFactory.Create(type);
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
if (m_subContentParent.activeSelf)
|
||||||
|
{
|
||||||
|
ConstructSubcontent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region UI CONSTRUCTION
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
{
|
{
|
||||||
public class InteractiveValue
|
public class InteractiveValue
|
||||||
{
|
{
|
||||||
// WIP
|
|
||||||
public static Type GetIValueForType(Type type)
|
public static Type GetIValueForType(Type type)
|
||||||
{
|
{
|
||||||
if (type == typeof(bool))
|
if (type == typeof(bool))
|
||||||
@ -69,9 +68,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
internal string m_defaultLabel;
|
internal string m_defaultLabel;
|
||||||
internal string m_richValueType;
|
internal string m_richValueType;
|
||||||
|
|
||||||
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
|
||||||
internal MethodInfo m_toStringMethod;
|
|
||||||
|
|
||||||
public bool m_UIConstructed;
|
public bool m_UIConstructed;
|
||||||
|
|
||||||
public virtual void OnDestroy()
|
public virtual void OnDestroy()
|
||||||
@ -203,7 +199,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var toString = (string)ToStringMethod.Invoke(Value, null);
|
var toString = (string)valueType.GetMethod("ToString", new Type[0])?.Invoke(Value, null)
|
||||||
|
?? Value.ToString();
|
||||||
|
|
||||||
var fullnametemp = valueType.ToString();
|
var fullnametemp = valueType.ToString();
|
||||||
if (fullnametemp.StartsWith("Il2CppSystem"))
|
if (fullnametemp.StartsWith("Il2CppSystem"))
|
||||||
@ -233,23 +230,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
|||||||
return m_defaultLabel = label;
|
return m_defaultLabel = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodInfo GetToStringMethod()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_toStringMethod = ReflectionHelpers.GetActualType(Value).GetMethod("ToString", new Type[0])
|
|
||||||
?? typeof(object).GetMethod("ToString", new Type[0]);
|
|
||||||
|
|
||||||
// test invoke
|
|
||||||
m_toStringMethod.Invoke(Value, null);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
|
|
||||||
}
|
|
||||||
return m_toStringMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region UI CONSTRUCTION
|
#region UI CONSTRUCTION
|
||||||
|
|
||||||
internal GameObject m_mainContentParent;
|
internal GameObject m_mainContentParent;
|
||||||
|
@ -134,7 +134,7 @@ namespace UnityExplorer.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if CPP
|
#if CPP
|
||||||
TestTexture = UIManager.MakeSolidTexture(Color.white, 200, 200);
|
TestTexture = UIManager.MakeSolidTexture(Color.white, 1000, 600);
|
||||||
TestTexture.name = "TestTexture";
|
TestTexture.name = "TestTexture";
|
||||||
|
|
||||||
var r = new Rect(0, 0, TestTexture.width, TestTexture.height);
|
var r = new Rect(0, 0, TestTexture.width, TestTexture.height);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user