-
Notifications
You must be signed in to change notification settings - Fork 3
/
IwsdSubInspectorWindow.cs
859 lines (715 loc) · 29.3 KB
/
IwsdSubInspectorWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
/*
* Iwsd / Sub Inspector
*
* By naqtn (https://twitter.com/naqtn)
* Hosted at https://github.com/naqtn/ProgrammingInVRChat
*
*/
using UnityEngine;
using System;
using System.Collections;
using System.Reflection;
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
namespace Iwsd
{
public class IwsdSubInspectorWindow : EditorWindow
{
[MenuItem("Window/VRC_Iwsd/Open Sub Inspector")]
static void OpenIwsdSubInspectorWindow()
{
EditorWindow.GetWindow<IwsdSubInspectorWindow>("Sub Inspector");
}
void OnInspectorUpdate()
{
Repaint();
}
string lastMessageString;
MessageType lastMessageType = MessageType.None;
int lastInstanceId;
Vector2 scrollPosition = new Vector2(0, 0);
void OnGUI ()
{
var assets = Selection.assetGUIDs;
for (int i = 0; i < assets.Length; i++)
{
//Debug.LogError("assets[" + i + "]='" + assets[i] + "'");
var path = AssetDatabase.GUIDToAssetPath(assets[i]);
//Debug.LogError(" path='" + path + "'");
}
// ref:2224:VRCSDK/Dependencies/VRChat/VRCSDK2.dll
var active = Selection.activeGameObject;
if (active == null)
{
return;
}
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
EditorGUILayout.LabelField("Iwsd Sub Inspector", new GUIStyle(){fontStyle = FontStyle.Bold});
// CHECK ExecuteInEditMode attribute and Update
if ((active.GetInstanceID() != lastInstanceId) || CheckComponentAlignmentChanged(active))
{
lastInstanceId = active.GetInstanceID();
lastMessageString = null;
ReplaceEditors(active);
}
DrawGUI(active);
EditorGUILayout.EndScrollView();
}
private void DrawGUI(GameObject active)
{
if (lastMessageString != null)
{
EditorGUILayout.HelpBox(lastMessageString, lastMessageType);
EditorGUILayout.Space();
}
EditorGUILayout.LabelField("Selected object path: (read only)");
EditorGUILayout.TextField(GetGameObjectPath(active));
// EditorGUILayout.SelectableLabel(GetGameObjectPath(active));
EditorGUILayout.Space();
HideFlagsEdit(active);
DispatchOnGUI();
}
// NOTE: https://forum.unity.com/threads/is-it-possible-to-fold-a-component-from-script-inspector-view.296333/
// UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded
// HideFlags
// http://tsubakit1.hateblo.jp/entry/20140422/1398177224
bool HideFlagsEditShow = false;
private void HideFlagsEdit(GameObject active)
{
HideFlagsEditShow = EditorGUILayout.Foldout(HideFlagsEditShow, "Inspector Edit Protection", true);
if (HideFlagsEditShow)
{
// Undo.RecordObject seems not to work for hideFlags.
bool changed = false;
EditorGUI.indentLevel++;
var cur = IsNotEditable(active);
var sel = EditorGUILayout.ToggleLeft("whole GameObject", cur);
if (cur != sel)
{
SetNotEditable(active, sel);
changed = true;
}
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(sel);
foreach (Component comp in active.GetComponents<Component>())
{
cur = IsNotEditable(comp);
sel = EditorGUILayout.ToggleLeft(comp.GetType().Name, cur);
if (cur != sel)
{
SetNotEditable(comp, sel);
changed = true;
}
}
EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
if (changed)
{
// Force Inspector redraw
// https://answers.unity.com/questions/333181/how-do-you-force-a-custom-inspector-to-redraw.html
EditorUtility.SetDirty(active);
}
}
}
private static bool IsNotEditable(UnityEngine.Object obj)
{
return (obj.hideFlags & HideFlags.NotEditable) == HideFlags.NotEditable;
}
private static void SetNotEditable(UnityEngine.Object obj, bool b)
{
if (b)
{
obj.hideFlags |= HideFlags.NotEditable;
}
else
{
obj.hideFlags &= ~HideFlags.NotEditable;
}
}
////////////////////////////////////////////////////////////
// REFINE move to utility class
internal static string GetGameObjectPath(GameObject anObject)
{
var buf = new System.Text.StringBuilder();
GetGameObjectPathSub(anObject.transform, buf);
return buf.ToString();
}
private static void GetGameObjectPathSub(Transform transform, System.Text.StringBuilder buf)
{
if (transform.parent != null)
{
GetGameObjectPathSub(transform.parent, buf);
}
buf.Append('/');
buf.Append(transform.name);
}
////////////////////////////////////////////////////////////
// "Inspector"
// Component to Editor map
// Key is full name of type string. It's not `System.Type`. This design is for supporting non public type (ex VRC_Panorama)
static private Dictionary<string, List<Type>> EditorRegistry;
static IwsdSubInspectorWindow()
{
EditorRegistry = new Dictionary<string, List<Type>>();
// TODO gather implementation classes via custom attributes
RegisterEditor("UnityEngine.UI.Button", typeof(ButtonUnityEventOrderEditor));
RegisterEditor("UnityEngine.UI.InputField", typeof(InputFieldOnValueChangedUnityEventOrderEditor));
RegisterEditor("UnityEngine.UI.InputField", typeof(InputFieldOnEndEditUnityEventOrderEditor));
RegisterEditor("VRCSDK2.VRC_Trigger", typeof(VRC_TriggerOrderEditor));
RegisterEditor("VRCSDK2.VRC_Trigger", typeof(VRC_TriggerCopyPasteEditor));
// RegisterEditor("VRCSDK2.scripts.Scenes.VRC_Panorama", typeof(VRC_PanoramaSimpleEditor)});
RegisterEditor("VRCSDK2.scripts.Scenes.VRC_Panorama", typeof(VRC_PanoramaOrderEditor));
RegisterEditor("UnityEngine.TextMesh", typeof(TextMeshTextEditor));
}
public static void RegisterEditor(string typeFullName, Type editorType)
{
if (!EditorRegistry.ContainsKey(typeFullName))
{
EditorRegistry.Add(typeFullName, new List<Type>());
}
EditorRegistry[typeFullName].Add(editorType);
}
List<int> ComponentIds = new List<int>();
List<Editor> EditorInstances = new List<Editor>();
private bool CheckComponentAlignmentChanged(GameObject anObject)
{
int idx = 0;
foreach (var compObj in anObject.GetComponents<Component>())
{
var compType = compObj.GetType();
if (EditorRegistry.ContainsKey(compType.FullName))
{
// for each supported component
if ((ComponentIds.Count <= idx ) || (ComponentIds[idx++] != compObj.GetInstanceID()))
{
return true;
}
}
}
return false;
}
// active object to inspect changed
private void ReplaceEditors(GameObject anObject)
{
foreach (var editor in EditorInstances)
{
InvokeMethod(editor, "OnDisable");
}
EditorInstances.Clear();
ComponentIds.Clear();
foreach (var compObj in anObject.GetComponents<Component>())
{
var compTypeName = compObj.GetType().FullName;
if (EditorRegistry.ContainsKey(compTypeName))
{
InstantiateIwsdEditors(compTypeName, compObj);
ComponentIds.Add(compObj.GetInstanceID());
}
}
}
private void InstantiateIwsdEditors(string compTypeName, Component compObj)
{
List<Type> editorTypes = EditorRegistry[compTypeName];
foreach (var t in editorTypes)
{
InstantiateIwsdEditor(t, compObj);
}
}
private void InstantiateIwsdEditor(Type editorType, Component compObj)
{
// ScriptableObject instance = ScriptableObject.CreateInstance(editorType);
// MEMO CreateInstance calls OnEnable on instantiation.
// It's not too early for this inspector emulation.
var ctor = editorType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[]{}, null);
if (ctor == null)
{
Debug.LogError("Not found constructor. type=" + editorType);
return;
}
// CHECK this implementation supports non public class ?
object instance = ctor.Invoke(new object[]{});
if (instance == null)
{
Debug.LogError("Faild to create instance. type=" + editorType);
return;
}
Editor theEditor = instance as Editor;
if (theEditor == null)
{
Debug.LogError("Invalid editor class registration. type=" + editorType + ", type of instance=" + instance.GetType());
Debug.LogError(" expect subclass of type=" + typeof(Editor));
Debug.LogError(" hum," + (instance is Editor));
return;
}
theEditor.Initialize(compObj);
InvokeMethod(theEditor, "OnEnable");
EditorInstances.Add(theEditor);
}
private void DispatchOnGUI()
{
EditorGUILayout.BeginVertical(new GUIStyle(){margin = new RectOffset(){left=10,right=5,top=5}});
foreach (var editor in EditorInstances)
{
editor.OnInspectorGUI();
EditorGUILayout.Space();
}
EditorGUILayout.EndVertical();
}
private object InvokeMethod(object anObject, string methodName)
{
Type type = anObject.GetType();
MethodInfo minfo = type.GetMethod(methodName);
if (minfo == null)
{
return null;
}
return minfo.Invoke(anObject, null);
}
}
// Fake UnityEditor.Editor : UnityEngine.ScriptableObject
public class Editor
{
SerializedObject _serializedObject;
public SerializedObject serializedObject
{
get
{
return _serializedObject;
}
}
private string targetTypeName;
private string headerString;
// This is internal and not compatible with UnityEditor.Editor
internal void Initialize(UnityEngine.Object targetComponent)
{
_serializedObject = new SerializedObject(targetComponent);
targetTypeName = targetComponent.GetType().Name;
headerString = targetTypeName + " (" + this.GetType() + ")";
}
public virtual void OnInspectorGUI()
{
EditorGUILayout.LabelField(headerString, new GUIStyle(){fontStyle = FontStyle.Bold});
}
}
////////////////////////////////////////////////////////////
// Editor implementations
class ReorderEditor : Iwsd.Editor
{
protected ReorderableList reorderableList;
protected string HeaderTitle;
// subclass must implement OnEnable() to build reorderableList
public void OnDisable()
{
reorderableList = null;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
reorderableList.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
// for VRCSDK2.VRC_Trigger
class VRC_TriggerOrderEditor : ReorderEditor
{
public void OnEnable()
{
var triggersProp = serializedObject.FindProperty("Triggers");
if (triggersProp == null)
{
Debug.LogError("triggersProp == null");
return;
}
reorderableList = new ReorderableList(serializedObject, triggersProp);
reorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField (rect, "VRC_Trigger | Triggers");
reorderableList.drawElementCallback = (rect, index, isActive, isFocused) => {
// padding
rect.height -= 4;
rect.y += 2;
// VRCSDK2.VRC_Trigger+TriggerEvent
var triggerProperty = triggersProp.GetArrayElementAtIndex(index);
var s = SummarizeTriggerEvent(index, serializedObject, triggerProperty);
EditorGUI.LabelField(rect, s);
};
// TODO add edit feature.
reorderableList.onMouseUpCallback = (list) => {
// Debug.Log("selected:" + list.index);
};
}
private static string SummarizeTriggerEvent(int index, SerializedObject vrc_trigger, SerializedProperty triggerEvent)
{
SerializedProperty triggerTypeProperty = triggerEvent.FindPropertyRelative("TriggerType");
var typeValue = (VRCSDK2.VRC_Trigger.TriggerType)triggerTypeProperty.intValue;
var buf = new System.Text.StringBuilder();
buf.Append(index);
buf.Append(": ");
buf.Append(typeValue);
switch (typeValue)
{
case VRCSDK2.VRC_Trigger.TriggerType.Custom:
var nameProperty = triggerEvent.FindPropertyRelative("Name");
buf.Append(" <Name=\"");
buf.Append(nameProperty.stringValue);
buf.Append("\">");
break;
case VRCSDK2.VRC_Trigger.TriggerType.OnInteract:
var interactText = vrc_trigger.FindProperty("interactText");
buf.Append(" <interactText=\"");
buf.Append(interactText.stringValue);
buf.Append("\">");
break;
case VRCSDK2.VRC_Trigger.TriggerType.OnKeyUp:
case VRCSDK2.VRC_Trigger.TriggerType.OnKeyDown:
var key = triggerEvent.FindPropertyRelative("Key");
var keyInt = key.intValue;
buf.Append(" <Key=");
if (Enum.IsDefined(typeof(KeyCode), keyInt))
{
var keyCode = (KeyCode)Enum.ToObject(typeof(KeyCode), keyInt);
buf.Append(keyCode);
}
else
{
buf.Append("unknown_value_");
buf.Append(keyInt);
}
buf.Append(">");
break;
case VRCSDK2.VRC_Trigger.TriggerType.OnEnterTrigger:
case VRCSDK2.VRC_Trigger.TriggerType.OnExitTrigger:
case VRCSDK2.VRC_Trigger.TriggerType.OnEnterCollider:
case VRCSDK2.VRC_Trigger.TriggerType.OnExitCollider:
var layers = triggerEvent.FindPropertyRelative("Layers");
var triggerIndividuals = triggerEvent.FindPropertyRelative("TriggerIndividuals");
buf.Append(" <Layers=\"");
buf.Append(LayerMaskNameStrings(layers.intValue));
buf.Append("\", individuals=");
buf.Append(FormatBooleanShort(triggerIndividuals.boolValue));
buf.Append(">");
break;
case VRCSDK2.VRC_Trigger.TriggerType.OnTimer:
var repeat = triggerEvent.FindPropertyRelative("Repeat");
var lowPeriodTime = triggerEvent.FindPropertyRelative("LowPeriodTime");
var highPeriodTime = triggerEvent.FindPropertyRelative("HighPeriodTime");
var resetOnEnable = triggerEvent.FindPropertyRelative("ResetOnEnable");
buf.Append(" <Repeat=");
buf.Append(FormatBooleanShort(repeat.boolValue));
buf.Append(", ResetOnEnable=");
buf.Append(FormatBooleanShort(resetOnEnable.boolValue));
if (lowPeriodTime.floatValue == highPeriodTime.floatValue)
{
buf.Append(", time=");
buf.Append(lowPeriodTime.floatValue);
}
else
{
buf.Append(", low=");
buf.Append(lowPeriodTime.floatValue);
buf.Append(", high=");
buf.Append(highPeriodTime.floatValue);
}
buf.Append(">");
break;
}
return buf.ToString();
}
private static string FormatBooleanShort(bool b)
{
return b? "T": "F";
}
private static string LayerMaskNameStrings(int layerMask)
{
if (layerMask == -1)
{
return "Everything";
}
if (layerMask == 0)
{
return "Nothing";
}
var buf = new System.Text.StringBuilder();
int v = 1;
for (int i = 0; i < 32; i++)
{
if ((layerMask & 1) != 0)
{
if (buf.Length != 0)
{
buf.Append('|');
}
buf.Append(LayerMask.LayerToName(i));
}
layerMask = layerMask >> 1;
v = v << 1;
}
return buf.ToString();
}
}
// for UnityEngine.UI.{Button, InputField}
class UnityEventOrderEditor : ReorderEditor
{
// EventPropName : Property name of a event (that is inherited from UnityEvent)
protected string EventPropName;
public void OnEnable()
{
// TODO check type and not-null
var m_OnClick = serializedObject.FindProperty(EventPropName);
if (m_OnClick == null)
{
Debug.LogError("m_OnClick == null. EventPropName=" + EventPropName);
return;
}
var m_PersistentCalls = m_OnClick.FindPropertyRelative("m_PersistentCalls");
var m_Calls = m_PersistentCalls.FindPropertyRelative("m_Calls");
reorderableList = new ReorderableList(serializedObject, m_Calls);
reorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField (rect, HeaderTitle);
reorderableList.drawElementCallback = (rect, index, isActive, isFocused) => {
var persistentCall = m_Calls.GetArrayElementAtIndex(index);
var m_MethodName = persistentCall.FindPropertyRelative("m_MethodName");
var s = index + ": '" + m_MethodName.stringValue + "'";
EditorGUI.LabelField(rect, s);
};
}
}
class ButtonUnityEventOrderEditor : UnityEventOrderEditor
{
public ButtonUnityEventOrderEditor()
{
EventPropName = "m_OnClick";
HeaderTitle = "Button | On Click ()";
}
}
class InputFieldOnValueChangedUnityEventOrderEditor : UnityEventOrderEditor
{
InputFieldOnValueChangedUnityEventOrderEditor()
{
EventPropName = "m_OnValueChanged";
HeaderTitle = "InputField | On Value Changed (String)";
}
}
class InputFieldOnEndEditUnityEventOrderEditor : UnityEventOrderEditor
{
InputFieldOnEndEditUnityEventOrderEditor()
{
EventPropName = "m_OnEndEdit";
HeaderTitle = "InputField | On End Edit (String)";
}
}
// In case of Button
// MonoBehaviour: <= Button component
// ...
// m_OnClick: <= inherited from UnityEvent
// m_PersistentCalls:
// m_Calls: <= List<PersistentCall>
// - m_Target: {fileID: 878055904}
// m_MethodName: set_layer
// m_Mode: 3
// m_Arguments:
// m_ObjectArgument: {fileID: 0}
// m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
// m_IntArgument: 3
// m_FloatArgument: 0
// m_StringArgument:
// m_BoolArgument: 0
// m_CallState: 2
// - m_Target: {fileID: 878055909}
// ...
// m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
// Culture=neutral, PublicKeyToken=null
// In case of InputField
// m_OnEndEdit:
// m_PersistentCalls:
// m_Calls: []
// m_TypeName: UnityEngine.UI.InputField+SubmitEvent, UnityEngine.UI, Version=1.0.0.0,
// Culture=neutral, PublicKeyToken=null
// m_OnValueChanged:
// m_PersistentCalls:
// m_Calls: []
// m_TypeName: UnityEngine.UI.InputField+OnChangeEvent, UnityEngine.UI, Version=1.0.0.0,
// Culture=neutral, PublicKeyToken=null
/**
* Editor for VRCSDK2.scripts.Scenes.VRC_Panorama
*/
class VRC_PanoramaSimpleEditor : Iwsd.Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
EditorGUI.indentLevel++;
panoramasGUI(serializedObject.FindProperty("panoramas"));
EditorGUI.indentLevel--;
serializedObject.ApplyModifiedProperties();
}
void panoramasGUI(SerializedProperty panoramas)
{
EditorGUILayout.LabelField("count of panoramas:" + panoramas.arraySize);
for (int idx = 0; idx < panoramas.arraySize; idx++)
{
// VRCSDK2.scripts.Scenes.VRC_Panorama+PanoSpec
var panoSpec = panoramas.GetArrayElementAtIndex(idx);
// SerializedProperty of string
var url = panoSpec.FindPropertyRelative("url");
// SerializedProperty of PPtr<$Texture2D>
var texture = panoSpec.FindPropertyRelative("texture");
EditorGUILayout.LabelField(idx + ":");
url.stringValue = EditorGUILayout.TextField("URL:", url.stringValue);
EditorGUILayout.PropertyField(texture, new GUIContent("texture"));
}
}
}
/**
* Yet another Editor for VRCSDK2.scripts.Scenes.VRC_Panorama
*/
class VRC_PanoramaOrderEditor : Iwsd.Editor
{
ReorderableList reorderableList;
int texDispSize = 40;
int paddingSize = 3;
public void OnDisable()
{
reorderableList = null;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
var renderer = serializedObject.FindProperty("renderer");
EditorGUILayout.PropertyField(renderer, new GUIContent("renderer"));
reorderableList.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
public void OnEnable()
{
var panoramas = serializedObject.FindProperty("panoramas");
reorderableList = new ReorderableList(serializedObject, panoramas);
reorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField (rect, "panoramas");
reorderableList.elementHeight = paddingSize + EditorGUIUtility.singleLineHeight + texDispSize + paddingSize;
reorderableList.drawElementCallback = (rect, index, isActive, isFocused) => {
// VRCSDK2.scripts.Scenes.VRC_Panorama+PanoSpec
var panoSpec = panoramas.GetArrayElementAtIndex(index);
DrawPeoperty(rect, panoSpec, index);
};
}
// PropertyDrawer.OnGUI like interface
private void DrawPeoperty(Rect position, SerializedProperty panoSpec, int index)
{
var url = panoSpec.FindPropertyRelative("url");
var texture = panoSpec.FindPropertyRelative("texture");
// index + url
var rect = new Rect (position) {
y = position.y + paddingSize,
height = EditorGUIUtility.singleLineHeight
};
url.stringValue = EditorGUI.TextField(rect, new GUIContent(index + " URL"), url.stringValue);
// texture
rect.y += paddingSize + rect.height;
rect.height = texDispSize;
texture.objectReferenceValue =
EditorGUI.ObjectField(rect, new GUIContent("texture"), texture.objectReferenceValue, typeof(Texture2D), false);
// (another simple way)
// EditorGUI.PropertyField(rect, texture, new GUIContent("texture"));
}
}
class TextMeshTextEditor : Iwsd.Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
EditorGUI.indentLevel++;
var text = serializedObject.FindProperty("m_Text");
text.stringValue = EditorGUILayout.TextArea(text.stringValue, new GUIStyle(GUI.skin.textArea){wordWrap = true});
EditorGUI.indentLevel--;
serializedObject.ApplyModifiedProperties();
}
}
class PropertyDump : Iwsd.Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
// serializedObject.Update();
DumpProperties(serializedObject);
}
// https://forum.unity.com/threads/enumarting-serializedproperty-throws-an-exception.511310/
// https://forum.unity.com/threads/loop-through-serializedproperty-children.435119/
//
// MEMO: Since Unity2018.3, property.objectReferenceValue is 0 for both Missing and None case.
// [Unity2018.3でのMissingが検出できない](https://teratail.com/questions/167668)
// Check child property "m_FileID", its intValue is 0 for None, otherwise Missing.
void DumpProperties(SerializedObject obj)
{
var s = DumpProperties(obj, 50);
EditorGUILayout.TextArea(s, new GUIStyle(GUI.skin.textArea){wordWrap = true});
}
string DumpProperties(SerializedObject obj, int limit)
{
SerializedProperty prop = obj.GetIterator();
var buf = new System.Text.StringBuilder();
int skipUntil = -1;
// not well at end of child propeties
// foreach (var item in property) {
// SerializedProperty prop = (SerializedProperty)item;
while (prop.Next(true))
{
if (--limit < 0)
{
buf.Append("...(snip tail)...\n");
break;
}
if (prop.depth <= skipUntil)
{
skipUntil = -1;
}
if (skipUntil < 0)
{
PrintPropertyItself(prop, buf);
// if (prop.propertyType == SerializedPropertyType.String)
// {
// skipUntil = prop.depth;
// Indent(prop.depth, buf);
// buf.Append("(content omitted)\n");
// }
}
}
return buf.ToString();
}
void PrintPropertyItself(SerializedProperty prop, System.Text.StringBuilder buf)
{
Indent(prop.depth, buf);
buf.Append(prop.propertyType);
buf.Append(": '");
buf.Append(prop.name);
buf.Append("', '");
buf.Append(prop.propertyPath);
buf.Append("'");
switch (prop.propertyType)
{
case SerializedPropertyType.String:
buf.Append(", value='");
buf.Append(prop.stringValue);
buf.Append("'");
break;
case SerializedPropertyType.Integer:
buf.Append(", value='");
buf.Append(prop.intValue);
buf.Append("'");
break;
default:
break;
}
buf.Append("\n");
}
private void Indent(int count, System.Text.StringBuilder buf)
{
while (0 < count-- )
{
buf.Append(" ");
}
}
}
}