Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 8e2e2ab

Browse files
committed
finishing off interactive values
1 parent 7920c54 commit 8e2e2ab

File tree

6 files changed

+128
-39
lines changed

6 files changed

+128
-39
lines changed

src/Inspectors/Reflection/InstanceInspector.cs

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,110 @@ private void OnScopeFilterClicked(MemberScopes type, Button button)
4545

4646
public void ConstructInstanceHelpers()
4747
{
48-
// On second thought, I'm not sure about this, seems unnecessary (and bloaty)
49-
// I might do the Texture2D helper (view/save image) but idk about anything else.
48+
// WIP
49+
50+
//if (m_targetType == typeof(Texture2D))
51+
// ConstructTextureHelper();
52+
53+
// todo other helpers
5054

5155
//if (typeof(Component).IsAssignableFrom(m_targetType))
5256
//{
53-
// // component helpers (ref GO)
54-
// var tempObj = UIFactory.CreateLabel(Content, TextAnchor.MiddleLeft);
55-
// var text = tempObj.GetComponent<Text>();
56-
// text.text = "TODO comp helpers";
5757
//}
5858
//else if (typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
5959
//{
60-
// // unityengine.object helpers (name, instantiate, destroy?)
61-
// var tempObj = UIFactory.CreateLabel(Content, TextAnchor.MiddleLeft);
62-
// var text = tempObj.GetComponent<Text>();
63-
// text.text = "TODO unity object helpers";
6460
//}
6561
}
6662

63+
//internal bool showingTextureHelper;
64+
//internal bool constructedTextureViewer;
65+
66+
//internal void ConstructTextureHelper()
67+
//{
68+
// var rowObj = UIFactory.CreateHorizontalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
69+
// var rowLayout = rowObj.AddComponent<LayoutElement>();
70+
// rowLayout.minHeight = 25;
71+
// rowLayout.flexibleHeight = 0;
72+
// var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
73+
// rowGroup.childForceExpandHeight = true;
74+
// rowGroup.childForceExpandWidth = false;
75+
// rowGroup.padding.top = 3;
76+
// rowGroup.padding.left = 3;
77+
// rowGroup.padding.bottom = 3;
78+
// rowGroup.padding.right = 3;
79+
// rowGroup.spacing = 5;
80+
81+
// var showBtnObj = UIFactory.CreateButton(rowObj, new Color(0.2f, 0.2f, 0.2f));
82+
// var showBtnLayout = showBtnObj.AddComponent<LayoutElement>();
83+
// showBtnLayout.minWidth = 50;
84+
// showBtnLayout.flexibleWidth = 0;
85+
// var showText = showBtnObj.GetComponentInChildren<Text>();
86+
// showText.text = "Show";
87+
// var showBtn = showBtnObj.GetComponent<Button>();
88+
89+
// var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
90+
// var labelText = labelObj.GetComponent<Text>();
91+
// labelText.text = "Texture Viewer";
92+
93+
// var textureViewerObj = UIFactory.CreateScrollView(Content, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
94+
// var viewerGroup = scrollContent.GetComponent<VerticalLayoutGroup>();
95+
// viewerGroup.childForceExpandHeight = false;
96+
// viewerGroup.childForceExpandWidth = false;
97+
// viewerGroup.childControlHeight = true;
98+
// viewerGroup.childControlWidth = true;
99+
// var mainLayout = textureViewerObj.GetComponent<LayoutElement>();
100+
// mainLayout.flexibleHeight = -1;
101+
// mainLayout.flexibleWidth = 2000;
102+
// mainLayout.minHeight = 25;
103+
104+
// textureViewerObj.SetActive(false);
105+
106+
// showBtn.onClick.AddListener(() =>
107+
// {
108+
// showingTextureHelper = !showingTextureHelper;
109+
110+
// if (showingTextureHelper)
111+
// {
112+
// if (!constructedTextureViewer)
113+
// ConstructTextureViewerArea(scrollContent);
114+
115+
// showText.text = "Hide";
116+
// textureViewerObj.SetActive(true);
117+
// }
118+
// else
119+
// {
120+
// showText.text = "Show";
121+
// textureViewerObj.SetActive(false);
122+
// }
123+
// });
124+
//}
125+
126+
//internal void ConstructTextureViewerArea(GameObject parent)
127+
//{
128+
// constructedTextureViewer = true;
129+
130+
// var tex = Target as Texture2D;
131+
132+
// if (!tex)
133+
// {
134+
// ExplorerCore.LogWarning("Could not cast the target instance to Texture2D!");
135+
// return;
136+
// }
137+
138+
// var imageObj = UIFactory.CreateUIObject("TextureViewerImage", parent, new Vector2(1, 1));
139+
// var image = imageObj.AddComponent<Image>();
140+
// var sprite = UIManager.CreateSprite(tex);
141+
// image.sprite = sprite;
142+
143+
// var fitter = imageObj.AddComponent<ContentSizeFitter>();
144+
// fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
145+
// //fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
146+
147+
// var imageLayout = imageObj.AddComponent<LayoutElement>();
148+
// imageLayout.preferredHeight = sprite.rect.height;
149+
// imageLayout.preferredWidth = sprite.rect.width;
150+
//}
151+
67152
public void ConstructInstanceFilters(GameObject parent)
68153
{
69154
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));

