Esempio n. 1
0
    public FadeArea BeginFadeArea(bool open, string label, string id, GUIStyle areaStyle, GUIStyle labelStyle)
    {
        //Rect r = EditorGUILayout.BeginVertical (areaStyle);

        Color tmp1 = GUI.color;

        FadeArea fadeArea = BeginFadeArea(open, id, 20, areaStyle);
        //GUI.Box (r,"",areaStyle);

        Color tmp2 = GUI.color;

        GUI.color = tmp1;

        if (label != "")
        {
            if (GUILayout.Button(label, labelStyle))
            {
                fadeArea.open = !fadeArea.open;
                editor.Repaint();
            }
        }

        GUI.color = tmp2;

        //EditorGUILayout.EndVertical ();
        return(fadeArea);
    }
Esempio n. 2
0
    public void EndFadeArea()
    {
        if (stack.Count <= 0)
        {
            Debug.LogError("You are popping more Fade Areas than you are pushing, make sure they are balanced");
            return;
        }

        FadeArea fadeArea = stack.Pop();

        //Debug.Log (r);
        //fadeArea.tmp = r;

        //r.width = 10;
        //r.height = 10;
        //GUI.Box (r,"");
        //GUILayout.Label ("HEllo : ");
        EditorGUILayout.EndVertical();
        GUILayout.EndArea();

        if (fade)
        {
            GUI.color = fadeArea.preFadeColor;
        }
        //GUILayout.Label ("Outside");

        /*currentDepth--;
         *
         * Rect r = GUILayoutUtility.GetRect (new GUIContent (),stretchStyle,GUILayout.Height (0));
         *
         * if (Event.current.type == EventType.Repaint || Event.current.type == EventType.ScrollWheel) {
         *      Rect currentRect = currentRects[id];
         *      Rect newRect = new Rect (currentRect.x,currentRect.y,currentRect.width,r.y-minHeight);
         *
         *      currentRects[id] = newRect;
         *
         *      if (lastRects[id] != newRect) {
         *              changedDelta = true;
         *              lastUpdate = Time.realtimeSinceStartup;
         *              editor.Repaint ();
         *      }
         *
         * }
         *
         * GUILayout.EndArea ();*/
    }
Esempio n. 3
0
    public void EndFadeArea()
    {
        if (fadeAreaStack.Count <= 0)
        {
            Debug.LogError("You are popping more Fade Areas than you are pushing, make sure they are balanced");
            return;
        }

        FadeArea fadeArea = fadeAreaStack.Pop();

        EditorGUILayout.EndVertical();
        GUILayout.EndArea();

        if (fade)
        {
            GUI.color = fadeArea.preFadeColor;
        }
    }
Esempio n. 4
0
        public FadeArea BeginFadeArea(bool open, string label, string id, GUIStyle areaStyle, GUIStyle labelStyle)
        {
            Color tmp1 = GUI.color;

            FadeArea fadeArea = BeginFadeArea(open, id, 20, areaStyle);
            Color    tmp2     = GUI.color;

            GUI.color = tmp1;

            if (label != "")
            {
                if (GUILayout.Button(label, labelStyle))
                {
                    fadeArea.open = !fadeArea.open;
                    editor.Repaint();
                }
            }

            GUI.color = tmp2;
            return(fadeArea);
        }
Esempio n. 5
0
    public FadeArea BeginFadeArea(bool open, string id, float minHeight, GUIStyle areaStyle)
    {
        //if (editor == null)
        //{
        //    Debug.LogError("You need to set the 'EditorGUIx.editor' variable before calling this function");
        //    return null;
        //}

        if (fadeAreaStack == null)
        {
            fadeAreaStack = new Stack <FadeArea>();
        }

        if (fadeAreas == null)
        {
            fadeAreas = new Dictionary <string, FadeArea>();
        }

        FadeArea fadeArea;

        if (!fadeAreas.TryGetValue(id, out fadeArea))
        {
            fadeArea = new FadeArea(open);
            fadeAreas.Add(id, fadeArea);
        }

        fadeAreaStack.Push(fadeArea);

        fadeArea.open = open;

        // Make sure the area fills the full width
        areaStyle.stretchWidth = true;

        Rect lastRect = fadeArea.lastRect;

        if (!fancyEffects)
        {
            fadeArea.value   = open ? 1F : 0F;
            lastRect.height -= minHeight;
            lastRect.height  = open ? lastRect.height : 0;
            lastRect.height += minHeight;
        }
        else
        {
            lastRect.height  = lastRect.height < minHeight ? minHeight : lastRect.height;
            lastRect.height -= minHeight;
            float faded = Hermite(0F, 1F, fadeArea.value);
            lastRect.height *= faded;
            lastRect.height += minHeight;
            lastRect.height  = Mathf.Round(lastRect.height);
        }

        Rect gotLastRect = GUILayoutUtility.GetRect(new GUIContent(), areaStyle, GUILayout.Height(lastRect.height));

        //The clipping area, also drawing background
        GUILayout.BeginArea(lastRect, areaStyle);

        Rect newRect = EditorGUILayout.BeginVertical();

        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      += areaStyle.padding.top + areaStyle.padding.bottom;
            fadeArea.currentRect = newRect;

            if (fadeArea.lastRect != newRect)
            {
                //@Fix - duplicate
                //fadeArea.lastUpdate = Time.realtimeSinceStartup;
                //editor.Repaint();
            }

            fadeArea.Switch();
        }

        if (Event.current.type == EventType.Repaint)
        {
            float value       = fadeArea.value;
            float targetValue = open ? 1F : 0F;

            float newRectHeight = fadeArea.lastRect.height;
            float deltaHeight   = 400F / newRectHeight;

            float deltaTime = Mathf.Clamp(Time.realtimeSinceStartup - fadeAreas[id].lastUpdate, 0.00001F, 0.05F);

            deltaTime *= Mathf.Lerp(deltaHeight * deltaHeight * 0.01F, 0.8F, 0.9F);

            fadeAreas[id].lastUpdate = Time.realtimeSinceStartup;


            if (Mathf.Abs(targetValue - value) > 0.001F)
            {
                float time = Mathf.Clamp01(deltaTime * speed);
                value += time * Mathf.Sign(targetValue - value);
                //editor.Repaint();
            }
            else
            {
                value = Mathf.Round(value);
            }

            fadeArea.value = Mathf.Clamp01(value);
        }

        if (fade)
        {
            Color c = GUI.color;
            fadeArea.preFadeColor = c;
            c.a      *= fadeArea.value;
            GUI.color = c;
        }

        fadeArea.open = open;

        return(fadeArea);
    }
