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 void OnGUI(Rect rect) { scroll = EditorGUILayout.BeginScrollView(scroll); EditorGUI.BeginChangeCheck(); if (OnGui == null) { FieldDrawerUtil.ObjectField(Title, current, current.GetType(), null); } else { OnGui(rect); } if (EditorGUI.EndChangeCheck()) { if (OnChange != null) { OnChange(); } } EditorGUILayout.EndScrollView(); }
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); }
public void OnGUI() { if (!ReferenceRoot.Instance) { EditorGUILayout.HelpBox("Scene need RefrenceRoot", MessageType.Error); if (GUILayout.Button("Create Root")) { CreateReferenceRoot(); } return; } EditorGUILayout.BeginHorizontal(); { ShowMode.OnGui(EditorStyles.toolbarButton); search.OnToolbarGUI(); if (GUILayout.Button("Refresh", EditorStyles.toolbarButton)) { RefreshData(); } if (Event.current.type == EventType.Layout && Event.current.keyCode == KeyCode.R) { RefreshData(); } if (Event.current.type == EventType.Layout && Missing) { RefreshData(); Missing = false; } } EditorGUILayout.EndHorizontal(); v = EditorGUILayout.BeginScrollView(v); { if (ShowMode.IsEnable(0)) { foreach (var objPair in AllDic) { if (objPair.Key == null) { Missing = true; break; } if (filtRefObj(objPair.Key)) { bool hasConflit = objPair.Value; OnGUIUtility.Vision.BeginBackGroundColor(hasConflit ? Color.red : Color.white); EditorGUILayout.BeginHorizontal(); { GUILayout.Label(objPair.Key.Data.GUID, GUILayout.MaxWidth(100)); if (GUILayout.Button(objPair.Key.gameObject.name, OnGUIUtility.Styles.Title)) { Selection.activeGameObject = objPair.Key.gameObject; } if (hasConflit) { if (GUILayout.Button("New", GUILayout.MaxWidth(64))) { NewGUID(objPair.Key); return; } if (GUILayout.Button(objPair.Value.gameObject.name, OnGUIUtility.Styles.Title)) { Selection.activeGameObject = objPair.Value.gameObject; } if (GUILayout.Button("New", GUILayout.MaxWidth(64))) { NewGUID(objPair.Value); return; } } } EditorGUILayout.EndHorizontal(); OnGUIUtility.Vision.EndBackGroundColor(); } } } else if (ShowMode.IsEnable(1)) { FieldDrawerUtil.ObjectField("测试资源", TestAssets); foreach (var reference in References) { if (filtReference(reference)) { var refobj = ReferenceRoot.Instance.Get(reference.Identity); Color color = Color.white; if (!refobj) { color = OnGUIUtility.Colors.red; } if (reference.Dynamic) { color = OnGUIUtility.Colors.blue; } OnGUIUtility.Vision.BeginBackGroundColor(color); EditorGUILayout.BeginHorizontal(); { var title = reference.Identity; if (reference.Dynamic) { title = "(" + reference.DyamicName + ")" + reference.Identity; } GUILayout.Label(title, GUILayout.MaxWidth(150)); if (refobj) { if (GUILayout.Button(refobj.gameObject.name, OnGUIUtility.Styles.Title)) { Selection.activeGameObject = refobj.gameObject; } } else { if (GUILayout.Button("Null", OnGUIUtility.Styles.Title)) { ObjectPopupWindow.Show(reference); } } EditorGUILayout.EndHorizontal(); } OnGUIUtility.Vision.EndBackGroundColor(); } } } else if (ShowMode.IsEnable(2)) { OnGUIUtility.Vision.BeginBackGroundColor(Color.blue); foreach (var item in ReferenceRoot.Instance.DynamicNameDic) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.SelectableLabel(item.Key, GUILayout.MaxWidth(100)); EditorGUILayout.SelectableLabel(item.Value, GUILayout.MaxWidth(300)); var refObj = ReferenceRoot.Instance.GetDynamic(item.Key); if (refObj) { if (GUILayout.Button(refObj.gameObject.name, OnGUIUtility.Styles.Title)) { Selection.activeGameObject = refObj.gameObject; } } else { GUILayout.Button("Null", OnGUIUtility.Styles.Title); } } EditorGUILayout.EndHorizontal(); } OnGUIUtility.Vision.EndBackGroundColor(); } } EditorGUILayout.EndScrollView(); }