src/Inspectors/Reflection/InteractiveValue/InteractiveEnum.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,29 @@ public InteractiveEnum(object value, Type valueType) : base(value, valueType)
2424

2525
internal KeyValuePair<int,string>[] m_values = new KeyValuePair<int, string>[0];
2626

27+
internal Type m_lastEnumType;
28+
2729
internal void GetNames()
2830
{
2931
var type = Value?.GetType() ?? FallbackType;
3032

33+
if (m_lastEnumType == type)
34+
return;
35+
36+
m_lastEnumType = type;
37+
38+
if (m_subContentConstructed)
39+
{
40+
// changing types, destroy subcontent
41+
for (int i = 0; i < m_subContentParent.transform.childCount; i++)
42+
{
43+
var child = m_subContentParent.transform.GetChild(i);
44+
GameObject.Destroy(child.gameObject);
45+
}
46+
47+
m_subContentConstructed = false;
48+
}
49+
3150
if (!s_enumNamesCache.ContainsKey(type))
3251
{
3352
// using GetValues not GetNames, to catch instances of weird enums (eg CameraClearFlags)
@@ -52,6 +71,8 @@ internal void GetNames()
5271

5372
public override void OnValueUpdated()
5473
{
74+
GetNames();
75+
5576
base.OnValueUpdated();
5677
}
5778

src/Inspectors/Reflection/InteractiveValue/InteractiveFlags.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public override void OnValueUpdated()
4545

4646
public override void RefreshUIForValue()
4747
{
48-
//base.RefreshUIForValue();
49-
5048
GetDefaultLabel();
5149
m_baseLabel.text = DefaultLabel;
5250

src/Inspectors/Reflection/InteractiveValue/InteractiveUnityStruct.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public InteractiveUnityStruct(object value, Type valueType) : base(value, valueT
198198

199199
public override void RefreshUIForValue()
200200
{
201+
InitializeStructInfo();
202+
201203
base.RefreshUIForValue();
202204

203205
if (m_subContentConstructed)
@@ -213,8 +215,6 @@ internal override void OnToggleSubcontent(bool toggle)
213215
StructInfo.RefreshUI(m_inputs, this.Value);
214216
}
215217

216-
#region STRUCT INFO HANDLERS
217-
218218
internal Type m_lastStructType;
219219

220220
internal void InitializeStructInfo()
@@ -232,14 +232,19 @@ internal void InitializeStructInfo()
232232
var child = m_subContentParent.transform.GetChild(i);
233233
GameObject.Destroy(child.gameObject);
234234
}
235+
236+
m_UIConstructed = false;
235237
}
236238

237239
m_lastStructType = type;
238240

239241
StructInfo = StructInfoFactory.Create(type);
240-
}
241242

242-
#endregion
243+
if (m_subContentParent.activeSelf)
244+
{
245+
ConstructSubcontent();
246+
}
247+
}
243248

244249
#region UI CONSTRUCTION
245250

src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace UnityExplorer.Inspectors.Reflection
1212
{
1313
public class InteractiveValue
1414
{
15-
// WIP
1615
public static Type GetIValueForType(Type type)
1716
{
1817
if (type == typeof(bool))
@@ -69,9 +68,6 @@ public InteractiveValue(object value, Type valueType)
6968
internal string m_defaultLabel;
7069
internal string m_richValueType;
7170

72-
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
73-
internal MethodInfo m_toStringMethod;
74-
7571
public bool m_UIConstructed;
7672

7773
public virtual void OnDestroy()
@@ -203,7 +199,8 @@ public string GetDefaultLabel(bool updateType = true)
203199
}
204200
else
205201
{
206-
var toString = (string)ToStringMethod.Invoke(Value, null);
202+
var toString = (string)valueType.GetMethod("ToString", new Type[0])?.Invoke(Value, null)
203+
?? Value.ToString();
207204

208205
var fullnametemp = valueType.ToString();
209206
if (fullnametemp.StartsWith("Il2CppSystem"))
@@ -233,23 +230,6 @@ public string GetDefaultLabel(bool updateType = true)
233230
return m_defaultLabel = label;
234231
}
235232

236-
private MethodInfo GetToStringMethod()
237-
{
238-
try
239-
{
240-
m_toStringMethod = ReflectionHelpers.GetActualType(Value).GetMethod("ToString", new Type[0])
241-
?? typeof(object).GetMethod("ToString", new Type[0]);
242-
243-
// test invoke
244-
m_toStringMethod.Invoke(Value, null);
245-
}
246-
catch
247-
{
248-
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
249-
}
250-
return m_toStringMethod;
251-
}
252-
253233
#region UI CONSTRUCTION
254234

255235
internal GameObject m_mainContentParent;

src/Tests/Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public TestClass()
134134
}
135135

136136
#if CPP
137-
TestTexture = UIManager.MakeSolidTexture(Color.white, 200, 200);
137+
TestTexture = UIManager.MakeSolidTexture(Color.white, 1000, 600);
138138
TestTexture.name = "TestTexture";
139139

140140
var r = new Rect(0, 0, TestTexture.width, TestTexture.height);

0 commit comments

Comments
 (0)