Esempio n. 6
0
    public FadeArea BeginFadeArea(bool open, string id, float minHeight, GUIStyle areaStyle)
    {
        if (editor == null)
        {
            Debug.LogError("You need to set the 'EditorGUIx.editor' variable before calling this function");
            return(null);
        }

        if (stretchStyle == null)
        {
            stretchStyle = new GUIStyle();
            stretchStyle.stretchWidth = true;
            //stretchStyle.padding = new RectOffset (0,0,4,14);
            //stretchStyle.margin = new RectOffset (0,0,4,4);
        }

        if (stack == null)
        {
            stack = new Stack <FadeArea>();
        }

        if (fadeAreas == null)
        {
            fadeAreas = new Dictionary <string, FadeArea> ();
        }

        if (!fadeAreas.ContainsKey(id))
        {
            fadeAreas.Add(id, new FadeArea(open));
        }

        FadeArea fadeArea = fadeAreas[id];

        stack.Push(fadeArea);

        fadeArea.open = open;

        //Make sure the area fills the full width
        areaStyle.stretchWidth = true;

        Rect lastRect = fadeArea.lastRect;

        if (!fancyEffects)
        {
            fadeArea.value   = open ? 1F : 0F;
            lastRect.height -= minHeight;
            lastRect.height  = open ? lastRect.height : 0;
            lastRect.height += minHeight;
        }
        else
        {
            //GUILayout.Label (lastRect.ToString ()+"\n"+fadeArea.tmp.ToString (),EditorStyles.miniLabel);
            lastRect.height  = lastRect.height < minHeight ? minHeight : lastRect.height;
            lastRect.height -= minHeight;
            float faded = Hermite(0F, 1F, fadeArea.value);
            lastRect.height *= faded;
            lastRect.height += minHeight;
            lastRect.height  = Mathf.Round(lastRect.height);
            //lastRect.height *= 2;
            //if (Event.current.type == EventType.Repaint) {
            //	isLayout = false;
            //}
        }

        //Rect stretchWidthRect = GUILayoutUtility.GetRect (new GUIContent (), stretchStyle,GUILayout.Height (0));


        Rect gotLastRect = GUILayoutUtility.GetRect(new GUIContent(), areaStyle, GUILayout.Height(lastRect.height));

        //Debug.Log (Event.current.type +" "+lastRect);

        //The clipping area, also drawing background
        GUILayout.BeginArea(lastRect, areaStyle);

        Rect newRect = EditorGUILayout.BeginVertical();

        if (Event.current.type == EventType.Repaint || Event.current.type == EventType.ScrollWheel)
        {
            newRect.x            = gotLastRect.x;
            newRect.y            = gotLastRect.y;
            newRect.width        = gotLastRect.width;     //stretchWidthRect.width;
            newRect.height      += areaStyle.padding.top + areaStyle.padding.bottom;
            fadeArea.currentRect = newRect;

            if (fadeArea.lastRect != newRect)
            {
                //@Fix - duplicate
                //fadeArea.lastUpdate = Time.realtimeSinceStartup;
                editor.Repaint();
            }

            fadeArea.Switch();
        }
        if (Event.current.type == EventType.Repaint)
        {
            float value       = fadeArea.value;
            float targetValue = open ? 1F : 0F;

            float newRectHeight = fadeArea.lastRect.height;
            float deltaHeight   = 400F / newRectHeight;

            float deltaTime = Mathf.Clamp(Time.realtimeSinceStartup - fadeAreas[id].lastUpdate, 0.00001F, 0.05F);

            deltaTime *= Mathf.Lerp(deltaHeight * deltaHeight * 0.01F, 0.8F, 0.9F);

            fadeAreas[id].lastUpdate = Time.realtimeSinceStartup;

            //Useless, but fun feature
            if (Event.current.shift)
            {
                deltaTime *= 0.05F;
            }

            if (Mathf.Abs(targetValue - value) > 0.001F)
            {
                float time = Mathf.Clamp01(deltaTime * speed);
                value += time * Mathf.Sign(targetValue - value);
                editor.Repaint();
            }
            else
            {
                value = Mathf.Round(value);
            }

            fadeArea.value = Mathf.Clamp01(value);

            //if (oldValue != value) {
            //	editor.Repaint ();
            //}
        }

        if (fade)
        {
            Color c = GUI.color;
            fadeArea.preFadeColor = c;
            c.a      *= fadeArea.value;
            GUI.color = c;
        }

        fadeArea.open = open;

        //GUILayout.Label ("Alpha : "+fadeArea.value);
        //GUILayout.Label ("Alpha : "+fadeArea.value);GUILayout.Label ("Alpha : "+fadeArea.value);GUILayout.Label ("Alpha : "+fadeArea.value);GUILayout.Label ("Alpha : "+fadeArea.value);

        /*GUILayout.Label ("Testing");
        *  GUILayout.Label ("Testing");
        *       GUILayout.Label ("Testing");
        *               GUILayout.Label ("Testing");*/


        return(fadeArea);
    }
		public FadeArea BeginFadeArea (bool open, string id, float minHeight, GUIStyle areaStyle) {

			if (editor == null) {
				Debug.LogError ("You need to set the 'EditorGUIx.editor' variable before calling this function");
				return null;
			}

			if (fadeAreaStack == null) {
				fadeAreaStack = new Stack<FadeArea>();
			}

			if (fadeAreas == null) {
				fadeAreas = new Dictionary<string, FadeArea> ();
			}

			FadeArea fadeArea;
			if (!fadeAreas.TryGetValue (id, out fadeArea)) {
				fadeArea = new FadeArea (open);
				fadeAreas.Add (id, fadeArea);
			}

			fadeAreaStack.Push (fadeArea);

			fadeArea.open = open;

			// Make sure the area fills the full width
			areaStyle.stretchWidth = true;

			Rect lastRect = fadeArea.lastRect;

			if (!fancyEffects) {
				fadeArea.value = open ? 1F : 0F;
				lastRect.height -= minHeight;
				lastRect.height = open ? lastRect.height : 0;
				lastRect.height += minHeight;
			} else {
				lastRect.height = lastRect.height < minHeight ? minHeight : lastRect.height;
				lastRect.height -= minHeight;
				float faded = Hermite (0F,1F,fadeArea.value);
				lastRect.height *= faded;
				lastRect.height += minHeight;
				lastRect.height = Mathf.Round (lastRect.height);
			}

			Rect gotLastRect = GUILayoutUtility.GetRect (new GUIContent (), areaStyle, GUILayout.Height (lastRect.height));

			//The clipping area, also drawing background
			GUILayout.BeginArea (lastRect,areaStyle);

			Rect newRect = EditorGUILayout.BeginVertical ();

			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 += areaStyle.padding.top+ areaStyle.padding.bottom;
				fadeArea.currentRect = newRect;

				if (fadeArea.lastRect != newRect) {
					//@Fix - duplicate
					//fadeArea.lastUpdate = Time.realtimeSinceStartup;
					editor.Repaint ();
				}

				fadeArea.Switch ();
			}

			if (Event.current.type == EventType.Repaint) {
				float value = fadeArea.value;
				float targetValue = open ? 1F : 0F;

				float newRectHeight = fadeArea.lastRect.height;
				float deltaHeight = 400F / newRectHeight;

				float deltaTime = Mathf.Clamp (Time.realtimeSinceStartup-fadeAreas[id].lastUpdate,0.00001F,0.05F);

				deltaTime *= Mathf.Lerp (deltaHeight*deltaHeight*0.01F, 0.8F, 0.9F);

				fadeAreas[id].lastUpdate = Time.realtimeSinceStartup;


				if (Mathf.Abs(targetValue-value) > 0.001F) {
					float time = Mathf.Clamp01 (deltaTime*speed);
					value += time*Mathf.Sign (targetValue-value);
					editor.Repaint ();
				} else {
					value = Mathf.Round (value);
				}

				fadeArea.value = Mathf.Clamp01 (value);
			}

			if (fade) {
				Color c = GUI.color;
				fadeArea.preFadeColor = c;
				c.a *= fadeArea.value;
				GUI.color = c;
			}

			fadeArea.open = open;

			return fadeArea;
		}