-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSofaBaseComponentEditor.cs
More file actions
180 lines (161 loc) · 7.53 KB
/
SofaBaseComponentEditor.cs
File metadata and controls
180 lines (161 loc) · 7.53 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
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
using UnityEngine;
using UnityEditor;
using SofaUnity;
using UnityEditor.AnimatedValues;
using System.Collections.Generic;
namespace SofaUnity
{
/// <summary>
/// Editor class corresponding to @sa SofaBaseComponent
/// Provide interface for all component inheriting from @sa SofaBaseComponent which will display all Data.
/// Not all Data types are shown, for example vectors. Option to show unsupported Data is availble.
/// </summary>
[CustomEditor(typeof(SofaBaseComponent), true)]
public class SofaBaseComponentEditor : Editor
{
AnimBool m_ShowUnsupportedFields;
protected bool m_showData = true;
/// Callback method to show or not unsupported Data
void OnEnable()
{
m_ShowUnsupportedFields = new AnimBool(false);
m_ShowUnsupportedFields.valueChanged.AddListener(Repaint);
}
/// Method to create parameters GUI
public override void OnInspectorGUI()
{
SofaBaseComponent compo = (SofaBaseComponent)this.target;
EditorGUILayout.LabelField("Sofa Component Information", EditorStyles.whiteLargeLabel);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField("Component Type", compo.m_componentType);
EditorGUILayout.EnumPopup("BaseComponentType", compo.m_baseComponentType);
EditorGUILayout.TextField("Unique Name Id", compo.UniqueNameId);
EditorGUILayout.ObjectField("Sofa DAG Node", compo.m_ownerNode, typeof(Object), true);
EditorGUI.EndDisabledGroup();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("SofaUnity Parameters", EditorStyles.whiteLargeLabel);
compo.m_log = EditorGUILayout.Toggle("Dump logs", compo.m_log);
EditorGUILayout.Separator();
SofaDataArchiver dataArchiver = compo.m_dataArchiver;
if (dataArchiver == null || !m_showData)
return;
EditorGUILayout.LabelField("Sofa Data", EditorStyles.whiteLargeLabel);
List<SofaData> m_unssuportedData = new List<SofaData>();
for (int i = 0; i < dataArchiver.m_names.Count; i++)
{
string dataType = dataArchiver.m_types[i];
string dataName = dataArchiver.m_names[i];
SofaBaseData bData = dataArchiver.m_dataArray[i];
if (!bData.IsDisplayed())
{
Debug.Log("Do not display: " + dataName + " of type: " + dataType);
continue;
}
if (!bData.IsSupported()) // not supported
{
m_unssuportedData.Add((SofaData)(bData));
continue;
}
if (bData.IsVector())
{
EditorGUI.BeginDisabledGroup(true);
SofaDataVector data = (SofaDataVector)(bData);
EditorGUILayout.TextField(data.DataName, "Type: " + data.DataType + " | Size: " + data.GetSize());
EditorGUI.EndDisabledGroup();
continue;
}
if (bData.IsReadOnly())
EditorGUI.BeginDisabledGroup(true);
//Debug.Log("dataName: " + dataName + " | dataType: " + dataType + " | bData: " + bData.DataName + " type: " + bData.GetType().Name);
if (dataType == "string")
{
SofaStringData data = (SofaStringData)(bData);
data.Value = EditorGUILayout.TextField(data.DataName, data.Value);
}
else if (dataType == "bool")
{
SofaBoolData data = (SofaBoolData)(bData);
data.Value = EditorGUILayout.Toggle(data.DataName, data.Value);
}
else if (dataType == "i" || dataType == "uint")
{
SofaIntData data = (SofaIntData)(dataArchiver.m_dataArray[i]);
data.Value = EditorGUILayout.IntField(data.DataName, data.Value);
}
else if (dataType == "f")
{
SofaFloatData data = (SofaFloatData)(bData);
data.Value = EditorGUILayout.FloatField(data.DataName, data.Value);
}
else if (dataType == "d")
{
SofaDoubleData data = (SofaDoubleData)(bData);
data.Value = EditorGUILayout.FloatField(data.DataName, data.Value);
}
else if (dataType == "Vec2i")
{
SofaVec2IntData data = (SofaVec2IntData)(bData);
data.Value = EditorGUILayout.Vector2IntField(data.DataName, data.Value);
}
else if (dataType == "Vec2f" || dataType == "Vec2d")
{
SofaVec2Data data = (SofaVec2Data)(bData);
data.Value = EditorGUILayout.Vector2Field(data.DataName, data.Value);
}
else if (dataType == "Vec3i")
{
SofaVec3IntData data = (SofaVec3IntData)(bData);
data.Value = EditorGUILayout.Vector3IntField(data.DataName, data.Value);
}
else if (dataType == "Vec3f" || dataType == "Vec3d")
{
SofaVec3Data data = (SofaVec3Data)(bData);
data.Value = EditorGUILayout.Vector3Field(data.DataName, data.Value);
}
else if (dataType == "Vec4f" || dataType == "Vec4d")
{
SofaVec4Data data = (SofaVec4Data)(bData);
data.Value = EditorGUILayout.Vector4Field(data.DataName, data.Value);
}
else if (dataType == "RigidCoord3f" || dataType == "RigidCoord3d")
{
SofaRigidData data = (SofaRigidData)(bData);
EditorGUILayout.Vector3Field(data.DataName, data.Position);
EditorGUILayout.Vector3Field(data.DataName, data.Angles);
}
else
{
Debug.LogError("Data not handled: " + dataName + " [" + dataType + "]");
}
if (bData.IsReadOnly())
EditorGUI.EndDisabledGroup();
}
// Add the links
SofaLinkArchiver linkArchiver = compo.m_linkArchiver;
if (linkArchiver != null && linkArchiver.m_links != null)
{
EditorGUILayout.Separator();
EditorGUI.BeginDisabledGroup(true);
foreach (SofaLink link in linkArchiver.m_links)
{
EditorGUILayout.TextField("@" + link.LinkName, link.LinkPath);
}
EditorGUI.EndDisabledGroup();
}
if (m_unssuportedData.Count > 0)
{
EditorGUILayout.Separator();
m_ShowUnsupportedFields.target = EditorGUILayout.ToggleLeft("Show unsupported Data", m_ShowUnsupportedFields.target);
if (EditorGUILayout.BeginFadeGroup(m_ShowUnsupportedFields.faded))
{
foreach (SofaData data in m_unssuportedData)
{
EditorGUILayout.TextField(data.DataName, "Unsupported type: " + data.DataType);
}
}
EditorGUILayout.Separator();
EditorGUILayout.EndFadeGroup();
}
}
}
}