public static bool CanDraw(FieldInfo _fieldInfo) { return(!CSUtility.TryGetTypeAttribute(_fieldInfo.DeclaringType, out NonSerializedAttribute nonAtt) && !CSUtility.TryGetFieldInfoAttribute(_fieldInfo, out HideInInspector hideAtt) && ((!_fieldInfo.IsPrivate && !_fieldInfo.IsFamily) || CSUtility.TryGetFieldInfoAttribute(_fieldInfo, out SerializeField serAtt))); }
private static object DrawSingleField(GUIContent _content, FieldInfo _fieldInfo, object _value) { ObjectDrawer objectDrawer; if ((CSUtility.TryGetFieldInfoAttribute(_fieldInfo, out ObjectDrawerAttribute att) || CSUtility.TryGetTypeAttribute(_fieldInfo.FieldType, out att)) && (objectDrawer = ObjectDrawerUtility.GetObjectDrawer(att)) != null) { if (_value == null && !_fieldInfo.FieldType.IsAbstract) { if (typeof(ScriptableObject).IsAssignableFrom(_fieldInfo.FieldType)) { _value = ScriptableObject.CreateInstance(_fieldInfo.FieldType); } else { _value = Activator.CreateInstance(_fieldInfo.FieldType, true); } } objectDrawer.Value = _value; objectDrawer.OnGUI(_content); if (objectDrawer.Value != _value) { _value = objectDrawer.Value; GUI.changed = true; } return(_value); } return(DrawSingleField(_content, _fieldInfo.FieldType, _value)); }
private static object DrawArrayField(GUIContent _content, FieldInfo _fieldInfo, Type _fieldType, object _value) { Type elementType; if (_fieldType.IsArray) { elementType = _fieldType.GetElementType(); } else { Type type2 = _fieldType; while (!type2.IsGenericType) { type2 = type2.BaseType; } elementType = type2.GetGenericArguments()[0]; } IList list; if (_value == null) { if (_fieldType.IsGenericType || _fieldType.IsArray) { list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { elementType }), true) as IList); } else { list = (Activator.CreateInstance(_fieldType, true) as IList); } if (_fieldType.IsArray) { Array array = Array.CreateInstance(elementType, list.Count); list.CopyTo(array, 0); list = array; } GUI.changed = true; } else { list = (IList)_value; } EditorGUILayout.BeginVertical(new GUILayoutOption[0]); if (EditorGUILayoutExtension.DrawFoldout(_content.text.GetHashCode(), _content)) { EditorGUI.indentLevel++; bool flag = _content.text.GetHashCode() == EditorGUILayoutExtension.editingFieldHash; int num = (!flag) ? list.Count : EditorGUILayoutExtension.savedArraySize; int num2 = EditorGUILayout.IntField("Size", num, new GUILayoutOption[0]); if (flag && EditorGUILayoutExtension.editingArray && (GUIUtility.keyboardControl != EditorGUILayoutExtension.currentKeyboardControl || Event.current.keyCode == (KeyCode)13)) { if (num2 != list.Count) { Array array2 = Array.CreateInstance(elementType, num2); int num3 = -1; for (int i = 0; i < num2; i++) { if (i < list.Count) { num3 = i; } if (num3 == -1) { break; } object value2 = list[num3]; if (i >= list.Count && !typeof(Object).IsAssignableFrom(elementType) && !typeof(string).IsAssignableFrom(elementType)) { value2 = Activator.CreateInstance(list[num3].GetType(), true); } array2.SetValue(value2, i); } if (_fieldType.IsArray) { list = array2; } else { if (_fieldType.IsGenericType) { list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { elementType }), true) as IList); } else { list = (Activator.CreateInstance(_fieldType, true) as IList); } for (int j = 0; j < array2.Length; j++) { list.Add(array2.GetValue(j)); } } } EditorGUILayoutExtension.editingArray = false; EditorGUILayoutExtension.savedArraySize = -1; EditorGUILayoutExtension.editingFieldHash = -1; GUI.changed = true; } else if (num2 != num) { if (!EditorGUILayoutExtension.editingArray) { EditorGUILayoutExtension.currentKeyboardControl = GUIUtility.keyboardControl; EditorGUILayoutExtension.editingArray = true; EditorGUILayoutExtension.editingFieldHash = _content.text.GetHashCode(); } EditorGUILayoutExtension.savedArraySize = num2; } if (_fieldInfo != null && (CSUtility.TryGetFieldInfoAttribute(_fieldInfo, out ObjectDrawerAttribute att) || CSUtility.TryGetTypeAttribute(elementType, out att))) { for (int k = 0; k < list.Count; k++) { ObjectDrawer objectDrawer; if ((objectDrawer = ObjectDrawerUtility.GetObjectDrawer(att)) != null) { _content.text = "Element " + k; objectDrawer.Value = list[k]; objectDrawer.OnGUI(_content); if (objectDrawer.Value != list[k]) { list[k] = objectDrawer.Value; GUI.changed = true; } } } } else { for (int k = 0; k < list.Count; k++) { GUILayout.BeginHorizontal(new GUILayoutOption[0]); _content.text = "Element " + k; list[k] = EditorGUILayoutExtension.DrawField(_content, elementType, list[k]); GUILayout.Space(6f); GUILayout.EndHorizontal(); } } EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); return(list); }