mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-04 00:23:31 +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()
|
||||
{
|
||||
// On second thought, I'm not sure about this, seems unnecessary (and bloaty)
|
||||
// I might do the Texture2D helper (view/save image) but idk about anything else.
|
||||
// WIP
|
||||
|
||||
//if (m_targetType == typeof(Texture2D))
|
||||
// ConstructTextureHelper();
|
||||
|
||||
// todo other helpers
|
||||
|
||||
//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))
|
||||
//{
|
||||
// // 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)
|
||||
{
|
||||
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 Type m_lastEnumType;
|
||||
|
||||
internal void GetNames()
|
||||
{
|
||||
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))
|
||||
{
|
||||
// using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags)
|
||||
@ -52,6 +71,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
GetNames();
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
//base.RefreshUIForValue();
|
||||
|
||||
GetDefaultLabel();
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
|
||||
|
@ -198,6 +198,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
@ -213,8 +215,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
#region STRUCT INFO HANDLERS
|
||||
|
||||
internal Type m_lastStructType;
|
||||
|
||||
internal void InitializeStructInfo()
|
||||
@ -232,14 +232,19 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
var child = m_subContentParent.transform.GetChild(i);
|
||||
GameObject.Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
m_UIConstructed = false;
|
||||
}
|
||||
|
||||
m_lastStructType = type;
|
||||
|
||||
StructInfo = StructInfoFactory.Create(type);
|
||||
}
|
||||
|
||||
#endregion
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
ConstructSubcontent();
|
||||
}
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
|
@ -12,7 +12,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
{
|
||||
public class InteractiveValue
|
||||
{
|
||||
// WIP
|
||||
public static Type GetIValueForType(Type type)
|
||||
{
|
||||
if (type == typeof(bool))
|
||||
@ -69,9 +68,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
internal string m_defaultLabel;
|
||||
internal string m_richValueType;
|
||||
|
||||
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
||||
internal MethodInfo m_toStringMethod;
|
||||
|
||||
public bool m_UIConstructed;
|
||||
|
||||
public virtual void OnDestroy()
|
||||
@ -203,7 +199,8 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
}
|
||||
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();
|
||||
if (fullnametemp.StartsWith("Il2CppSystem"))
|
||||
@ -233,23 +230,6 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
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
|
||||
|
||||
internal GameObject m_mainContentParent;
|
||||
|
@ -134,7 +134,7 @@ namespace UnityExplorer.Tests
|
||||
}
|
||||
|
||||
#if CPP
|
||||
TestTexture = UIManager.MakeSolidTexture(Color.white, 200, 200);
|
||||
TestTexture = UIManager.MakeSolidTexture(Color.white, 1000, 600);
|
||||
TestTexture.name = "TestTexture";
|
||||
|
||||
var r = new Rect(0, 0, TestTexture.width, TestTexture.height);
|
||||
|
Loading…
x
Reference in New Issue
Block a user