Beispiel #1
0
        [SerializeField] private List <ScoreData> leaderboards; // For Testing


        public bool Inspect()
        {
            var changed = false;

            pegi.nl();

            "Player Name".edit(90, ref playerName).nl(ref changed);

            if (sortedLeaderboard.Count > 1 && "Sort Leaderboard".Click(ref changed))
            {
                sortedLeaderboard.Sort((s1, s2) => s2.GetScore() - s1.GetScore());
            }

            if (icon.Save.Click("Save Game State Data Locally"))
            {
                Save();
            }

            if (icon.Load.ClickUnFocus("Load Game State Data from Persistant path"))
            {
                Load();
            }

            if (icon.Folder.Click("Open Save data folder"))
            {
                FileExplorerUtils.OpenPersistentFolder(cfg.savedGameFolderName);
            }

            pegi.nl();



            "Leaderboard".edit_List(ref sortedLeaderboard).nl(ref changed);



#if UNITY_EDITOR
            if ("Json leaderboard test".enter(ref inspectedSection, 0).nl())
            {
                "Score Json File Test".edit(ref test_Json).changes(ref changed);

                if (test_Json && icon.Create.ClickUnFocus("Try extract scoreboard from json"))
                {
                    var filePath = AssetDatabase.GetAssetPath(test_Json);

                    JsonUtility.FromJsonOverwrite(File.ReadAllText(filePath), this);
                }

                pegi.nl();

                "Score Json string Test".edit(ref jsonTestString).changes(ref changed);

                if (!jsonTestString.IsNullOrEmpty() && icon.Create.ClickUnFocus("Read Json data from string").nl(ref changed))
                {
                    JsonUtility.FromJsonOverwrite(jsonTestString, this);
                }

                pegi.nl();

                "Tmp Scores".edit_List(ref leaderboards).nl(ref changed);


                if (!leaderboards.IsNullOrEmpty())
                {
                    if ("Add Scores to leadeboard".ClickUnFocus("Will add the highest scores").nl())
                    {
                        foreach (var scoreData in sortedLeaderboard)
                        {
                            var duplicant = leaderboards.GetByIGotName(scoreData.name);

                            if (duplicant != null)
                            {
                                scoreData.UpdateScore(duplicant.GetScore());
                                leaderboards.Remove(duplicant);
                            }
                        }

                        sortedLeaderboard.AddRange(leaderboards);

                        leaderboards.Clear();

                        sortedLeaderboard.Sort((s1, s2) => s2.GetScore() - s1.GetScore());
                    }
                }
            }

            pegi.nl();
#endif

            if ("HTTP request test".enter(ref inspectedSection, 1).nl())
            {
                "Server URL: ".edit(70, ref serverURL).nl(ref changed);

                if (!lastResult.IsNullOrEmpty())
                {
                    "Last Result: {0}".F(lastResult).nl();
                }

                if (request != null)
                {
                    if (request.isDone)
                    {
                        "Downloading done".nl();

                        if ("Read Data".Click())
                        {
                            var wr = request.webRequest;

                            if (wr.isNetworkError)
                            {
                                lastResult = wr.error;
                            }
                            else
                            {
                                lastResult = wr.downloadHandler.text;

                                JsonUtility.FromJsonOverwrite(lastResult, this);

                                if (lastResult.Length > 100)
                                {
                                    lastResult = lastResult.Substring(0, 100) + "...";
                                }
                            }

                            request = null;
                        }
                    }
                    else
                    {
                        "Request is processing: {0}%".F(Mathf.FloorToInt(request.progress * 100)).nl();
                    }
                }
                else
                {
                    "Request Field".edit(ref requestField).nl(ref changed);
                    "Request Value".edit(ref requestValue).nl(ref changed);

                    if ("Post Request".Click())
                    {
                        WWWForm form = new WWWForm();
                        form.AddField(requestField, requestValue);
                        form.AddField("leaderboard_version", leaderboardVersion);

                        UnityWebRequest wwwSignin = UnityWebRequest.Post(serverURL, form);

                        request = wwwSignin.SendWebRequest();
                    }
                }
            }

            return(changed);
        }
