Example #1
0
 static public void HelpButton(string helpTopic, string helpAnchor = null)
 {
     if (FunDream_GUI.Button(HelpIcon, "?", "Help about:\n" + helpTopic))
     {
         OpenHelpFor(string.IsNullOrEmpty(helpAnchor) ? helpTopic : helpAnchor);
     }
 }
Example #2
0
    static private void UnpackShaders(string filter)
    {
        string[] archFiles = Directory.GetFiles(FunDream_Utils.UnityToSystemPath(Application.dataPath), "FunDream_ Packed Shaders.tcp2data", SearchOption.AllDirectories);
        if (archFiles == null || archFiles.Length == 0)
        {
            EditorApplication.Beep();
            Debug.LogError("[FunDream_ Unpack Shaders] Couldn't find file: \"FunDream_ Packed Shaders.tcp2data\"\nPlease reimport Toony Colors Pro 2.");
            return;
        }
        string archivePath = archFiles[0];

        if (archivePath.EndsWith(".tcp2data"))
        {
            FunDream_Utils.PackedFile[] files = FunDream_Utils.ExtractArchive(archivePath, filter);

            int @continue = 0;
            if (files.Length > 8)
            {
                do
                {
                    @continue = EditorUtility.DisplayDialogComplex("FunDream_ : Unpack Shaders", "You are about to import " + files.Length + " shaders in Unity.\nIt could take a few minutes!\nContinue?", "Yes", "No", "Help");
                    if (@continue == 2)
                    {
                        FunDream_GUI.OpenHelpFor("Unpack Shaders");
                    }
                }while(@continue == 2);
            }

            if (@continue == 0 && files.Length > 0)
            {
                string tcpRoot = FunDream_Utils.FindReadmePath();
                foreach (FunDream_Utils.PackedFile f in files)
                {
                    string filePath = tcpRoot + f.path;
                    string fileDir  = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }
                    File.WriteAllText(filePath, f.content);
                }

                Debug.Log("Toony Colors Pro 2 - Unpack Shaders:\n" + files.Length + (files.Length > 1 ? " shaders extracted." : " shader extracted."));
                AssetDatabase.Refresh();
            }

            if (files.Length == 0)
            {
                Debug.Log("Toony Colors Pro 2 - Unpack Shaders:\nNothing to unpack. Shaders are probably already unpacked!");
            }
        }
    }
Example #3
0
    public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
    {
        FunDream_GUI.Header("OUTLINE NORMALS", "Defines where to take the vertex normals from to draw the outline.\nChange this when using a smoothed mesh to fill the gaps shown in hard-edged meshes.");

        Rect r = EditorGUILayout.GetControlRect();

        r = EditorGUI.IndentedRect(r);
        int index = GetCurrentIndex(prop);

        EditorGUI.BeginChangeCheck();
        index = FunDream_GUI.RadioChoiceHorizontal(r, index, labels);
        if (EditorGUI.EndChangeCheck())
        {
            SetKeyword(prop, index);
        }
    }
