Exemple #1
0
 public static void UpdateScreenCapAtEOF(xCBMScreenCap screenCap)
 {
     // capture Render at EndOfFrame
     Proxy.StartUpdateScreenCapCoroutine(screenCap);
     // force EndOfFrame - to execute yield
     GameView.Repaint();
 }
Exemple #2
0
    private static void addOrReplaceScreenCap(xCBMScreenCap screenCapToAdd, xCBMScreenCap screenCapToReplace)
    {
        int screenCapIndexToReplace = getScreenCapIndex(screenCapToReplace);
        int screenCapIndexToAdd     = getScreenCapIndex(screenCapToAdd);

        if (screenCapIndexToReplace >= 0)         // replace
        // values to keep
        {
            bool origEnabledState = AvailScreenCaps[screenCapIndexToReplace].Enabled;

            AvailScreenCaps[screenCapIndexToReplace]         = screenCapToAdd;
            AvailScreenCaps[screenCapIndexToReplace].Enabled = origEnabledState;
        }
        else if (screenCapIndexToAdd >= 0)           // update (don't add duplicates)
        // values to keep
        {
            bool origEnabledState = AvailScreenCaps[screenCapIndexToAdd].Enabled;

            AvailScreenCaps[screenCapIndexToAdd]         = screenCapToAdd;
            AvailScreenCaps[screenCapIndexToAdd].Enabled = origEnabledState;
        }
        else             // add
        {
            AvailScreenCaps.Add(screenCapToAdd);
        }
    }
    // Draws an default (=bultin) ScreenCap entry line
    private static void DrawDefaultScreenCapEntry(xCBMScreenCap screenCap)
    {
        GUILayout.BeginHorizontal("box");
        GUILayout.Space(spacing);

        screenCap.Enabled = GUILayout.Toggle(screenCap.Enabled, "", GUILayout.Width(labelWidthEnabled));
        GUILayout.Label(screenCap.Name, GUILayout.Width(labelWidthName));
        GUILayout.Label(screenCap.TypeColl, GUILayout.Width(labelWidthName));

        if (screenCap.FrequencyMalePercent == -1f)
        {
            GUILayout.Label("n/a", GUILayout.Width(labelWidthStats));
        }
        else
        {
            GUILayout.Label(screenCap.FrequencyMalePercent.ToString() + "%", GUILayout.Width(labelWidthStats));
        }
        if (screenCap.FrequencyFemalePercent == -1f)
        {
            GUILayout.Label("n/a", GUILayout.Width(labelWidthStats));
        }
        else
        {
            GUILayout.Label(screenCap.FrequencyFemalePercent.ToString() + "%", GUILayout.Width(labelWidthStats));
        }

        GUILayout.Label(screenCap.Description, GUILayout.MinWidth(labelMinWidthDescription));

        GUILayout.EndHorizontal();
    }
