Esempio n. 1
0
        void OnGUI()
        {
            if (!SceneManager.GetActiveScene().IsValid())
            {
                return;
            }

            if (!currentWindow)
            {
                currentWindow = Resources.FindObjectsOfTypeAll(Params.WindowType).FirstOrDefault() as EditorWindow;
                if (currentWindow)
                {
                    ResetWindow();
                }
            }
            if (!currentWindow)
            {
                return;
            }

            if (SceneManager.GetActiveScene().GetHashCode() != EditorPrefs.GetInt("EModules/" + Params.TITLE + "/Scene", -1))
            {
                ResetWindow();
            }

            if (Params.Label == null)
            {
                Params.Label           = new GUIStyle(GUI.skin.label);
                Params.Label.fontSize  = 14;
                Params.Label.fontStyle = FontStyle.Bold;

                Params.Button = new GUIStyle(GUI.skin.button);
                // Button.fontSize = 14;
                var t = new Texture2D(1, 1, TextureFormat.ARGB32, false, true);
                t.hideFlags = HideFlags.DontSave;
                t.SetPixel(0, 0, new Color(0, 0.1f, 0.4f, 0.3f));
                t.Apply();
                Params.Button.normal.background  = null;
                Params.Button.hover.background   = null;
                Params.Button.focused.background = null;
                Params.Button.active.background  = t;
            }


            if (!Camera.main)
            {
                GUILayout.Label("No Camera", Params.Label);
                return;
            }

            ISupportedPostComponent currentComponent = null;
            MonoBehaviour           c1 = null;
            MonoBehaviour           c2 = null;

            if (Params.PostProcessingBehaviourType != null)
            {
                c1 = Camera.main.GetComponent(Params.PostProcessingBehaviourType) as MonoBehaviour;
            }
            if (Params.AmplifyBaseType != null)
            {
                c2 = Camera.main.GetComponent(Params.AmplifyBaseType) as MonoBehaviour;
            }

            if (c1 && c1.enabled)
            {
                currentComponent = postPresets_UnityPostGUI;
            }
            else if (c2 && c2.enabled)
            {
                currentComponent = postPresets_AmplifyPostGUI;
            }
            else if (c1)
            {
                currentComponent = postPresets_UnityPostGUI;
            }
            else if (c2)
            {
                currentComponent = postPresets_AmplifyPostGUI;
            }
            else if (Params.PostProcessingBehaviourType != null)
            {
                currentComponent = postPresets_UnityPostGUI;
            }
            else if (Params.AmplifyBaseType != null)
            {
                currentComponent = postPresets_AmplifyPostGUI;
            }


            if (currentComponent == null)
            {
                GUILayout.Label("Unity PostProcessing or AmplifyColor not imported", Params.Label);
                if (GUILayout.Button("Download Unity 'Post Processing Stack'", GUILayout.Height(40)))
                {
                    Application.OpenURL("https://www.assetstore.unity3d.com/#!/content/83912");
                }
                if (GUILayout.Button("Download 'Amplify Color'", GUILayout.Height(40)))
                {
                    Application.OpenURL(" https://www.assetstore.unity3d.com/en/#!/content/1894");
                }
                return;
            }


            // Left column ////
            GUILayout.BeginHorizontal();
            var leftwidth = Mathf.Clamp(position.width / 3f, 200, 350);

            GUILayout.BeginVertical(GUILayout.Width(leftwidth));
            GUILayout.Label("Camera: " + Camera.main.name, Params.Label);
            if (GUI.Button(GUILayoutUtility.GetLastRect(), "", Params.Button))
            {
                Selection.objects = new[] { Camera.main.gameObject }
            }
            ;
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);


            if (currentComponent.MonoComponent == null)
            {
                if (GUILayout.Button("Add " + currentComponent.MonoComponentType + " Script", GUILayout.Height(200)))
                {
                    Undo.RecordObject(Camera.main.gameObject, "Add " + currentComponent.MonoComponentType + " Script");
                    Camera.main.gameObject.AddComponent(currentComponent.MonoComponentType);
                    EditorUtility.SetDirty(Camera.main.gameObject);
                }
                return;
            }

            if (!currentComponent.MonoComponent.enabled)
            {
                GUILayout.Label(currentComponent.MonoComponent.GetType().Name + " Component Disabled", Params.Label);
                if (GUILayout.Button("Enable " + currentComponent.MonoComponent.GetType().Name + " Component", GUILayout.Height(200)))
                {
                    Undo.RecordObject(currentComponent.MonoComponent, "Enable " + currentComponent.MonoComponent.GetType().Name + " Component");
                    currentComponent.MonoComponent.enabled = true;
                    EditorUtility.SetDirty(currentComponent.MonoComponent);
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
                return;
            }

            if (widthCheck == null)
            {
                widthCheck = position.width;
            }
            if (widthCheck.Value != position.width)
            {
                widthCheck = position.width;
                ClearImages(false);
                currentWindow.Repaint();
            }

            //! *** POSTPROCESSING COMPONENT GUI *** //
            currentComponent.LeftSideGUI(this, leftwidth);
            //! *** POSTPROCESSING COMPONENT GUI *** //

            if (GUILayout.Button("http://emodules.me/", Params.Button))
            {
                Application.OpenURL("http://emodules.me/");
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

            GUILayout.EndVertical();
            // Left column

            GUILayout.Space(10);

            leftwidth += 20;

            //! PRESETS GRID GUI
            if (currentComponent.IsValid)
            {
                GUILayout.BeginVertical();
                ////////////////////////
                currentComponent.TopFastButtonsGUI(this, leftwidth);
                ////////////////////////
                FiltresAndSorting(this, leftwidth);
                ////////////////////////
                DrawPresets(currentComponent);
                ////////////////////////
                GUILayout.EndVertical();
            }
            //! PRESETS GRID GUI

            GUILayout.EndHorizontal();
        }//!OnGUI

        void FiltresAndSorting(EditorWindow window, float leftWidth)
        {
#if !P128
            GUI.enabled = true;
#else
            GUI.enabled = false;
#endif

            // FILTRES
            //var filtresCount = filtername_to_filterindex.Values.Max();

            /*for (int i = 0 ; i < filtresCount ; i++)
             * {
             * var filtMask = 1 << i;
             * var enable = ((int)Params.filtres & filtMask) != 0;
             * var captureI=i;
             * var name = filtername_to_filterindex.Where(f=>f.Value == captureI).Select(f=>f.Key).Aggregate((a,b)=>a+'\n' +b);
             * if (Button( GetRect( leftWidth, 40, window, 8 ), name, enable ))
             * {
             *  if (enable) Params.filtres.Set( ((int)Params.filtres & ~filtMask) );
             *  else Params.filtres.Set( ((int)Params.filtres | filtMask) );
             *  renderedDoubleCheck = new Texture2D[gradients.Length];
             *  window.Repaint();
             * }
             * }*/
            GUILayout.BeginHorizontal();
            var lineR = GetRect(leftWidth, 16, window, 1); //SPACE
            GUILayout.EndHorizontal();
            var seaR = lineR;
            seaR.width  *= 0.7f;
            lineR.x     += seaR.width + 40;
            lineR.width -= seaR.width + 40;
            var newFilter = EditorGUI.TextField(seaR, "Search: ", (string)Params.filtres);
            if (newFilter != Params.filtres)
            {
                Params.filtres.Set(newFilter);
                window.Repaint();
            }
            seaR.x    += seaR.width;
            seaR.width = 20;
            if (GUI.Button(seaR, "X"))
            {
                Params.filtres.Set("");
                EditorGUI.FocusTextInControl(null);
                ClearImages(true);
                window.Repaint();
            }
            EditorGUIUtility.AddCursorRect(lineR, MouseCursor.Link);
            if (GUI.Button(lineR, "Show Favorites", Params.Button))
            {
                Params.showFav.Set(1 - Params.showFav);
                ClearImages(true);
                if (Params.showFav == 0)
                {
                    mayResetScroll = WasElementsChanged;
                }
                WasElementsChanged = false;
                window.Repaint();
            }
            if (Params.showFav == 1)
            {
                EditorGUI.DrawRect(lineR, new Color(0.8f, 0.6f, 0.33f, 0.4f));
            }
            lineR.x    += lineR.width;
            lineR.width = 16;
#if !P128
            GUI.DrawTexture(lineR, favicon_enable);
#endif
            // FILTRES


            // SORTING
            GUILayout.BeginHorizontal();
            var D = 8;
            var r = GetRect(leftWidth, 20, window, D);
            GUI.Label(r, "Sorting:");
            for (int i = 0; i < 4; i++)
            {
                var sortNotInverse = ((int)Params.sortInverse & (1 << i)) == 0;
                if (Button(GetRect(leftWidth, 20, window, D), sotrNames[i] + (Params.sortMode == i ? (sortNotInverse ? "▼" : "▲") : ""), Params.sortMode == i, "Set Ordering Method"))
                {
                    if (Params.sortMode == i)
                    {
                        if (!sortNotInverse)
                        {
                            Params.sortInverse.Set(((int)Params.sortInverse & ~(1 << i)));
                        }
                        else
                        {
                            Params.sortInverse.Set(((int)Params.sortInverse | (1 << i)));
                        }
                    }
                    else
                    {
                        Params.sortMode.Set((float)i);
                    }
                    ClearImages(true);
                    window.Repaint();
                }
            }

            GUI.enabled = true;

            GetRect(leftWidth, 20, window, D); //SPACE
            GUI.Label(GetRect(leftWidth, 20, window, D), "Zoom:");

            var ZoomRect = GetRect(leftWidth, 20, window, D);
            ZoomRect.width /= 3;
            for (int i = 0; i < 3; i++)
            {
                if (Button(ZoomRect, "x" + (i + 1) * 3, Params.zoomFactor == i, "Set Zooming Factor"))
                {
                    Params.zoomFactor.Set(i);
                    ClearImages(true);
                    window.Repaint();
                }
                ZoomRect.x += ZoomRect.width;
            }
            GUILayout.EndHorizontal();
            // SORTING
        }//!FiltresAndSorting

        Rect GetRect(float leftWidth, float height, EditorWindow window, int divider)
        {
            return(EditorGUILayout.GetControlRect(GUILayout.Width(Math.Min((window.position.width - leftWidth - 10 - 40) / divider, 700 / divider)), GUILayout.Height(height)));
        }

        bool Button(Rect rect, string name, bool enable, string helpTExt = null)
        {
            if (enable)
            {
                EditorGUI.DrawRect(rect, new Color(0.33f, 0.6f, 0.8f, 0.4f));
            }
            EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
            var content = Params.CONTENT(name, helpTExt ?? "enable/disable " + name.Replace('\n', ' '));
            var result  = (GUI.Button(rect, content));

            //if (enable) EditorGUI.DrawRect( rect, new Color( 0.33f, 0.6f, 0.8f, 0.4f ) );
            if (Event.current.type == EventType.Repaint && enable)
            {
                GUI.skin.button.Draw(rect, content, true, true, true, true);
            }
            if (enable)
            {
                EditorGUI.DrawRect(rect, new Color(0.33f, 0.6f, 0.8f, 0.4f));
            }
            return(result);
        } //! TOP FAST BUTTIONS

        float?widthCheck;

        Texture2D[] renderedDoubleCheck = new Texture2D[0];
        Texture2D[] renderedScreen      = new Texture2D[0];
    void OnGUI()
    {
      if (!SceneManager.GetActiveScene().IsValid()) return;

      if (!currentWindow)
      {
        currentWindow = Resources.FindObjectsOfTypeAll( Params.WindowType ).FirstOrDefault() as EditorWindow;
        if (currentWindow) ResetWindow();
      }
      if (!currentWindow) return;

      if (SceneManager.GetActiveScene().GetHashCode() != EditorPrefs.GetInt( "EModules/" + Params.TITLE + "/Scene", -1 )) ResetWindow();

      if (Params.Label == null)
      {
        Params.Label = new GUIStyle( GUI.skin.label );
        Params.Label.fontSize = 14;
        Params.Label.fontStyle = FontStyle.Bold;

        Params.Button = new GUIStyle( GUI.skin.button );
        // Button.fontSize = 14;
        var t = new Texture2D(1,1,TextureFormat.ARGB32,false,true);
        t.hideFlags = HideFlags.DontSave;
        t.SetPixel( 0, 0, new Color( 0, 0.1f, 0.4f, 0.3f ) );
        t.Apply();
        Params.Button.normal.background = null;
        Params.Button.hover.background = null;
        Params.Button.focused.background = null;
        Params.Button.active.background = t;
      }


      if (!Camera.main)
      {
        GUILayout.Label( "No Camera", Params.Label );
        return;
      }

      ISupportedPostComponent currentComponent = null;
      MonoBehaviour c1 = null;
      MonoBehaviour c2 = null;
      if (Params.PostProcessingBehaviourType != null)
        c1 = Camera.main.GetComponent( Params.PostProcessingBehaviourType ) as MonoBehaviour;
      if (Params.AmplifyBaseType != null)
        c2 = Camera.main.GetComponent( Params.AmplifyBaseType ) as MonoBehaviour;

      if (c1 && c1.enabled) currentComponent = postPresets_UnityPostGUI;
      else if (c2 && c2.enabled) currentComponent = postPresets_AmplifyPostGUI;
      else if (c1) currentComponent = postPresets_UnityPostGUI;
      else if (c2) currentComponent = postPresets_AmplifyPostGUI;
      else if (Params.PostProcessingBehaviourType != null) currentComponent = postPresets_UnityPostGUI;
      else if (Params.AmplifyBaseType != null) currentComponent = postPresets_AmplifyPostGUI;


      if (currentComponent == null)
      {
        GUILayout.Label( "Unity PostProcessing or AmplifyColor not imported", Params.Label );
        if (GUILayout.Button( "Download Unity 'Post Processing Stack'", GUILayout.Height( 40 ) ))
        {
          Application.OpenURL( "https://www.assetstore.unity3d.com/#!/content/83912" );
        }
        if (GUILayout.Button( "Download 'Amplify Color'", GUILayout.Height( 40 ) ))
        {
          Application.OpenURL( " https://www.assetstore.unity3d.com/en/#!/content/1894" );
        }
        return;
      }


      // Left column ////
      GUILayout.BeginHorizontal();
      var leftwidth =  Mathf.Clamp( position.width / 3f, 200, 350 );

      GUILayout.BeginVertical( GUILayout.Width( leftwidth ) );
      GUILayout.Label( "Camera: " + Camera.main.name, Params.Label );
      if (GUI.Button( GUILayoutUtility.GetLastRect(), "", Params.Button )) Selection.objects = new[] { Camera.main.gameObject };
      EditorGUIUtility.AddCursorRect( GUILayoutUtility.GetLastRect(), MouseCursor.Link );


      if (currentComponent.MonoComponent == null)
      {
        if (GUILayout.Button( "Add " + currentComponent.MonoComponentType + " Script", GUILayout.Height( 200 ) ))
        {
          Undo.RecordObject( Camera.main.gameObject, "Add " + currentComponent.MonoComponentType + " Script" );
          Camera.main.gameObject.AddComponent( currentComponent.MonoComponentType );
          EditorUtility.SetDirty( Camera.main.gameObject );
        }
        return;
      }

      if (!currentComponent.MonoComponent.enabled)
      {
        GUILayout.Label( currentComponent.MonoComponent.GetType().Name + " Component Disabled", Params.Label );
        if (GUILayout.Button( "Enable " + currentComponent.MonoComponent.GetType().Name + " Component", GUILayout.Height( 200 ) ))
        {
          Undo.RecordObject( currentComponent.MonoComponent, "Enable " + currentComponent.MonoComponent.GetType().Name + " Component" );
          currentComponent.MonoComponent.enabled = true;
          EditorUtility.SetDirty( currentComponent.MonoComponent );
          UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
        }
        return;
      }

      if (widthCheck == null) widthCheck = position.width;
      if (widthCheck.Value != position.width)
      {
        widthCheck = position.width;
        ClearImages( false );
        currentWindow.Repaint();
      }

      //! *** POSTPROCESSING COMPONENT GUI *** //
      currentComponent.LeftSideGUI( this, leftwidth );
      //! *** POSTPROCESSING COMPONENT GUI *** //

      if (GUILayout.Button( "http://emodules.me/", Params.Button )) Application.OpenURL( "http://emodules.me/" );
      EditorGUIUtility.AddCursorRect( GUILayoutUtility.GetLastRect(), MouseCursor.Link );

      GUILayout.EndVertical();
      // Left column

      GUILayout.Space( 10 );

      leftwidth += 20;

      //! PRESETS GRID GUI
      if (currentComponent.IsValid)
      {
        GUILayout.BeginVertical();
        ////////////////////////
        currentComponent.TopFastButtonsGUI( this, leftwidth );
        ////////////////////////
        FiltresAndSorting( this, leftwidth );
        ////////////////////////
        DrawPresets( currentComponent );
        ////////////////////////
        GUILayout.EndVertical();
      }
      //! PRESETS GRID GUI

      GUILayout.EndHorizontal();



    }//!OnGUI