Example #4
0
    static public bool ShaderKeywordToggle(string keyword, string label, string tooltip, List <string> list, ref bool update, string helpTopic = null)
    {
        float w = EditorGUIUtility.labelWidth;

        if (!string.IsNullOrEmpty(helpTopic))
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = w - 16;
            FunDream_GUI.HelpButton(helpTopic);
        }

        bool boolValue = list.Contains(keyword);

        EditorGUI.BeginChangeCheck();
        boolValue = EditorGUILayout.ToggleLeft(new GUIContent(label, tooltip), boolValue, boolValue ? EditorStyles.boldLabel : EditorStyles.label);
        if (EditorGUI.EndChangeCheck())
        {
            if (boolValue)
            {
                list.Add(keyword);
            }
            else
            {
                list.Remove(keyword);
            }

            update = true;
        }

        if (!string.IsNullOrEmpty(helpTopic))
        {
            EditorGUIUtility.labelWidth = w;
            EditorGUILayout.EndHorizontal();
        }

        return(boolValue);
    }
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        FunDream_GUI.HeaderBig(editMode ? "TCP 2 - RAMP EDITOR" : "TCP 2 - RAMP GENERATOR");
        FunDream_GUI.HelpButton("Ramp Generator");
        EditorGUILayout.EndHorizontal();
        FunDream_GUI.Separator();

        if (editMode)
        {
            string msg = "This will affect <b>all materials</b> that use this texture!" +
                         (this.editModeFromMaterial ? "\n\nSave as a new texture first if you want to affect this material only." : "\n\nSave as a new texture if you want to keep the original ramp.");
            EditorGUILayout.LabelField(GUIContent.none, new GUIContent(msg, FunDream_GUI.GetHelpBoxIcon(MessageType.Warning)), FunDream_GUI.HelpBoxRichTextStyle);

            var rect = EditorGUILayout.GetControlRect(GUILayout.Height(16f));
            var lw   = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = 50f;
            var enabled = GUI.enabled;
            GUI.enabled = false;
            EditorGUI.ObjectField(rect, "Editing: ", linkedTexture, typeof(Texture2D), false);
            EditorGUIUtility.labelWidth = lw;
            GUI.enabled = enabled;
        }

        GUILayout.Label("Click on the gradient to edit it:");
        SerializedObject   so = new SerializedObject(this);
        SerializedProperty sp = so.FindProperty("mGradient");

        EditorGUILayout.PropertyField(sp, GUIContent.none);

        if (!editMode)
        {
            textureWidth = EditorGUILayout.IntField("TEXTURE SIZE:", textureWidth);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("64", EditorStyles.miniButtonLeft))
            {
                textureWidth = 64;
            }
            if (GUILayout.Button("128", EditorStyles.miniButtonMid))
            {
                textureWidth = 128;
            }
            if (GUILayout.Button("256", EditorStyles.miniButtonMid))
            {
                textureWidth = 256;
            }
            if (GUILayout.Button("512", EditorStyles.miniButtonMid))
            {
                textureWidth = 512;
            }
            if (GUILayout.Button("1024", EditorStyles.miniButtonRight))
            {
                textureWidth = 1024;
            }
            EditorGUILayout.EndHorizontal();
        }

        if (GUI.changed)
        {
            so.ApplyModifiedProperties();
            mGradient.alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) };

            if (editMode)
            {
                textureEdited = true;

                //Update linked texture
                var pixels = FunDream_GradientManager.GetPixelsFromGradient(mGradient, linkedTexture.width);
                linkedTexture.SetPixels(pixels);
                linkedTexture.Apply(true, false);
            }
        }

        GUILayout.Space(8f);
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (editMode)
        {
            if (GUILayout.Button("Discard", GUILayout.Width(90f), GUILayout.Height(20f)))
            {
                DiscardEditedTexture();
                if (this.editModeFromMaterial)
                {
                    this.Close();
                }
                else
                {
                    FunDream_RampGenerator.OpenTool();
                }
            }
            if (GUILayout.Button("Apply", GUILayout.Width(90f), GUILayout.Height(20f)))
            {
                SaveEditedTexture();
                if (this.editModeFromMaterial)
                {
                    this.Close();
                }
                else
                {
                    FunDream_RampGenerator.OpenTool();
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
        }

        bool saveButton = false;

        if (editMode)
        {
            saveButton = GUILayout.Button("Save as...", EditorStyles.miniButton, GUILayout.Width(120f), GUILayout.Height(16f));
        }
        else
        {
            saveButton = GUILayout.Button("GENERATE", GUILayout.Width(120f), GUILayout.Height(34f));
        }
        if (saveButton)
        {
            string path = EditorUtility.SaveFilePanel("Save Generated Ramp", FunDream_GradientManager.LAST_SAVE_PATH, editMode ? linkedTexture.name : "FunDream__CustomRamp", "png");
            if (!string.IsNullOrEmpty(path))
            {
                FunDream_GradientManager.LAST_SAVE_PATH = System.IO.Path.GetDirectoryName(path);
                var projectPath = path.Replace(Application.dataPath, "Assets");
                GenerateAndSaveTexture(projectPath);

                if (editMode)
                {
                    var newtexture = AssetDatabase.LoadAssetAtPath <Texture2D>(projectPath);
                    if (newtexture != null)
                    {
                        foreach (var mat in linkedMaterials)
                        {
                            mat.SetTexture("_Ramp", newtexture);
                            EditorUtility.SetDirty(mat);
                        }
                    }

                    //Reinitialize edit mode
                    InitEditMode(newtexture, linkedMaterials);
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        if (!editMode)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Load Texture", EditorStyles.miniButton, GUILayout.Width(120f)))
            {
                LoadTexture();
            }
            EditorGUILayout.EndHorizontal();
        }
    }
Example #6
0
    static public bool ShaderKeywordRadio(string header, string[] keywords, GUIContent[] labels, List <string> list, ref bool update)
    {
        int index = 0;

        for (int i = 1; i < keywords.Length; i++)
        {
            if (list.Contains(keywords[i]))
            {
                index = i;
                break;
            }
        }

        EditorGUI.BeginChangeCheck();

        //Header and rect calculations
        bool hasHeader  = (!string.IsNullOrEmpty(header));
        Rect headerRect = GUILayoutUtility.GetRect(120f, 16f, GUILayout.ExpandWidth(false));
        Rect r          = headerRect;

        if (hasHeader)
        {
            Rect helpRect = headerRect;
            helpRect.width    = 16;
            headerRect.width -= 16;
            headerRect.x     += 16;
            string helpTopic = header.ToLowerInvariant();
            helpTopic = char.ToUpperInvariant(helpTopic[0]) + helpTopic.Substring(1);
            FunDream_GUI.HelpButton(helpRect, helpTopic);
            GUI.Label(headerRect, header, index > 0 ? EditorStyles.boldLabel : EditorStyles.label);
            r.width = FunDream_Utils.ScreenWidthRetina - headerRect.width - 34f;
            r.x    += headerRect.width;
        }
        else
        {
            r.width = FunDream_Utils.ScreenWidthRetina - 34f;
        }

        for (int i = 0; i < keywords.Length; i++)
        {
            Rect rI = r;
            rI.width /= keywords.Length;
            rI.x     += i * rI.width;
            if (GUI.Toggle(rI, index == i, labels[i], (i == 0) ? EditorStyles.miniButtonLeft : (i == keywords.Length - 1) ? EditorStyles.miniButtonRight : EditorStyles.miniButtonMid))
            {
                index = i;
            }
        }

        if (EditorGUI.EndChangeCheck())
        {
            //Remove all other keywords and add selected
            for (int i = 0; i < keywords.Length; i++)
            {
                if (list.Contains(keywords[i]))
                {
                    list.Remove(keywords[i]);
                }
            }

            if (index > 0)
            {
                list.Add(keywords[index]);
            }

            update = true;
        }

        return(index > 0);
    }
Example #7
0
 public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
 {
     position.y      += 4;
     position.height -= 4;
     FunDream_GUI.Separator(position);
 }
Example #8
0
 public FunDream_HelpBoxDecorator(string messageType, string msg)
 {
     this.msgType = (MessageType)System.Enum.Parse(typeof(MessageType), messageType);
     this.message = ParseMessage(msg);
     this.icon    = FunDream_GUI.GetHelpBoxIcon(this.msgType);
 }
Example #9
0
 public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
 {
     FunDream_GUI.HeaderAndHelp(position, this.header, null, this.help);
 }
Example #10
0
 static public void HelpBoxLayout(string message, MessageType msgType)
 {
     EditorGUILayout.LabelField(GUIContent.none, new GUIContent(message, FunDream_GUI.GetHelpBoxIcon(msgType)), FunDream_GUI.HelpBoxRichTextStyle);
 }
Example #11
0
 static public void HelpBox(Rect position, string message, MessageType msgType)
 {
     EditorGUI.LabelField(position, GUIContent.none, new GUIContent(message, FunDream_GUI.GetHelpBoxIcon(msgType)), FunDream_GUI.HelpBoxRichTextStyle);
 }
Example #12
0
 public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
 {
     position.y += 2;
     FunDream_GUI.Header(position, header);
 }
Example #13
0
 static void OpenDocumentation()
 {
     FunDream_GUI.OpenHelp();
 }