Exemple #4
0
 public static bool IsToUpdate(xCBMScreenCap screenCap)
 {
     if (screenCap.LastUpdateTime != lastChangeInEditorTime && screenCap.LastUpdateTryTime != lastChangeInEditorTime)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
    private IEnumerator WaitXFrames(xCBMScreenCap ScreenCap, int frameCount)
    {
        while (frameCount > 0)
        {
            yield return(null);            // wait until next frame

            frameCount--;
        }

        xCBMManager.UpdateScreenCapAtEOF(ScreenCap);
    }
Exemple #6
0
    private static int getScreenCapIndex(xCBMScreenCap ScreenCapToCheck)
    {
        for (int x = 0; x < AvailScreenCaps.Count; x++)
        {
            if (AvailScreenCaps[x] == ScreenCapToCheck)
            {
                return(x);
            }
        }

        return(-1);
    }
    private static void DrawGallery()
    {
        int entriesPerRow = xCBMManager.Config.GalleryScreenCapsPerRow;

        EditorGUILayout.BeginVertical();
        EditorGUILayout.BeginHorizontal();

        for (int x = 0; x < activeScreenCaps.Count; x++)
        {
            xCBMScreenCap currScreenCap = activeScreenCaps[x];

            // begin new row?
            if (x % entriesPerRow == 0)
            {
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
            }

            DrawScreenCap(currScreenCap, x);

            // last entry?
            if (x == activeScreenCaps.Count - 1)
            {
                // fill last row to ensure same/correct size of last row entries
                int entriesInLastRow = activeScreenCaps.Count % entriesPerRow;

                if (entriesInLastRow < entriesPerRow && entriesInLastRow != 0 && !xCBMManager.Config.UseFixedScreenCapSize)
                {
                    int entriesToFill = entriesPerRow - entriesInLastRow;

                    // add invisible dummy entries
                    for (int y = 0; y < entriesToFill; y++)
                    {
                        // use same layout cammands as below for similar spacing

                        EditorGUILayout.BeginVertical();
                        float aspect = (float)currScreenCap.Texture.width / currScreenCap.Texture.height;
                        GUILayoutUtility.GetAspectRect(aspect, GUILayout.MinWidth(screenCapMinWidth), GUILayout.MinHeight(screenCapMinHeight));

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.EndVertical();
                    }
                }
            }
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
Exemple #8
0
    private static void addOrUpdateScreenCap(xCBMScreenCap screenCapToAdd)
    {
        int screenCapIndex = getScreenCapIndex(screenCapToAdd);

        if (screenCapIndex >= 0)         // update (don't add duplicates)
        // values to keep
        {
            bool origEnabledState = AvailScreenCaps[screenCapIndex].Enabled;

            AvailScreenCaps[screenCapIndex]         = screenCapToAdd;
            AvailScreenCaps[screenCapIndex].Enabled = origEnabledState;
        }
        else             // add
        {
            AvailScreenCaps.Add(screenCapToAdd);
        }
    }
    private static void DrawScreenCap(xCBMScreenCap screenCap, int screenCapIndex)
    {
        Rect screenCapRect, screenCapBox;

        // create Box and Rect
        if (xCBMManager.Config.UseFixedScreenCapSize)
        {
            screenCapBox  = EditorGUILayout.BeginVertical("box", GUILayout.Width(xCBMManager.Config.FixedScreenCapSize.x), GUILayout.Height(xCBMManager.Config.FixedScreenCapSize.y));
            screenCapRect = GUILayoutUtility.GetRect(xCBMManager.Config.FixedScreenCapSize.x, xCBMManager.Config.FixedScreenCapSize.y);
        }
        else
        {
            screenCapBox = EditorGUILayout.BeginVertical("box");
            float aspect = (float)screenCap.Texture.width / screenCap.Texture.height;
            screenCapRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.MinWidth(screenCapMinWidth), GUILayout.MinHeight(screenCapMinHeight));
        }

        // draw SC
        if (screenCap.UpdatedSuccessful)
        {
            // draw ScreenCap in prepared rect (use EditorGUI.DrawTextureTransparent to draw it without Play mode tint)
            EditorGUI.DrawTextureTransparent(screenCapRect, screenCap.Texture, ScaleMode.ScaleToFit);

            // select SC in xCBM Preview on click
            if (screenCapBox.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    xCBMPreviewWindow.ChangeActiveScreenCap(screenCapIndex);
                }
            }
        }
        else
        {
            EditorGUILayout.HelpBox("ScreenCap could not been updated", MessageType.Warning, true);
        }

        // description
        GUILayout.Label(screenCap.Name + "\n(" + screenCap.TypeColl + ")", labelStyle);

        EditorGUILayout.EndVertical();
    }
    public static void ChangeActiveScreenCap(int screenCapIndex)
    {
        // ensure correct index
        if (screenCapIndex >= activeScreenCaps.Count)
        {
            screenCapIndex = 0;
        }
        else if (screenCapIndex < 0)
        {
            screenCapIndex = activeScreenCaps.Count - 1;
        }
        xCBMManager.Config.PreviewSelectedScreenCapIndex = screenCapIndex;

        // repaint windows on next update
        xCBMManager.RepaintAllWindows();

        if (activeScreenCaps.Count > 0)
        {
            SelectedScreenCap = activeScreenCaps[screenCapIndex];             // get Ref to selected SC
        }
    }
Exemple #11
0
    public static void UpdateScreenCap(xCBMScreenCap screenCap)
    {
        // make current ScreenCap available to delegates
        UpdatingScreenCap = screenCap;

        // run custom code
        if (OnPreScreenCapUpdate != null)
        {
            OnPreScreenCapUpdate();
        }

        xCBMManager.ScreenCapUpdateInProgress = true;

        // wait x frames to ensure correct results with other (lazy) plugins
        if (xCBMManager.CurrEditorMode == EditorMode.Play)         // don't wait in Play mode
        {
            Proxy.StartWaitXFramesCoroutine(screenCap, 0);
        }
        else
        {
            Proxy.StartWaitXFramesCoroutine(screenCap, xCBMManager.Config.FramesToWait);
        }
    }
    // update one ScreenCap per Update()
    void Update()
    {
        // send heartbeat
        xCBMManager.SendHeartbeatGallery();

        // ensures a xCBM Proxy exists
        xCBMManager.CreateProxyGO();

        // finalize SC update (set default GV size etc.)
        if (xCBMManager.AllScreenCapsUpdatedRecently() && !xCBMManager.FinalizeScreenCapInProgress)
        {
            // reset 1xUpdate
            if (updateOnce)
            {
                screenCapsToUpdateOnce = 0;
                updateOnce             = false;
            }

            xCBMManager.GalleryIsUpdating           = false;
            xCBMManager.FinalizeScreenCapInProgress = true;
            xCBMManager.FinalizeScreenCapUpdate();
        }
        // ensure some frames after default resolution is set
        else if (xCBMManager.AllScreenCapsUpdatedRecently() && xCBMManager.FinalizeScreenCapInProgress)
        {
            // still frames to go?
            if (postUpdateFramesToGo <= 0)
            {
                xCBMManager.SetAllScreenCapsUpdated();

                xCBMManager.FinalizeScreenCapInProgress = false;
            }
            else
            {
                xCBMManager.EnsureNextFrame();
                postUpdateFramesToGo--;
            }
        }
        // auto update or 1xUpdate
        else if (((xCBMManager.Config.GalleryAutoUpdateInEditorMode && xCBMManager.CurrEditorMode == EditorMode.Edit) || // Editor mode
                  (xCBMManager.Config.GalleryAutoUpdateInPauseMode && xCBMManager.CurrEditorMode == EditorMode.Pause) || // Pause mode
                  (xCBMManager.Config.GalleryAutoUpdateInPlayMode && xCBMManager.CurrEditorMode == EditorMode.Play) ||   // Play
                  updateOnce) &&                                                                                         // 1x Update
                 !xCBMManager.ScreenCapUpdateInProgress)
        {                                                                                                                // update ScreenCap
            // limit SC-block updates
            if (!updateOnce && !xCBMManager.GalleryIsUpdating && xCBMManager.CurrEditorMode == EditorMode.Edit)          // limit auto update in Edit mode (only for SC-blocks)
            {
                updateInterval = 1f / xCBMManager.Config.GalleryUpdateIntervalLimitEdit;
            }
            else if (!updateOnce && !xCBMManager.GalleryIsUpdating && xCBMManager.CurrEditorMode == EditorMode.Play)               // limit auto update in Play mode (only for SC-blocks)
            {
                updateInterval = 1f / xCBMManager.Config.GalleryUpdateIntervalLimitPlay;
            }
            else
            {
                updateInterval = 0f;                 // do not limit update interval
            }

            if (EditorApplication.timeSinceStartup > lastUpdateTime + updateInterval)             // limit updates per sec
            {
                lastUpdateTime = EditorApplication.timeSinceStartup;

                // cache list
                activeScreenCaps = xCBMManager.ActiveScreenCaps;

                // execute update?
                if (activeScreenCaps.Count != 0 && xCBMManager.ProxyGO && !xCBMManager.PreviewIsUpdating && !xCBMManager.OtherUpdateInProgress)
                {
                    // find next ScreenCap to update
                    if (currScreenCapIndex >= activeScreenCaps.Count)
                    {
                        currScreenCapIndex = 0;
                    }
                    xCBMScreenCap currScreenCap = activeScreenCaps[currScreenCapIndex];

                    // update ScreenCap only if it's outdated (try one time) OR update1x is clicked
                    if (xCBMManager.IsToUpdate(currScreenCap) || updateOnce)
                    {
                        if (xCBMManager.GalleryIsUpdating == false && xCBMManager.OnStartScreenCapUpdate != null)
                        {
                            xCBMManager.OnStartScreenCapUpdate();
                        }

                        xCBMManager.GalleryIsUpdating = true;
                        xCBMManager.UpdateScreenCap(currScreenCap);

                        currScreenCapIndex++;

                        // decrease Update1x-to-go count
                        if (updateOnce && screenCapsToUpdateOnce > 0)
                        {
                            screenCapsToUpdateOnce--;
                        }

                        // number os frames to step after all SCs are updated
                        postUpdateFramesToGo = xCBMManager.Config.FramesToWait;
                    }
                    else                         // skip SC
                    {
                        currScreenCapIndex++;
                    }
                }
            }
        }

        // ensure a next frame while waiting for one
        if (xCBMManager.ScreenCapUpdateInProgress && xCBMManager.GalleryIsUpdating && xCBMManager.GalleryWindowIsAlive)
        {
            xCBMManager.EnsureNextFrame();
        }

        if (activeScreenCaps.Count == 0)
        {
            InfoBoxText = "No ScreenCaps active. Open xCBM Options to activate color blindness types.";
        }
        else
        {
            InfoBoxText = "";
        }

        // repaint window
        if (RepaintNextUpdate)
        {
            myWindow.Repaint();
            RepaintNextUpdate = false;
        }
    }
Exemple #13
0
    // coroutine to render all cameras to RT with xCBM shader and get the result at end of the frame
    public static IEnumerator ReadScreenCap(xCBMScreenCap screenCap)
    {
        int width  = Screen.width;
        int height = Screen.height;

        renderTex = new RenderTexture(width, height, 24);

        // render only to RT and not to screen
        RenderTexture prevActiveRenderTex = RenderTexture.active;

        RenderTexture.active = renderTex;

        // render all cameras
        Camera[] cams = new Camera[Camera.allCamerasCount];
        Camera.GetAllCameras(cams);
        foreach (Camera cam in cams)
        {
            if (cam.targetTexture == null)
            {
                // copy cam settings
                myxCBMCamera.CopyFrom(cam);
                // render to texture
                myxCBMCamera.targetTexture = renderTex;
                myxCBMCamera.Render();
            }
        }

        yield return(new WaitForEndOfFrame());        // wait until rendering is done

        yield return(new WaitForEndOfFrame());        // improves performance

        Texture2D screenTex = new Texture2D(width, height, TextureFormat.RGB24, false);

        if (screenCap.Type != xCBMColorBlindnessType.Normal)
        {
            if (Config.UseWorkaroundUGuiCanvasScreenSpace)             // Workaround for RenderTexture - uGUI screen space canvas bug
            {
                screenTex.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
                screenTex.Apply(false, false);

                // apply shader variant to Tex2D
                Graphics.Blit(screenTex, renderTex, xCBMMat[(int)screenCap.Type]);
            }
            else
            {
                // apply shader variant to RT
                Graphics.Blit(renderTex, renderTex, xCBMMat[(int)screenCap.Type]);
            }
        }

        screenTex.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
        screenTex.Apply(false, false);          // readable to enable export as file
        screenCap.Texture = screenTex;

        // Restore previously active RenderTexture
        RenderTexture.active = prevActiveRenderTex;

        screenCap.LastUpdateTime    = lastChangeInEditorTime;
        screenCap.LastUpdateTryTime = lastChangeInEditorTime;
        screenCap.UpdatedSuccessful = true;

        // repaint editor windows
        if (myxCBMPreviewWindow)
        {
            myxCBMPreviewWindow.Repaint();
        }
        if (myxCBMGalleryWindow)
        {
            myxCBMGalleryWindow.Repaint();
        }

        // run custom code
        if (OnPostScreenCapUpdate != null)
        {
            OnPostScreenCapUpdate();
        }

        xCBMManager.ScreenCapUpdateInProgress = false;
    }
Exemple #14
0
 // coroutine to wait a few frames between resolution change and SC update
 public void StartWaitXFramesCoroutine(xCBMScreenCap ScreenCap, int frameCount)
 {
     StartCoroutine(WaitXFrames(ScreenCap, frameCount));
 }
Exemple #15
0
 public void StartUpdateScreenCapCoroutine(xCBMScreenCap ScreenCapToUpdate)
 {
     StartCoroutine(xCBMManager.ReadScreenCap(ScreenCapToUpdate));
 }
    void Update()
    {
        // send heartbeat
        xCBMManager.SendHeartbeatPreview();

        // ensures a xCBM Proxy exists
        xCBMManager.CreateProxyGO();

        // finalize SC update
        if (xCBMManager.PreviewIsUpdating && !xCBMManager.ScreenCapUpdateInProgress)
        {
            xCBMManager.PreviewIsUpdating           = false;
            xCBMManager.FinalizeScreenCapInProgress = true;
            xCBMManager.FinalizeScreenCapUpdate();
            xCBMManager.FinalizeScreenCapInProgress = false;
        }

        // update SC if auto update is enabled or Update1x was clicked
        if (((xCBMManager.Config.PreviewAutoUpdateInEditorMode && xCBMManager.CurrEditorMode == EditorMode.Edit) ||      // Edit
             (xCBMManager.Config.PreviewAutoUpdateInPauseMode && xCBMManager.CurrEditorMode == EditorMode.Pause) ||      // Pause
             (xCBMManager.Config.PreviewAutoUpdateInPlayMode && xCBMManager.CurrEditorMode == EditorMode.Play) ||        // Play
             updateOnce) &&
            !xCBMManager.GalleryIsUpdating &&
            !xCBMManager.ScreenCapUpdateInProgress &&
            !xCBMManager.OtherUpdateInProgress)
        {
            // limit SC updates
            if (!updateOnce && xCBMManager.CurrEditorMode == EditorMode.Edit)             // limit auto update in Edit mode
            {
                updateInterval = 1f / xCBMManager.Config.PreviewUpdateIntervalLimitEdit;
            }
            else if (!updateOnce && xCBMManager.CurrEditorMode == EditorMode.Play)               // limit auto update in Play mode
            {
                updateInterval = 1f / xCBMManager.Config.PreviewUpdateIntervalLimitPlay;
            }
            else
            {
                updateInterval = 0f;                 // do not limit update interval
            }

            if (EditorApplication.timeSinceStartup > lastUpdateTime + updateInterval)             // limit updates per sec
            {
                lastUpdateTime = EditorApplication.timeSinceStartup;
                if (SelectedScreenCap is xCBMScreenCap && xCBMManager.ProxyGO /*&& !xCBMManager.GalleryIsUpdating*/)
                {
                    xCBMScreenCap currScreenCap = SelectedScreenCap;

                    // update ScreenCap only if it's outdated (try one time) OR update1x is clicked
                    if (xCBMManager.IsToUpdate(currScreenCap) || updateOnce)
                    {
                        // run custom code
                        if (xCBMManager.PreviewIsUpdating == false && xCBMManager.OnStartScreenCapUpdate != null)
                        {
                            xCBMManager.OnStartScreenCapUpdate();
                        }

                        xCBMManager.PreviewIsUpdating = true;
                        xCBMManager.UpdateScreenCap(currScreenCap);
                        updateOnce = false;
                    }
                }
            }
        }

        // ensure a next frame while waiting for one
        if (xCBMManager.ScreenCapUpdateInProgress && xCBMManager.PreviewIsUpdating && xCBMManager.PreviewWindowIsAlive)         // while SC update
        {
            xCBMManager.EnsureNextFrame();
        }

        if (activeScreenCaps.Count == 0)
        {
            InfoBoxText = "No ScreenCaps active. Open xCBM Options to activate color blindness types.";
        }
        else
        {
            InfoBoxText = "";
        }


        // repaint window
        if (RepaintNextUpdate)
        {
            myWindow.Repaint();
            RepaintNextUpdate = false;
        }
    }