public XArea BeginXArea(string id, GUIStyle style, float minHeight, EArea type, SerializedProperty bobj, float offset) { GUIStyle buttonStyle = EffectLayerCustom.Xbutton; if (!XAreas.ContainsKey(id)) { XAreas.Add(id, new XArea()); } //find my area. XArea m = XAreas[id]; style.stretchWidth = true; Rect gotLastRect = GUILayoutUtility.GetRect(new GUIContent(), style, GUILayout.Height(m.LastRect.height)); if (m.Open) { buttonStyle = EffectLayerCustom.XbuttonClicked; } GUILayout.BeginArea(m.LastRect, style); Rect newRect = EditorGUILayout.BeginVertical(); //head bar EditorGUILayout.BeginHorizontal(); if (type == EArea.CheckBox || type == EArea.AlwaysToggle) { if (type == EArea.CheckBox) { //little trick. m.Enable = bobj.boolValue; m.Enable = GUILayout.Toggle(m.Enable, GUIContent.none, EffectLayerCustom.Xtoggle, GUILayout.Width(18f), GUILayout.Height(18f)); bobj.boolValue = m.Enable; } else { m.Open = GUILayout.Toggle(m.Open, GUIContent.none, EffectLayerCustom.XToggle2, GUILayout.Width(18f), GUILayout.Height(18f)); m.Enable = true; } if (GUILayout.Button(id, buttonStyle, GUILayout.Height(20f))) { MyEditor.Repaint(); m.Open = !m.Open; } } else if (type == EArea.Texture) { Texture tex = null; string mname = "no material"; if (MyEditor.Script.Material != null) { tex = MyEditor.Script.Material.mainTexture; mname = MyEditor.Script.Material.name; } GUILayout.Label(new GUIContent(tex), EffectLayerCustom.XTexture, GUILayout.Width(25f), GUILayout.Height(25f)); if (GUILayout.Button(mname, buttonStyle, GUILayout.Height(24f))) { MyEditor.Repaint(); m.Open = !m.Open; } m.Enable = true; } //increase a bit, need to do this. newRect.height += 3f; newRect.height += offset; EditorGUILayout.EndHorizontal(); GUI.enabled = m.Enable; if (!m.Open) { newRect.height = minHeight; } //calculate area size. if (Event.current.type == EventType.Repaint || Event.current.type == EventType.ScrollWheel) { newRect.x = gotLastRect.x; newRect.y = gotLastRect.y; newRect.width = gotLastRect.width; newRect.height += style.padding.top + style.padding.bottom; if (m.LastRect != newRect) { m.LastRect = newRect; MyEditor.Repaint(); } } return(m); }
public XArea BeginCommonArea(string id, string name, Editor editor, bool forceOpen) { GUIStyle buttonStyle = EffectLayerCustom.Xbutton; GUIStyle style = EffectLayerCustom.XArea; if (!XAreas.ContainsKey(id)) { XAreas.Add(id, new XArea()); } //find my area. XArea m = XAreas[id]; style.stretchWidth = true; Rect gotLastRect = GUILayoutUtility.GetRect(new GUIContent(), style, GUILayout.Height(m.LastRect.height)); GUILayout.BeginArea(m.LastRect, style); Rect newRect = EditorGUILayout.BeginVertical(); //head bar EditorGUILayout.BeginHorizontal(); m.Open = GUILayout.Toggle(m.Open, GUIContent.none, EffectLayerCustom.XToggle2, GUILayout.Width(18f), GUILayout.Height(18f)); m.Enable = true; if (GUILayout.Button(name, buttonStyle, GUILayout.Height(20f))) { m.Open = !m.Open; } if (forceOpen) { m.Open = true; } //increase a bit, need to do this. newRect.height += 3f; EditorGUILayout.EndHorizontal(); GUI.enabled = m.Enable; if (!m.Open) { newRect.height = MinHeight; } //calculate area size. if (Event.current.type == EventType.Repaint || Event.current.type == EventType.ScrollWheel) { newRect.x = gotLastRect.x; newRect.y = gotLastRect.y; newRect.width = gotLastRect.width; newRect.height += style.padding.top + style.padding.bottom; if (m.LastRect != newRect) { m.LastRect = newRect; editor.Repaint(); } } return(m); }