public static object DrawField(Task task, GUIContent guiContent, FieldInfo field, object value) { ObjectDrawer objectDrawer; if ((objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, field)) != null) { if (value == null && !field.FieldType.IsAbstract) { value = Activator.CreateInstance(field.FieldType, true); } objectDrawer.Value = value; objectDrawer.OnGUI(guiContent); if (objectDrawer.Value != value) { value = objectDrawer.Value; GUI.changed = (true); } return(value); } ObjectDrawerAttribute[] array; if ((array = (field.GetCustomAttributes(typeof(ObjectDrawerAttribute), true) as ObjectDrawerAttribute[])).Length > 0 && (objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, array[0])) != null) { if (value == null) { value = Activator.CreateInstance(field.FieldType, true); } objectDrawer.Value = value; objectDrawer.OnGUI(guiContent); if (objectDrawer.Value != value) { value = objectDrawer.Value; GUI.changed = (true); } return(value); } return(FieldInspector.DrawField(task, guiContent, field, field.FieldType, 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); }