private static object DrawSingleField(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, object value) { if (fieldType.Equals(typeof(int))) { return(EditorGUILayout.IntField(guiContent, (int)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(float))) { return(EditorGUILayout.FloatField(guiContent, (float)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(double))) { return(EditorGUILayout.FloatField(guiContent, Convert.ToSingle((double)value), new GUILayoutOption[0])); } if (fieldType.Equals(typeof(long))) { return((long)EditorGUILayout.IntField(guiContent, Convert.ToInt32((long)value), new GUILayoutOption[0])); } if (fieldType.Equals(typeof(bool))) { return(EditorGUILayout.Toggle(guiContent, (bool)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(string))) { return(EditorGUILayout.TextField(guiContent, (string)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(byte))) { return(Convert.ToByte(EditorGUILayout.IntField(guiContent, Convert.ToInt32(value), new GUILayoutOption[0]))); } if (fieldType.Equals(typeof(Vector2))) { return(EditorGUILayout.Vector2Field(guiContent.text, (Vector2)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(Vector3))) { return(EditorGUILayout.Vector3Field(guiContent.text, (Vector3)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(Vector4))) { return(EditorGUILayout.Vector4Field(guiContent.text, (Vector4)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(Quaternion))) { Quaternion quaternion = (Quaternion)value; Vector4 value2 = Vector4.zero; value2.Set(quaternion.x, quaternion.y, quaternion.z, quaternion.w); value2 = EditorGUILayout.Vector4Field(guiContent.text, value2, new GUILayoutOption[0]); quaternion.Set(value2.x, value2.y, value2.z, value2.w); return(quaternion); } if (fieldType.Equals(typeof(Color))) { return(EditorGUILayout.ColorField(guiContent, (Color)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(Rect))) { return(EditorGUILayout.RectField(guiContent, (Rect)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(Matrix4x4))) { GUILayout.BeginVertical(new GUILayoutOption[0]); if (FieldInspector.DrawFoldout(value.GetHashCode(), guiContent)) { EditorGUI.indentLevel++; Matrix4x4 matrix4x = (Matrix4x4)value; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { EditorGUI.BeginChangeCheck(); matrix4x[i, j] = EditorGUILayout.FloatField("E" + i.ToString() + j.ToString(), matrix4x[i, j], new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { GUI.changed = true; } } } value = matrix4x; EditorGUI.indentLevel--; } GUILayout.EndVertical(); return(value); } if (fieldType.Equals(typeof(AnimationCurve))) { if (value == null) { value = new AnimationCurve(); } return(EditorGUILayout.CurveField(guiContent, (AnimationCurve)value, new GUILayoutOption[0])); } if (fieldType.Equals(typeof(LayerMask))) { return(FieldInspector.DrawLayerMask(guiContent, (LayerMask)value)); } if (typeof(SharedVariable).IsAssignableFrom(fieldType)) { return(FieldInspector.DrawSharedVariable(task, guiContent, fieldInfo, fieldType, value as SharedVariable)); } if (typeof(UnityEngine.Object).IsAssignableFrom(fieldType)) { return(EditorGUILayout.ObjectField(guiContent, (UnityEngine.Object)value, fieldType, true, new GUILayoutOption[0])); } if (fieldType.IsEnum) { return(EditorGUILayout.EnumPopup(guiContent, (Enum)value, new GUILayoutOption[0])); } if (!fieldType.IsClass && (!fieldType.IsValueType || fieldType.IsPrimitive)) { EditorGUILayout.LabelField("Unsupported Type: " + fieldType, new GUILayoutOption[0]); return(null); } int hashCode = guiContent.text.GetHashCode(); if (FieldInspector.drawnObjects.Contains(hashCode)) { return(null); } FieldInspector.drawnObjects.Add(hashCode); GUILayout.BeginVertical(new GUILayoutOption[0]); if (fieldType.IsAbstract) { EditorGUILayout.LabelField(guiContent, new GUILayoutOption[0]); GUILayout.EndVertical(); return(null); } if (value == null) { if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable <>)) { fieldType = Nullable.GetUnderlyingType(fieldType); } value = Activator.CreateInstance(fieldType, true); } if (FieldInspector.DrawFoldout(value.GetHashCode(), guiContent)) { EditorGUI.indentLevel++; value = FieldInspector.DrawFields(task, value); EditorGUI.indentLevel--; } GUILayout.EndVertical(); FieldInspector.drawnObjects.Remove(hashCode); return(value); }
private static object DrawArrayField(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, object value) { Type type; if (fieldType.IsArray) { type = fieldType.GetElementType(); } else { Type type2 = fieldType; while (!type2.IsGenericType) { type2 = type2.BaseType; } type = type2.GetGenericArguments()[0]; } IList list; if (value == null) { if (fieldType.IsGenericType || fieldType.IsArray) { list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type }), true) as IList); } else { list = (Activator.CreateInstance(fieldType, true) as IList); } if (fieldType.IsArray) { Array array = Array.CreateInstance(type, list.Count); list.CopyTo(array, 0); list = array; } GUI.changed = true; } else { list = (IList)value; } EditorGUILayout.BeginVertical(new GUILayoutOption[0]); if (FieldInspector.DrawFoldout(list.GetHashCode(), guiContent)) { EditorGUI.indentLevel++; bool flag = guiContent.text.GetHashCode() == FieldInspector.editingFieldHash; int num = (!flag) ? list.Count : FieldInspector.savedArraySize; int num2 = EditorGUILayout.IntField("Size", num, new GUILayoutOption[0]); if (flag && FieldInspector.editingArray && (GUIUtility.keyboardControl != FieldInspector.currentKeyboardControl || Event.current.keyCode == KeyCode.Return)) { if (num2 != list.Count) { Array array2 = Array.CreateInstance(type, num2); int num3 = -1; for (int i = 0; i < num2; i++) { if (i < list.Count) { num3 = i; } if (num3 == -1) { break; } array2.SetValue(list[num3], i); } if (fieldType.IsArray) { list = array2; } else { if (fieldType.IsGenericType) { list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type }), true) as IList); } else { list = (Activator.CreateInstance(fieldType, true) as IList); } for (int j = 0; j < array2.Length; j++) { list.Add(array2.GetValue(j)); } } } FieldInspector.editingArray = false; FieldInspector.savedArraySize = -1; FieldInspector.editingFieldHash = -1; GUI.changed = true; } else if (num2 != num) { if (!FieldInspector.editingArray) { FieldInspector.currentKeyboardControl = GUIUtility.keyboardControl; FieldInspector.editingArray = true; FieldInspector.editingFieldHash = guiContent.text.GetHashCode(); } FieldInspector.savedArraySize = num2; } for (int k = 0; k < list.Count; k++) { GUILayout.BeginHorizontal(new GUILayoutOption[0]); guiContent.text = "Element " + k; list[k] = FieldInspector.DrawField(task, guiContent, fieldInfo, type, list[k]); GUILayout.Space(6f); GUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); return(list); }