Advertisement
Guest User

Untitled

a guest
Jun 9th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.65 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Internal;
  4. public static bool Foldout (Rect position, bool foldout, GUIContent content, bool toggleOnLabelClick, [DefaultValue ("EditorStyles.foldout")] GUIStyle style)
  5. {
  6.     Rect rect = position;
  7.     if (EditorGUIUtility.hierarchyMode)
  8.     {
  9.         int num = EditorStyles.foldout.padding.left - EditorStyles.label.padding.left;
  10.         position.xMin -= (float)num;
  11.     }
  12.     int controlID = GUIUtility.GetControlID (EditorGUI.s_FoldoutHash, EditorGUIUtility.native, position);
  13.     EventType eventType = Event.current.type;
  14.     if (!GUI.enabled && GUIClip.enabled && (Event.current.rawType == EventType.MouseDown || Event.current.rawType == EventType.MouseDrag || Event.current.rawType == EventType.MouseUp))
  15.     {
  16.         eventType = Event.current.rawType;
  17.     }
  18.     EventType eventType2 = eventType;
  19.     switch (eventType2)
  20.     {
  21.     case EventType.MouseDown:
  22.         if (position.Contains (Event.current.mousePosition) && Event.current.button == 0)
  23.         {
  24.             int num2 = controlID;
  25.             GUIUtility.hotControl = num2;
  26.             GUIUtility.keyboardControl = num2;
  27.             Event.current.Use ();
  28.         }
  29.         return foldout;
  30.     case EventType.MouseUp:
  31.         if (GUIUtility.hotControl == controlID)
  32.         {
  33.             GUIUtility.hotControl = 0;
  34.             Event.current.Use ();
  35.             Rect rect2 = position;
  36.             if (!toggleOnLabelClick)
  37.             {
  38.                 rect2.width = (float)style.padding.left;
  39.                 rect2.x += EditorGUI.indent;
  40.             }
  41.             if (rect2.Contains (Event.current.mousePosition))
  42.             {
  43.                 GUI.changed = true;
  44.                 return !foldout;
  45.             }
  46.         }
  47.         return foldout;
  48.     case EventType.MouseMove:
  49.     case EventType.KeyUp:
  50.     case EventType.ScrollWheel:
  51.     case EventType.Layout:
  52.         IL_D8:
  53.         if (eventType2 != EventType.DragExited)
  54.         {
  55.             return foldout;
  56.         }
  57.         if (EditorGUI.s_DragUpdatedOverID == controlID)
  58.         {
  59.             EditorGUI.s_DragUpdatedOverID = 0;
  60.             Event.current.Use ();
  61.         }
  62.         return foldout;
  63.     case EventType.MouseDrag:
  64.         if (GUIUtility.hotControl == controlID)
  65.         {
  66.             Event.current.Use ();
  67.         }
  68.         return foldout;
  69.     case EventType.KeyDown:
  70.         if (GUIUtility.keyboardControl == controlID)
  71.         {
  72.             KeyCode keyCode = Event.current.keyCode;
  73.             if ((keyCode == KeyCode.LeftArrow && foldout) || (keyCode == KeyCode.RightArrow && !foldout))
  74.             {
  75.                 foldout = !foldout;
  76.                 GUI.changed = true;
  77.                 Event.current.Use ();
  78.             }
  79.         }
  80.         return foldout;
  81.     case EventType.Repaint:
  82.     {
  83.         EditorStyles.foldoutSelected.Draw (position, GUIContent.none, controlID, EditorGUI.s_DragUpdatedOverID == controlID);
  84.         Rect position2 = new Rect (position.x + EditorGUI.indent, position.y, EditorGUIUtility.labelWidth - EditorGUI.indent, position.height);
  85.         if (EditorGUI.showMixedValue && !foldout)
  86.         {
  87.             style.Draw (position2, content, controlID, foldout);
  88.             EditorGUI.BeginHandleMixedValueContentColor ();
  89.             Rect position3 = rect;
  90.             position3.xMin += EditorGUIUtility.labelWidth;
  91.             EditorStyles.label.Draw (position3, EditorGUI.s_MixedValueContent, controlID, false);
  92.             EditorGUI.EndHandleMixedValueContentColor ();
  93.         }
  94.         else
  95.         {
  96.             style.Draw (position2, content, controlID, foldout);
  97.         }
  98.         return foldout;
  99.     }
  100.     case EventType.DragUpdated:
  101.         if (EditorGUI.s_DragUpdatedOverID == controlID)
  102.         {
  103.             if (position.Contains (Event.current.mousePosition))
  104.             {
  105.                 if ((double)Time.realtimeSinceStartup > EditorGUI.s_FoldoutDestTime)
  106.                 {
  107.                     foldout = true;
  108.                     Event.current.Use ();
  109.                 }
  110.             }
  111.             else
  112.             {
  113.                 EditorGUI.s_DragUpdatedOverID = 0;
  114.             }
  115.         }
  116.         else
  117.         {
  118.             if (position.Contains (Event.current.mousePosition))
  119.             {
  120.                 EditorGUI.s_DragUpdatedOverID = controlID;
  121.                 EditorGUI.s_FoldoutDestTime = (double)Time.realtimeSinceStartup + 0.7;
  122.                 Event.current.Use ();
  123.             }
  124.         }
  125.         return foldout;
  126.     }
  127.     goto IL_D8;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement