Example #1
0
    public static Preview Create(Vector2 size, AnyWalker target, AnyWalkerEditor genEdit)
    {
        Preview preview = EditorWindow.GetWindowWithRect <Preview>(new Rect(Screen.width / 2 - size.x / 2, (Screen.height / 2) - (size.y + 120) / 2, size.x, size.y + 60));

        preview.size     = size;
        preview.tar      = target;
        preview.genEdit  = genEdit;
        preview.settings = genEdit.ScanFileType();
        preview.settings.SetSettings(AnyWalker.GET_GAMEMODE(preview.genEdit.save.mode));

        //Base Material
        Material mat = Resources.Load(AnyWalkerEditor.TOOL_NAME + "/PreviewCube") as Material;

        mat.color = AnyWalkerEditor.col_egg;
        preview.tar.InitGenerator(mat, AnyWalkerEditor.col_egg, AnyWalkerEditor.col_semiblack);

        //Generation settings
        preview.values = new object[preview.settings.variables.Count];
        for (int i = 0; i < preview.values.Length; i++)
        {
            preview.values[i] = preview.settings.variables[i].value;
        }
        preview.obj = preview.settings.Convert(genEdit.GetCurrentPath(), preview.values, AnyWalker.GET_GAMEMODE(preview.genEdit.save.mode));
        if (preview.obj == null)
        {
            preview.Close();
            return(null);
        }
        return(preview);
    }
Example #2
0
    private void UpdateMesh()
    {
        foreach (Transform child in obj.transform)
        {
            DestroyImmediate(child.gameObject);
        }
        obj = settings.Convert(genEdit.GetCurrentPath(), values, AnyWalker.GET_GAMEMODE(genEdit.save.mode));
        Editor temp = Editor.CreateEditor(obj);

        DestroyImmediate(editor);
        editor = temp;
    }
