public virtual bool DrawCommonInspector() { EditorGUI.BeginChangeCheck(); serializedObject.Update(); SerializedProperty spScript = serializedObject.FindProperty("m_Script"); if (spScript != null) { using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.PropertyField(spScript, true); } } bool inGroup = false; for (int i = 0; i < _fieldList.Count; i++) { FieldInfo fi = _fieldList[i]; SerializedProperty sp = serializedObject.FindProperty(fi.Name); GroupAttribute ga = GetGroupAttrByMemberName(sp.propertyPath); if (ga != null && ga.State != GroupAttribute.EState.EndGroup) { if (inGroup) { GUILayout.EndVertical(); inGroup = false; } DrawGroupHeader(ga); inGroup = DrawGroupContentBg(ga); } EditorGUILayout.PropertyField(sp, true); if (ga != null && ga.State != GroupAttribute.EState.StartGroup) { GUILayout.EndVertical(); inGroup = false; } } if (inGroup) { GUILayout.EndVertical(); inGroup = false; } serializedObject.ApplyModifiedProperties(); return(EditorGUI.EndChangeCheck()); }
private void DrawGroupHeader(GroupAttribute ga) { if (ga == null || ga.State == GroupAttribute.EState.EndGroup) { return; } Color prevColor = GUI.backgroundColor; GUI.backgroundColor = ga.Title != null ? new Color(0.8f, 0.9f, 0.99f) : new Color(0.78f, 0.78f, 0.78f); GUILayout.Label(ga.Title, ga.Title != null ? GS.gsGroupTitle1 : GS.gsGroupTitle2); GUI.backgroundColor = prevColor; }
private void DrawMethodButtons() { // Draw Head if (_buttonMethodAttrList.Count > 0) { GUILayout.BeginHorizontal(); { GUILayout.Label("", GS.gsSpliterLine); GUILayout.Button("Method", GS.gsSpliterText); GUILayout.Label("", GS.gsSpliterLine); } GUILayout.EndHorizontal(); } bool inGroup = false; for (int i = 0; i < _buttonMethodAttrList.Count; i++) { KeyValuePair <MethodInfo, Attribute> pair = _buttonMethodAttrList[i]; if (pair.Key.GetParameters().Length > 0) { continue; } ButtonAttribute attr = pair.Value as ButtonAttribute; GroupAttribute ga = (_groupMemberAttrDic.ContainsKey(pair.Key) ? _groupMemberAttrDic[pair.Key] : null) as GroupAttribute; if (ga != null && ga.State != GroupAttribute.EState.EndGroup) { if (inGroup) { GUILayout.EndVertical(); inGroup = false; } DrawGroupHeader(ga); inGroup = DrawGroupContentBg(ga); } Color prevColor = GUI.backgroundColor; GUI.backgroundColor = attr.BgColor; //bool click = GUILayout.Button( attr.Name, attr.Style); var name = string.IsNullOrEmpty(attr.Name) ? pair.Key.Name.BigCamel() : attr.Name; bool click = GUILayout.Button(name, attr.Style); GUI.backgroundColor = prevColor; if (click) { for (int j = 0; j < targets.Length; j++) { pair.Key.Invoke(targets[j], null); } } if (ga != null && ga.State != GroupAttribute.EState.StartGroup) { GUILayout.EndVertical(); inGroup = false; } } if (inGroup) { GUILayout.EndVertical(); inGroup = false; } }
private void DrawShowProperties() { // 不支持多选 if (targets.Length != 1) { return; } // Draw Head if (_showPropertyAttrList.Count > 0) { GUILayout.BeginHorizontal(); { GUILayout.Label("", GS.gsSpliterLine); GUILayout.Button("Property", GS.gsSpliterText); GUILayout.Label("", GS.gsSpliterLine); } GUILayout.EndHorizontal(); } bool inGroup = false; for (int i = 0; i < _showPropertyAttrList.Count; i++) { KeyValuePair <PropertyInfo, Attribute> pair = _showPropertyAttrList[i]; PropertyInfo info = pair.Key; ShowPropertyAttribute attr = pair.Value as ShowPropertyAttribute; GroupAttribute ga = (_groupMemberAttrDic.ContainsKey(info) ? _groupMemberAttrDic[info] : null) as GroupAttribute; if (ga != null && ga.State != GroupAttribute.EState.EndGroup) { if (inGroup) { GUILayout.EndVertical(); inGroup = false; } DrawGroupHeader(ga); inGroup = DrawGroupContentBg(ga); } if (attr.ValueType == ShowPropertyAttribute.EValueType.Enum) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is Enum) { Enum value = (Enum)rawValue; Enum newValue = EditorGUILayout.EnumPopup(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.Bool) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is bool) { bool value = (bool)rawValue; bool newValue = EditorGUILayout.Toggle(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.Int) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is int) { int value = (int)rawValue; int newValue = EditorGUILayout.IntField(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.Float) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is float) { float value = (float)rawValue; float newValue = EditorGUILayout.FloatField(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.String) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is string) { string value = rawValue as string ?? string.Empty; string newValue = EditorGUILayout.TextField(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.Vector2) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is Vector2) { Vector2 value = (Vector2)rawValue; Vector2 newValue = EditorGUILayout.Vector2Field(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.Vector3) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is Vector3) { Vector3 value = (Vector3)rawValue; Vector3 newValue = EditorGUILayout.Vector3Field(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } else if (attr.ValueType == ShowPropertyAttribute.EValueType.Vector4) { if (info.CanRead) { object rawValue = info.GetValue(target, null); if (rawValue is Vector4) { Vector4 value = (Vector4)rawValue; Vector4 newValue = EditorGUILayout.Vector4Field(info.Name, value); if (info.CanWrite && value != newValue) { info.SetValue(target, newValue, null); } } } } if (ga != null && ga.State != GroupAttribute.EState.StartGroup) { GUILayout.EndVertical(); inGroup = false; } } if (inGroup) { GUILayout.EndVertical(); inGroup = false; } }