VRMMetaEditor.cs
5.45 KB
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
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace VRM
{
[CustomEditor(typeof(VRMMeta))]
public class VRMMetaEditor : Editor
{
//VRMMeta m_target;
SerializedProperty m_ScriptProp;
SerializedProperty m_VRMMetaObjectProp;
SerializedProperty VRMMetaObjectProp
{
get { return m_VRMMetaObjectProp; }
set
{
if (m_VRMMetaObjectProp == value) return;
m_VRMMetaObjectProp = value;
// get props
Debug.Log("clear");
m_propMap.Clear();
}
}
Dictionary<string, SerializedProperty> m_propMap = new Dictionary<string, SerializedProperty>();
void InitMap(SerializedObject so)
{
if (VRMMetaObjectProp == null) return;
//if (m_propMap.Count > 0) return;
m_propMap.Clear();
for (var it = so.GetIterator(); it.NextVisible(true);)
{
if (it.name == "m_Script") continue;
//Debug.LogFormat("{0}", it.name);
m_propMap.Add(it.name, so.FindProperty(it.name));
}
}
private void OnEnable()
{
//m_target = (VRMMeta)target;
m_ScriptProp = serializedObject.FindProperty("m_Script");
m_VRMMetaObjectProp = serializedObject.FindProperty("Meta");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_ScriptProp, true);
EditorGUILayout.PropertyField(m_VRMMetaObjectProp, true);
serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space();
#if true
if (m_VRMMetaObjectProp.objectReferenceValue != null)
{
VRMMetaObjectGUI(new SerializedObject(m_VRMMetaObjectProp.objectReferenceValue));
}
#else
if(m_target!=null && m_target.Meta != null)
{
VRMMetaObjectGUI(new SerializedObject(m_target.Meta));
}
#endif
}
bool m_foldoutInfo = true;
bool m_foldoutPersmission = true;
bool m_foldoutDistribution = true;
void VRMMetaObjectGUI(SerializedObject so)
{
InitMap(so);
if (m_propMap == null || m_propMap.Count == 0) return;
so.Update();
GUI.enabled = false;
EditorGUILayout.PropertyField(m_propMap["ExporterVersion"]);
if (VRMVersion.IsNewer(m_propMap["ExporterVersion"].stringValue))
{
EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning);
}
GUI.enabled = true;
m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information");
if (m_foldoutInfo)
{
EditorGUILayout.PropertyField(m_propMap["Title"]);
EditorGUILayout.PropertyField(m_propMap["Version"]);
EditorGUILayout.PropertyField(m_propMap["Author"]);
EditorGUILayout.PropertyField(m_propMap["ContactInformation"]);
EditorGUILayout.PropertyField(m_propMap["Reference"]);
var thumbnail = m_propMap["Thumbnail"];
EditorGUILayout.PropertyField(thumbnail);
thumbnail.objectReferenceValue = TextureField("", (Texture2D)thumbnail.objectReferenceValue, 100);
}
EditorGUILayout.LabelField("License ", EditorStyles.boldLabel);
m_foldoutPersmission = EditorGUILayout.Foldout(m_foldoutPersmission, "Personation / Characterization Permission");
if (m_foldoutPersmission)
{
EditorGUILayout.PropertyField(m_propMap["AllowedUser"], new GUIContent("A person who can perform with this avatar"), false);
EditorGUILayout.PropertyField(m_propMap["ViolentUssage"], new GUIContent("Violent acts using this avatar"));
EditorGUILayout.PropertyField(m_propMap["SexualUssage"], new GUIContent("Sexuality acts using this avatar"));
EditorGUILayout.PropertyField(m_propMap["CommercialUssage"], new GUIContent("For commercial use"));
EditorGUILayout.PropertyField(m_propMap["OtherPermissionUrl"], new GUIContent("Other License Url"));
}
m_foldoutDistribution = EditorGUILayout.Foldout(m_foldoutDistribution, "Redistribution / Modifications License");
if (m_foldoutDistribution)
{
var licenseType = m_propMap["LicenseType"];
EditorGUILayout.PropertyField(licenseType);
if ((LicenseType)licenseType.intValue == LicenseType.Other)
{
EditorGUILayout.PropertyField(m_propMap["OtherLicenseUrl"]);
}
}
so.ApplyModifiedProperties();
}
private static Texture2D TextureField(string name, Texture2D texture, int size)
{
GUILayout.BeginHorizontal();
var style = new GUIStyle(GUI.skin.label);
style.alignment = TextAnchor.UpperCenter;
//style.fixedWidth = size;
GUILayout.Label(name, style);
var result = (Texture2D)EditorGUILayout.ObjectField(texture, typeof(Texture2D), false, GUILayout.Width(size), GUILayout.Height(size));
GUILayout.EndVertical();
return result;
}
}
}