Example #3
0
    public override void OnInspectorGUI()
    {
        AnyWalker tar = (AnyWalker)target;

        //EditorGUI.ProgressBar(Rect, value:, label);

        //Colors
        ColorUtility.TryParseHtmlString("#eaf0ce", out col_egg);
        ColorUtility.TryParseHtmlString("#333232", out col_black);
        ColorUtility.TryParseHtmlString("#474647", out col_semiblack);
        ColorUtility.TryParseHtmlString("#f45d01", out col_red);
        ColorUtility.TryParseHtmlString("#e1aa7d", out col_blank);

        //Styling
        GUIContent content        = new GUIContent();
        GUIStyle   oldLabel       = EditorStyles.boldLabel;
        GUIStyle   style          = new GUIStyle(GUI.skin.button),
                   labelstyle     = EditorStyles.boldLabel,
                   generateButton = new GUIStyle(GUI.skin.button),
                   elementBtn     = new GUIStyle(GUI.skin.button),
                   resetButton    = new GUIStyle(GUI.skin.button);

        style.imagePosition              = ImagePosition.ImageLeft;
        style.fixedHeight                = style.fixedWidth = 45;
        elementBtn.fontStyle             = FontStyle.Bold;
        resetButton.fontStyle            = FontStyle.Bold;
        elementBtn.onActive.textColor    = col_egg;
        elementBtn.onNormal.textColor    = col_egg;
        elementBtn.active.textColor      = col_semiblack;
        generateButton.active.textColor  = col_black;
        generateButton.normal.textColor  = col_semiblack;
        generateButton.onHover.textColor = col_black;
        generateButton.fontStyle         = FontStyle.Bold;
        generateButton.padding           = new RectOffset(10, 10, 10, 5);
        labelstyle.normal.textColor      = col_egg;
        labelstyle.alignment             = TextAnchor.MiddleLeft;
        labelstyle.fontStyle             = FontStyle.Bold;
        labelstyle.fontSize              = 14;

        //Load Icons
        folderIcon      = Resources.Load(TOOL_NAME + "/Folder") as Texture;
        content.image   = (Texture2D)folderIcon;
        content.tooltip = "Choose a main directory folder where all files are located.";

        //File Loading & Directory
        GUI.backgroundColor = col_semiblack;
        GUILayout.BeginVertical("Box");
        GUILayout.Label("File Loading", labelstyle);
        GUI.backgroundColor = col_black;
        GUILayout.BeginHorizontal("box");
        GUI.backgroundColor = col_egg;
        if (GUILayout.Button(content, style))
        {
            path       = EditorUtility.OpenFolderPanel("Select directory", "", "");
            currentDir = new DirectoryInfo(path);
            SaveSettings();
            FileInfo[] info = currentDir.GetFiles("*.");
            foreach (FileInfo f in info)
            {
                files.Add(f.Name);
            }
        }
        GUI.backgroundColor = Color.white;

        if (path.Length <= 1)
        {
            buttonName   = "Load Directory";
            hasDirectory = false;
        }
        else
        {
            buttonName   = "Directory loaded:";
            hasDirectory = true;
        }

        GUILayout.BeginVertical();
        GUILayout.Box(buttonName, labelstyle);
        int oldSize = labelstyle.fontSize;

        labelstyle.fontSize = 10;
        if (hasDirectory)
        {
            GUILayout.Label(Simplify(path), labelstyle);
        }
        else
        {
            GUILayout.Label("<--", labelstyle);
        }
        labelstyle.fontSize = oldSize;
        GUILayout.EndVertical();
        GUI.backgroundColor = col_egg;
        if (GUILayout.Button("Reset", elementBtn, GUILayout.Width(50)))
        {
            path         = "";
            currentDir   = null;
            hasDirectory = false;
        }
        GUILayout.EndHorizontal();

        //File Selection
        int labelSize = labelstyle.fontSize;

        if (hasDirectory)
        {
            GUILayout.BeginVertical("Box");
            FileInfo[] files = GetFileList();
            fileTypeScroll = GUILayout.BeginScrollView(fileTypeScroll, false, true, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Height(200));
            for (int i = 0; i < files.Length; i++)
            {
                if (save.file == files[i].Name)
                {
                    GUI.backgroundColor         = col_semiblack;
                    labelstyle.normal.textColor = col_egg;
                    labelstyle.fontSize         = 15;
                }
                else
                {
                    GUI.backgroundColor         = col_egg;
                    labelstyle.normal.textColor = col_semiblack;
                    labelstyle.fontSize         = 14;
                }

                if (!hasConversionMethod(files[i].Extension))
                {
                    GUI.backgroundColor = col_blank;
                }

                GUILayout.BeginHorizontal("box", GUILayout.Width(Screen.width / 1.5f));
                string name = files[i].Name.Split('.')[0];
                if (name.Length > 24)
                {
                    name = name.Substring(0, 24) + "...";
                }
                if (GUILayout.Button(name, labelstyle))
                {
                    if (hasConversionMethod(files[i].Extension))
                    {
                        save.file = files[i].Name;
                        ScanFileType();
                    }
                }
                TextAnchor oldAlignment = labelstyle.alignment;
                FontStyle  oldStyle     = labelstyle.fontStyle;
                labelstyle.fontStyle = FontStyle.Normal;
                labelstyle.fontSize  = 10;

                if (save.file == files[i].Name)
                {
                    GUI.backgroundColor         = col_egg;
                    labelstyle.normal.textColor = col_semiblack;
                }
                else
                {
                    GUI.backgroundColor         = col_semiblack;
                    labelstyle.normal.textColor = col_egg;
                }
                if (!hasConversionMethod(files[i].Extension))
                {
                    GUI.backgroundColor = col_red;
                }

                GUILayout.BeginHorizontal("box", GUILayout.Width(40));
                labelstyle.alignment = TextAnchor.MiddleCenter;
                GUILayout.Box(files[i].Extension.ToUpper().Substring(1), labelstyle);
                GUILayout.EndHorizontal();

                labelstyle.fontSize  = labelSize;
                labelstyle.alignment = oldAlignment;
                labelstyle.fontStyle = oldStyle;
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            if (save.file != lastFile)
            {
                SaveSettings();
            }
            GUILayout.EndVertical();
        }
        GUILayout.EndVertical();

        //Reset style vars
        labelstyle.fontSize         = labelSize;
        labelstyle.normal.textColor = col_egg;

        //GameType Generation Presets
        if (hasDirectory)
        {
            GUIStyle gameTypeBtn = elementBtn;
            gameTypeBtn.imagePosition = ImagePosition.ImageAbove;
            gameTypeBtn.fixedHeight   = 105;
            gameTypeBtn.fixedWidth    = 150;
            gameTypeBtn.padding       = new RectOffset(0, 0, 10, 5);

            GUILayout.Space(10);
            GUI.backgroundColor = col_semiblack;
            GUILayout.BeginVertical("Box", GUILayout.Height(gameTypeBtn.fixedHeight + 50));
            GUILayout.Label("Game Type", EditorStyles.boldLabel);
            string[] names = new string[AnyWalker.AMOUNT_GAMEMODES()];
            for (int i = 0; i < names.Length; i++)
            {
                names[i] = ((AnyWalker.GameType[])System.Enum.GetValues(typeof(AnyWalker.GameType)))[i].ToString().Replace('_', ' ');
            }

            GUI.backgroundColor = col_egg;
            //IMAGES LOADING
            GUIContent[] contents = new GUIContent[AnyWalker.AMOUNT_GAMEMODES()];
            for (int i = 0; i < contents.Length; i++)
            {
                contents[i] = new GUIContent();
                Texture2D img = Resources.Load(TOOL_NAME + "/" + names[i].Replace(" ", "")) as Texture2D;
                //Complexity
                int   complexity = (int)(((i + 1) / (float)contents.Length) * 3);
                int   baseX = img.width / 3 * 2, baseY = img.height / 3 * 2;
                Color col = col_egg;
                if (complexity == 2)
                {
                    col = col_blank;
                }
                else if (complexity >= 3)
                {
                    col = col_red;
                }
                Color baseCol = col;
                //Complexity Icon Generation
                for (int c = complexity; c > 0; c--)
                {
                    int si = 50;
                    if (c > 1)
                    {
                        col *= 0.5f - c / 10;
                    }
                    else
                    {
                        col = baseCol;
                    }
                    for (int mX = 0; mX < si; mX++)
                    {
                        for (int mY = 0; mY < si; mY++)
                        {
                            img.SetPixel(baseX + mX + (c * si / 4), baseY + mY + (c * si / 4), col);
                            img.SetPixel(baseX + mX + (si / 8) + (c * si / 4), baseY + (si / 8) + mY + (c * si / 4), col_semiblack);
                        }
                    }
                }
                img.Apply();
                contents[i].image = img;
                contents[i].text  = names[i];
            }
            //Horizontal Scrolling
            Vector2 scroll = new Vector2(0, 0);
            if (Event.current.isScrollWheel)
            {
                scroll = new Vector2(Event.current.delta.y * 10, 0);
            }
            gameTypeScroll = GUILayout.BeginScrollView(gameTypeScroll + scroll, true, false, GUI.skin.horizontalScrollbar, GUIStyle.none);

            save.mode = GUILayout.SelectionGrid(save.mode, contents, names.Length, gameTypeBtn);
            EditorGUILayout.EndScrollView();

            GUILayout.EndVertical();
            if (save.mode != lastMode)
            {
                SaveSettings();
            }
            GUILayout.Space(10);

            //Generate button
            GUI.backgroundColor = col_semiblack;
            GUILayout.BeginVertical("Box");
            GUILayout.BeginHorizontal();
            GUILayout.Label("Preview", EditorStyles.boldLabel);
            GUI.backgroundColor = col_egg;
            if (GUILayout.Button("Clear World", resetButton, GUILayout.Width(85)))
            {
                tar.Reset();
            }
            GUI.backgroundColor = col_semiblack;
            GUILayout.EndHorizontal();
            GUI.backgroundColor = col_egg;
            if (GUILayout.Button("Generate", generateButton))
            {
                if (preview == null && ScanFileType() != null)
                {
                    preview = Preview.Create(new Vector2(800, 620), tar, this);
                }
            }
            GUILayout.EndVertical();
            GUILayout.Space(5);
        }
        labelstyle.normal.textColor = Color.black;
        labelstyle = oldLabel;
    }