Beispiel #2
0
        public override bool Inspect()
        {
            var changed = false;

            if ("CPU blit options".conditional_enter(this.TargetIsTexture2D(), ref inspectedItems, 0).nl())
            {
                "Disable Continious Lines".toggleIcon("If you see unwanted lines appearing on the texture as you paint, enable this.", ref disableContiniousLine).nl(ref changed);

                "CPU blit repaint delay".edit("Delay for video memory update when painting to Texture2D", 140, ref _repaintDelay, 0.01f, 0.5f).nl(ref changed);

                "Don't update mipMaps".toggleIcon("May increase performance, but your changes may not disaplay if you are far from texture.",
                                                  ref dontRedoMipMaps).changes(ref changed);

                if (isAVolumeTexture)
                {
                    "Is A volume texture".toggleIcon(ref isAVolumeTexture).nl(ref changed);
                }
            }

            #region Processors

            var newWidth  = Cfg.SelectedWidthForNewTexture(); //PainterDataAndConfig.SizeIndexToSize(PainterCamera.Data.selectedWidthIndex);
            var newHeight = Cfg.SelectedHeightForNewTexture();

            if ("Texture Processors".enter(ref inspectedItems, 6).nl())
            {
                if (errorWhileReading)
                {
                    "There was en error reading texture pixels, can't process it".writeWarning();
                }
                else
                {
                    if ("Resize ({0}*{1}) => ({2}*{3})".F(width, height, newWidth, newHeight).enter(ref _inspectedProcess, 0).nl_ifFoldedOut())
                    {
                        "New Width ".select(60, ref PainterCamera.Data.selectedWidthIndex, PainterDataAndConfig.NewTextureSizeOptions).nl(ref changed);

                        "New Height ".select(60, ref PainterCamera.Data.selectedHeightIndex, PainterDataAndConfig.NewTextureSizeOptions).nl(ref changed);

                        if (newWidth != width || newHeight != height)
                        {
                            bool rescale;

                            if (newWidth <= width && newHeight <= height)
                            {
                                rescale = "Downscale".Click();
                            }
                            else if (newWidth >= width && newHeight >= height)
                            {
                                rescale = "Upscale".Click();
                            }
                            else
                            {
                                rescale = "Rescale".Click();
                            }

                            if (rescale)
                            {
                                Resize(newWidth, newHeight);
                            }
                        }
                        pegi.nl();
                    }

                    if (_inspectedProcess == -1)
                    {
                        if ((newWidth != width || newHeight != height) && icon.Replace.Click("Resize").nl(ref changed))
                        {
                            Resize(newWidth, newHeight);
                        }

                        pegi.nl();
                    }

                    if ("Clear ".enter(ref _inspectedProcess, 1, false))
                    {
                        "Clear Color".edit(80, ref clearColor).nl();

                        if ("Clear Texture".Click().nl())
                        {
                            Colorize(clearColor);
                            SetApplyUpdateRenderTexture();
                        }
                    }

                    if (_inspectedProcess == -1 && icon.Refresh.Click("Apply color {0}".F(clearColor)).nl())
                    {
                        Colorize(clearColor);
                        SetApplyUpdateRenderTexture();
                    }

                    if ("Color to Alpha".enter(ref _inspectedProcess, 2).nl())
                    {
                        "Background Color".edit(80, ref clearColor).nl();
                        if (Pixels != null)
                        {
                            if ("Color to Alpha".Click("Will Convert Background Color with transparency").nl())
                            {
                                bool wasRt = WasRenderTexture();

                                for (int i = 0; i < _pixels.Length; i++)
                                {
                                    _pixels[i] = BlitFunctions.ColorToAlpha(_pixels[i], clearColor);
                                }

                                SetAndApply();

                                if (wasRt)
                                {
                                    ReturnToRenderTexture();
                                }
                            }

                            if ("Color from Alpha".Click("Will subtract background color from transparency").nl())
                            {
                                bool wasRt = WasRenderTexture();

                                for (int i = 0; i < _pixels.Length; i++)
                                {
                                    var col = _pixels[i];

                                    col.a = BlitFunctions.ColorToAlpha(_pixels[i], clearColor).a;

                                    _pixels[i] = col;
                                }

                                SetAndApply();

                                if (wasRt)
                                {
                                    ReturnToRenderTexture();
                                }
                            }
                        }
                    }

                    if ("Signed Distance Filelds generator".enter(ref _inspectedProcess, 4).nl())
                    {
                        "Will convert black and white color to black and white signed field".nl();

                        "SDF Max Inside".edit(ref sdfMaxInside).nl();
                        "SDF Max Outside".edit(ref sdfMaxOutside).nl();
                        "SDF Post Process".edit(ref sdfPostProcessDistance).nl();

                        if ("Generate".Click())
                        {
                            bool wasRt = WasRenderTexture();

                            var p = PlaytimePainter.inspected;
                            if (p)
                            {
                                p.UpdateOrSetTexTarget(TexTarget.Texture2D);
                            }

                            DistanceFieldProcessor.Generate(this, sdfMaxInside, sdfMaxOutside, sdfPostProcessDistance);

                            SetAndApply();

                            if (wasRt)
                            {
                                ReturnToRenderTexture();
                            }
                        }
                    }

                    if ("Curves".enter(ref _inspectedProcess, 5).nl())
                    {
                        var crv = TexMGMT.InspectAnimationCurve("Channel");

                        if (Pixels != null)
                        {
                            if ("Remap Alpha".Click())
                            {
                                for (int i = 0; i < _pixels.Length; i++)
                                {
                                    var col = _pixels[i];
                                    col.a      = crv.Evaluate(col.a);
                                    _pixels[i] = col;
                                }
                                SetApplyUpdateRenderTexture();
                            }

                            if ("Remap Color".Click())
                            {
                                for (int i = 0; i < _pixels.Length; i++)
                                {
                                    var col = _pixels[i];
                                    col.r      = crv.Evaluate(col.r);
                                    col.g      = crv.Evaluate(col.g);
                                    col.b      = crv.Evaluate(col.b);
                                    _pixels[i] = col;
                                }
                                SetApplyUpdateRenderTexture();
                            }
                        }
                    }

                    if ("Save Textures In Game ".enter(ref _inspectedProcess, 7).nl_ifFolded())
                    {
                        "This is intended to test playtime saving. The functions to do so are quite simple. You can find them inside ImageData.cs class."
                        .writeHint();

                        pegi.nl();

                        "Save Name".edit(70, ref saveName);

                        if (icon.Folder.Click("Open Folder with textures").nl())
                        {
                            FileExplorerUtils.OpenPersistentFolder(SavedImagesFolder);
                        }

                        if ("Save Playtime".Click("Will save to {0}/{1}".F(Application.persistentDataPath, saveName)).nl())
                        {
                            SaveInPlayer();
                        }

                        if (Cfg && Cfg.playtimeSavedTextures.Count > 0)
                        {
                            "Playtime Saved Textures".write_List(Cfg.playtimeSavedTextures, LoadTexturePegi);
                        }
                    }

                    if ("Fade edges".enter(ref _inspectedProcess, 8).nl())
                    {
                        ("This will cahange pixels on the edges of the texture. Useful when wrap mode " +
                         "is set to clamp.").writeHint();

                        if (texture2D)
                        {
                            #if UNITY_EDITOR
                            var ti = texture2D.GetTextureImporter();
                            if (ti)
                            {
                                if (ti.wrapMode != TextureWrapMode.Clamp && "Change wrap mode from {0} to Clamp"
                                    .F(ti.wrapMode).Click().nl(ref changed))
                                {
                                    ti.wrapMode = TextureWrapMode.Clamp;
                                    ti.SaveAndReimport();
                                }
                            }
                            #endif

                            if ("Set edges to transparent".Click().nl(ref changed))
                            {
                                SetEdges(Color.clear, BrushMask.A);
                                SetAndApply(true);
                            }

                            if ("Set edges to Clear Black".Click().nl(ref changed))
                            {
                                SetEdges(Color.clear);
                                SetAndApply(true);
                            }
                        }
                    }
                }
            }

            #endregion

            if ("Enable Undo for {0}".F(NameForPEGI).toggle_enter(ref enableUndoRedo, ref inspectedItems, 2, ref changed).nl())
            {
                "UNDOs: Tex2D".edit(80, ref _numberOfTexture2DBackups).changes(ref changed);
                "RendTex".edit(60, ref _numberOfRenderTextureBackups).nl(ref changed);

                "Backup manually".toggleIcon(ref backupManually).nl();

                if (_numberOfTexture2DBackups > 50 || _numberOfRenderTextureBackups > 50)
                {
                    "Too big of a number will eat up lot of memory".writeWarning();
                }

                "Creating more backups will eat more memory".writeOneTimeHint("backupIsMem");
                "This are not connected to Unity's Undo/Redo because when you run out of backups you will by accident start undoing other operations.".writeOneTimeHint("noNativeUndo");
                "Use Z/X to undo/redo".writeOneTimeHint("ZxUndoRedo");
            }

            return(changed);
        }