Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.Internal;
- public static bool Foldout (Rect position, bool foldout, GUIContent content, bool toggleOnLabelClick, [DefaultValue ("EditorStyles.foldout")] GUIStyle style)
- {
- Rect rect = position;
- if (EditorGUIUtility.hierarchyMode)
- {
- int num = EditorStyles.foldout.padding.left - EditorStyles.label.padding.left;
- position.xMin -= (float)num;
- }
- int controlID = GUIUtility.GetControlID (EditorGUI.s_FoldoutHash, EditorGUIUtility.native, position);
- EventType eventType = Event.current.type;
- if (!GUI.enabled && GUIClip.enabled && (Event.current.rawType == EventType.MouseDown || Event.current.rawType == EventType.MouseDrag || Event.current.rawType == EventType.MouseUp))
- {
- eventType = Event.current.rawType;
- }
- EventType eventType2 = eventType;
- switch (eventType2)
- {
- case EventType.MouseDown:
- if (position.Contains (Event.current.mousePosition) && Event.current.button == 0)
- {
- int num2 = controlID;
- GUIUtility.hotControl = num2;
- GUIUtility.keyboardControl = num2;
- Event.current.Use ();
- }
- return foldout;
- case EventType.MouseUp:
- if (GUIUtility.hotControl == controlID)
- {
- GUIUtility.hotControl = 0;
- Event.current.Use ();
- Rect rect2 = position;
- if (!toggleOnLabelClick)
- {
- rect2.width = (float)style.padding.left;
- rect2.x += EditorGUI.indent;
- }
- if (rect2.Contains (Event.current.mousePosition))
- {
- GUI.changed = true;
- return !foldout;
- }
- }
- return foldout;
- case EventType.MouseMove:
- case EventType.KeyUp:
- case EventType.ScrollWheel:
- case EventType.Layout:
- IL_D8:
- if (eventType2 != EventType.DragExited)
- {
- return foldout;
- }
- if (EditorGUI.s_DragUpdatedOverID == controlID)
- {
- EditorGUI.s_DragUpdatedOverID = 0;
- Event.current.Use ();
- }
- return foldout;
- case EventType.MouseDrag:
- if (GUIUtility.hotControl == controlID)
- {
- Event.current.Use ();
- }
- return foldout;
- case EventType.KeyDown:
- if (GUIUtility.keyboardControl == controlID)
- {
- KeyCode keyCode = Event.current.keyCode;
- if ((keyCode == KeyCode.LeftArrow && foldout) || (keyCode == KeyCode.RightArrow && !foldout))
- {
- foldout = !foldout;
- GUI.changed = true;
- Event.current.Use ();
- }
- }
- return foldout;
- case EventType.Repaint:
- {
- EditorStyles.foldoutSelected.Draw (position, GUIContent.none, controlID, EditorGUI.s_DragUpdatedOverID == controlID);
- Rect position2 = new Rect (position.x + EditorGUI.indent, position.y, EditorGUIUtility.labelWidth - EditorGUI.indent, position.height);
- if (EditorGUI.showMixedValue && !foldout)
- {
- style.Draw (position2, content, controlID, foldout);
- EditorGUI.BeginHandleMixedValueContentColor ();
- Rect position3 = rect;
- position3.xMin += EditorGUIUtility.labelWidth;
- EditorStyles.label.Draw (position3, EditorGUI.s_MixedValueContent, controlID, false);
- EditorGUI.EndHandleMixedValueContentColor ();
- }
- else
- {
- style.Draw (position2, content, controlID, foldout);
- }
- return foldout;
- }
- case EventType.DragUpdated:
- if (EditorGUI.s_DragUpdatedOverID == controlID)
- {
- if (position.Contains (Event.current.mousePosition))
- {
- if ((double)Time.realtimeSinceStartup > EditorGUI.s_FoldoutDestTime)
- {
- foldout = true;
- Event.current.Use ();
- }
- }
- else
- {
- EditorGUI.s_DragUpdatedOverID = 0;
- }
- }
- else
- {
- if (position.Contains (Event.current.mousePosition))
- {
- EditorGUI.s_DragUpdatedOverID = controlID;
- EditorGUI.s_FoldoutDestTime = (double)Time.realtimeSinceStartup + 0.7;
- Event.current.Use ();
- }
- }
- return foldout;
- }
- goto IL_D8;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement