public override object OnGUI(params GUILayoutOption[] options) { if (!type.IsClass) { EditorGUILayout.LabelField("not class type"); return(instance); } if (instance == null) { //try set defalut instance = TypeHelper.DefaultValue(type); } if (instance == null) { EditorGUILayout.LabelField(type + "cant serialize"); return(instance); } if (OnGUIUtility.EditorPrefsFoldoutGroup(this.Title)) { OnGUIUtility.Layout.IndentBegin(); List <FieldInfo> fields = new List <FieldInfo>(); fields.AddRange(type.GetPublicFields()); fields.AddRange(type.GetPrivateFields(typeof(SerializeField))); foreach (var field in fields) { object value = field.GetValue(instance); var fieldValue = FieldDrawerUtil.ObjectField(field.Name, value, field.FieldType, field, this, options); field.SetValue(instance, fieldValue); } OnGUIUtility.Layout.IndentEnd(); } return(instance); }
public override object OnGUI(params GUILayoutOption[] options) { EditorGUILayout.BeginVertical(); if (OnGUIUtility.EditorPrefsFoldoutGroup(Title)) { OnGUIUtility.Layout.IndentBegin(); Type dataType = instance.GetType().GetElementType(); Array a = (Array)instance; int count = EditorGUILayout.IntField("Size", a.Length); count = Mathf.Max(0, count); if (count > a.Length) { int offset = count - a.Length; Array temp = Array.CreateInstance(dataType, count); a.CopyTo(temp, 0); for (int i = a.Length; i < a.Length + offset; i++) { temp.SetValue(TypeHelper.DefaultValue(dataType), i); } instance = temp; } else if (count < a.Length) { Array temp = Array.CreateInstance(dataType, count); for (int i = 0; i < count; i++) { temp.SetValue(a.GetValue(i), i); } instance = temp; } a = (Array)instance; for (int i = 0; i < a.Length; i++) { object data = a.GetValue(i); a.SetValue(FieldDrawerUtil.ObjectField(i.ToString(), data, dataType, this.fieldInfo, this), i); //a.SetValue(FieldDrawerUtil.ValueField(i.ToString(), data, dataType), i); } OnGUIUtility.Layout.IndentEnd(); } EditorGUILayout.EndVertical(); return(instance); }
public override object OnGUI(params GUILayoutOption[] options) { EditorGUILayout.BeginVertical(); if (OnGUIUtility.EditorPrefsFoldoutGroup(Title)) { OnGUIUtility.Layout.IndentBegin(); Type dataType = instance.GetType().GetGenericArguments()[0]; IList list = (IList)instance; int count = EditorGUILayout.IntField("Size", list.Count); count = Mathf.Max(0, count); if (count > list.Count) { int offset = count - list.Count; for (int i = 0; i < offset; i++) { list.Add(TypeHelper.DefaultValue(dataType)); } } else if (count < list.Count) { for (int i = list.Count - 1; i >= count; i--) { list.RemoveAt(i); } } for (int i = 0; i < list.Count; i++) { object data = list[i]; list[i] = FieldDrawerUtil.ObjectField(i.ToString(), data, dataType, this.fieldInfo, this); } OnGUIUtility.Layout.IndentEnd(); } EditorGUILayout.EndVertical(); return(instance); }