Exemplo n.º 1
0
    /// <summary>
    /// Helper function that draws a serialized property.
    /// </summary>

    static public SerializedProperty DrawProperty(string label, SerializedObject serializedObject, string property, bool padding, params GUILayoutOption[] options)
    {
        SerializedProperty sp = serializedObject.FindProperty(property);

        if (sp != null)
        {
            if (NGUISettings.minimalisticLook)
            {
                padding = false;
            }

            if (padding)
            {
                EditorGUILayout.BeginHorizontal();
            }

            if (label != null)
            {
                EditorGUILayout.PropertyField(sp, new GUIContent(label), options);
            }
            else
            {
                EditorGUILayout.PropertyField(sp, options);
            }

            if (padding)
            {
                NGUIEditorTools.DrawPadding();
                EditorGUILayout.EndHorizontal();
            }
        }
        return(sp);
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);

        serializedObject.Update();

        GUILayout.Space(3f);

        DrawLegacyFields();

        GUILayout.BeginHorizontal();
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Steps", serializedObject, "numberOfSteps", GUILayout.Width(110f));

        if (sp.intValue == 0)
        {
            GUILayout.Label("= unlimited");
        }
        GUILayout.EndHorizontal();

        OnDrawExtraFields();

        if (NGUIEditorTools.DrawHeader("Appearance", "Appearance", false, true))
        {
            NGUIEditorTools.BeginContents(true);
            NGUIEditorTools.DrawProperty("Foreground", serializedObject, "mFG");
            NGUIEditorTools.DrawProperty("Background", serializedObject, "mBG");
            NGUIEditorTools.DrawProperty("Thumb", serializedObject, "thumb");

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Direction", serializedObject, "mFill");
            NGUIEditorTools.DrawPadding();
            GUILayout.EndHorizontal();

            OnDrawAppearance();
            NGUIEditorTools.EndContents();
        }
        NGUIEditorTools.DrawProperty("Division", serializedObject, "Division");
        UISlider _this = target as UISlider;

        if (_this != null)
        {
            if (_this.Division)
            {
                NGUIEditorTools.SetLabelWidth(100f);

                if (NGUIEditorTools.DrawHeader("Division"))
                {
                    NGUIEditorTools.BeginContents();
                    NGUIEditorTools.DrawProperty("DivisionCount", serializedObject, "DivisionCount");


                    NGUIEditorTools.EndContents();
                }
            }
        }
        UIProgressBar sb = target as UIProgressBar;

        NGUIEditorTools.DrawEvents("On Value Change", sb, sb.onChange);
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Helper function that draws a serialized property.
    /// </summary>

    static public void DrawProperty(string label, SerializedProperty sp, bool padding, params GUILayoutOption[] options)
    {
        if (sp != null)
        {
            if (padding)
            {
                EditorGUILayout.BeginHorizontal();
            }

            if (label != null)
            {
                EditorGUILayout.PropertyField(sp, new GUIContent(label), options);
            }
            else
            {
                EditorGUILayout.PropertyField(sp, options);
            }

            if (padding)
            {
                NGUIEditorTools.DrawPadding();
                EditorGUILayout.EndHorizontal();
            }
        }
    }
    protected override bool ShouldDrawProperties()
    {
        if (mTexEx == null)
        {
            return(false);
        }

        if (mTexEx.replacement != null)
        {
            mType        = TextureType.Reference;
            mReplacement = mTexEx.replacement;
        }

        GUI.changed = false;
        GUILayout.BeginHorizontal();
        mType = (TextureType)EditorGUILayout.EnumPopup("Texture Type", mType);
        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (GUI.changed)
        {
            if (mType == TextureType.Self)
            {
                OnSelectTexture(null);
            }
        }

        if (mType == TextureType.Reference)
        {
            GUI.changed = false;
            Object obj = EditorGUILayout.ObjectField("Replacement", mTexEx.replacement, typeof(UITexture), true);
            if (GUI.changed)
            {
                OnSelectTexture(obj);
            }

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one texture simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "texture with another one, for example for " +
                                    "swapping an SD font with an HD one, or " +
                                    "replacing an English texture with a Chinese " +
                                    "one. All the textures referencing this texture " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mTexEx && mTexEx.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Texture Change", mTexEx);
                mTexEx.replacement = mReplacement;
                NGUITools.SetDirty(mTexEx);
            }
            return(true);
        }
        else
        {
            return(base.ShouldDrawProperties());
        }
    }
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        NGUIEditorTools.SetLabelWidth(100f);
        UIToggle toggle = target as UIToggle;

        GUILayout.Space(6f);
        GUI.changed = false;

        GUILayout.BeginHorizontal();
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Group", serializedObject, "group", GUILayout.Width(120f));

        GUILayout.Label(" - zero means 'none'");
        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(sp.intValue == 0);
        NGUIEditorTools.DrawProperty("  State of 'None'", serializedObject, "optionCanBeNone");
        EditorGUI.EndDisabledGroup();

        NGUIEditorTools.DrawProperty("Starting State", serializedObject, "startsActive");
        NGUIEditorTools.SetLabelWidth(80f);

        if (NGUIEditorTools.DrawMinimalisticHeader("State Transition"))
        {
            NGUIEditorTools.BeginContents(true);
            NGUIEditorTools.DrawProperty("Sprite", serializedObject, "activeSprite");
            NGUIEditorTools.DrawProperty("Animation", serializedObject, "activeAnimation");

            if (serializedObject.isEditingMultipleObjects)
            {
                NGUIEditorTools.DrawProperty("Instant", serializedObject, "instantTween");
            }
            else
            {
                GUI.changed = false;
                Transition tr = toggle.instantTween ? Transition.Instant : Transition.Smooth;
                GUILayout.BeginHorizontal();
                tr = (Transition)EditorGUILayout.EnumPopup("Transition", tr);
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Toggle Change", toggle);
                    toggle.instantTween = (tr == Transition.Instant);
                    NGUITools.SetDirty(toggle);
                }
            }
            NGUIEditorTools.EndContents();
        }

        NGUIEditorTools.DrawEvents("On Value Change", toggle, toggle.onChange);
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);

        serializedObject.Update();

        GUILayout.Space(3f);

        DrawLegacyFields();

        GUILayout.BeginHorizontal();
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Steps", serializedObject, "numberOfSteps", GUILayout.Width(110f));

        if (sp.intValue == 0)
        {
            GUILayout.Label("= unlimited");
        }
        GUILayout.EndHorizontal();

        OnDrawExtraFields();

        if (NGUIEditorTools.DrawHeader("Appearance", "Appearance", false, true))
        {
            NGUIEditorTools.BeginContents(true);
            SerializedProperty fg = NGUIEditorTools.DrawProperty("Foreground", serializedObject, "mFG");
            NGUIEditorTools.DrawProperty("Background", serializedObject, "mBG");
            NGUIEditorTools.DrawProperty("Thumb", serializedObject, "thumb");

            UIBasicSprite fsp = fg.objectReferenceValue as UIBasicSprite;

            EditorGUI.BeginDisabledGroup(fg.hasMultipleDifferentValues ||
                                         (fsp != null && fsp.type == UIBasicSprite.Type.Filled));
            {
                GUILayout.BeginHorizontal();
                NGUIEditorTools.DrawProperty("Direction", serializedObject, "mFill");
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();

            OnDrawAppearance();
            NGUIEditorTools.EndContents();
        }

        UIProgressBar sb = target as UIProgressBar;

        NGUIEditorTools.DrawEvents("On Value Change", sb, sb.onChange);
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 7
0
    /// <summary>
    /// Helper function that draws a serialized property.
    /// </summary>

    static public SerializedProperty DrawProperty(string label, SerializedObject serializedObject, string property, bool padding, params GUILayoutOption[] options)
    {
        SerializedProperty sp = serializedObject.FindProperty(property);

        if (sp != null)
        {
            if (NGUISettings.minimalisticLook)
            {
                padding = false;
            }

            if (padding)
            {
                EditorGUILayout.BeginHorizontal();
            }

            if (sp.isArray && sp.type != "string")
            {
                DrawArray(serializedObject, property, label ?? property);
            }
            else if (label != null)
            {
                EditorGUILayout.PropertyField(sp, new GUIContent(label), options);
            }
            else
            {
                EditorGUILayout.PropertyField(sp, options);
            }

            if (padding)
            {
                NGUIEditorTools.DrawPadding();
                EditorGUILayout.EndHorizontal();
            }
        }
        else
        {
            Debug.LogWarning("Unable to find property " + property);
        }
        return(sp);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

    void OnGUI()
    {
        Object fnt    = NGUISettings.ambigiousFont;
        UIFont uiFont = (fnt as UIFont);

        NGUIEditorTools.SetLabelWidth(80f);
        GUILayout.Space(3f);

        NGUIEditorTools.DrawHeader("Input", true);
        NGUIEditorTools.BeginContents(false);

        GUILayout.BeginHorizontal();
        mType = (FontType)EditorGUILayout.EnumPopup("Type", mType, GUILayout.MinWidth(200f));
        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();
        Create create = Create.None;

        if (mType == FontType.ImportedBitmap)
        {
            NGUISettings.fontData    = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset;
            NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false, GUILayout.Width(140f)) as Texture2D;
            NGUIEditorTools.EndContents();

            // Draw the atlas selection only if we have the font data and texture specified, just to make it easier
            EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null);
            {
                NGUIEditorTools.DrawHeader("Output", true);
                NGUIEditorTools.BeginContents(false);
                ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false);
                NGUIEditorTools.EndContents();
            }
            EditorGUI.EndDisabledGroup();

            if (NGUISettings.fontData == null)
            {
                EditorGUILayout.HelpBox("To create a font from a previously exported FNT file, you need to use BMFont on " +
                                        "Windows or your choice of Glyph Designer or the less expensive bmGlyph on the Mac.\n\n" +
                                        "Either of these tools will create a FNT file for you that you will drag & drop into the field above.", MessageType.Info);
            }
            else if (NGUISettings.fontTexture == null)
            {
                EditorGUILayout.HelpBox("When exporting your font, you should get two files: the FNT, and the texture. Only one texture can be used per font.", MessageType.Info);
            }
            else if (NGUISettings.atlas == null)
            {
                EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " +
                                        "labels using this font will generate an extra draw call.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info);
            }

            EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null);
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                if (GUILayout.Button("Create the Font"))
                {
                    create = Create.Import;
                }
                GUILayout.Space(20f);
                GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();
        }
        else
        {
            GUILayout.BeginHorizontal();
            if (NGUIEditorTools.DrawPrefixButton("Source"))
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }

            Font ttf = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont as Font, typeof(Font), false) as Font;
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                NGUISettings.fontSize = EditorGUILayout.IntField("Size", NGUISettings.fontSize, GUILayout.Width(120f));

                if (mType == FontType.Dynamic)
                {
                    NGUISettings.fontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.fontStyle);
                    NGUIEditorTools.DrawPadding();
                }
            }
            GUILayout.EndHorizontal();

            // Choose the font style if there are multiple faces present
            if (mType == FontType.GeneratedBitmap)
            {
                if (!FreeType.isPresent)
                {
                    string filename = (Application.platform == RuntimePlatform.WindowsEditor) ? "FreeType.dll" : "FreeType.dylib";

                    EditorGUILayout.HelpBox("Assets/NGUI/Editor/" + filename + " is missing", MessageType.Error);

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20f);

                    if (GUILayout.Button("Find " + filename))
                    {
                        string path = EditorUtility.OpenFilePanel("Find " + filename, NGUISettings.currentPath,
                                                                  (Application.platform == RuntimePlatform.WindowsEditor) ? "dll" : "dylib");

                        if (!string.IsNullOrEmpty(path))
                        {
                            if (System.IO.Path.GetFileName(path) == filename)
                            {
                                NGUISettings.currentPath    = System.IO.Path.GetDirectoryName(path);
                                NGUISettings.pathToFreeType = path;
                            }
                            else
                            {
                                Debug.LogError("The library must be named '" + filename + "'");
                            }
                        }
                    }
                    GUILayout.Space(20f);
                    GUILayout.EndHorizontal();
                }
                else if (ttf != null)
                {
                    string[] faces = FreeType.GetFaces(ttf);

                    if (faces != null)
                    {
                        if (mFaceIndex >= faces.Length)
                        {
                            mFaceIndex = 0;
                        }

                        if (faces.Length > 1)
                        {
                            GUILayout.Label("Style", EditorStyles.boldLabel);
                            for (int i = 0; i < faces.Length; ++i)
                            {
                                GUILayout.BeginHorizontal();
                                GUILayout.Space(10f);
                                if (DrawOption(i == mFaceIndex, " " + faces[i]))
                                {
                                    mFaceIndex = i;
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }

                    GUILayout.Label("Characters", EditorStyles.boldLabel);

                    CharacterMap cm = characterMap;

                    GUILayout.BeginHorizontal(GUILayout.Width(100f));
                    GUILayout.BeginVertical();
                    GUI.changed = false;
                    if (DrawOption(cm == CharacterMap.Numeric, " Numeric"))
                    {
                        cm = CharacterMap.Numeric;
                    }
                    if (DrawOption(cm == CharacterMap.Ascii, " ASCII"))
                    {
                        cm = CharacterMap.Ascii;
                    }
                    if (DrawOption(cm == CharacterMap.Latin, " Latin"))
                    {
                        cm = CharacterMap.Latin;
                    }
                    if (DrawOption(cm == CharacterMap.Custom, " Custom"))
                    {
                        cm = CharacterMap.Custom;
                    }
                    if (GUI.changed)
                    {
                        characterMap = cm;
                    }
                    GUILayout.EndVertical();

                    EditorGUI.BeginDisabledGroup(cm != CharacterMap.Custom);
                    {
                        if (cm != CharacterMap.Custom)
                        {
                            string chars = "";

                            if (cm == CharacterMap.Ascii)
                            {
                                for (int i = 33; i < 127; ++i)
                                {
                                    chars += System.Convert.ToChar(i);
                                }
                            }
                            else if (cm == CharacterMap.Numeric)
                            {
                                chars = "01234567890";
                            }
                            else if (cm == CharacterMap.Latin)
                            {
                                for (int i = 33; i < 127; ++i)
                                {
                                    chars += System.Convert.ToChar(i);
                                }

                                for (int i = 161; i < 256; ++i)
                                {
                                    chars += System.Convert.ToChar(i);
                                }
                            }

                            NGUISettings.charsToInclude = chars;
                        }

                        GUI.changed = false;

                        string text = NGUISettings.charsToInclude;

                        if (cm == CharacterMap.Custom)
                        {
                            text = EditorGUILayout.TextArea(text, GUI.skin.textArea,
                                                            GUILayout.Height(80f), GUILayout.Width(Screen.width - 100f));
                        }
                        else
                        {
                            GUILayout.Label(text, GUI.skin.textArea,
                                            GUILayout.Height(80f), GUILayout.Width(Screen.width - 100f));
                        }

                        if (GUI.changed)
                        {
                            string final = "";

                            for (int i = 0; i < text.Length; ++i)
                            {
                                char c = text[i];
                                if (c < 33)
                                {
                                    continue;
                                }
                                string s = c.ToString();
                                if (!final.Contains(s))
                                {
                                    final += s;
                                }
                            }

                            if (final.Length > 0)
                            {
                                char[] chars = final.ToCharArray();
                                System.Array.Sort(chars);
                                final = new string(chars);
                            }
                            else
                            {
                                final = "";
                            }

                            NGUISettings.charsToInclude = final;
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                    GUILayout.EndHorizontal();
                }
            }
            NGUIEditorTools.EndContents();

            if (mType == FontType.Dynamic)
            {
                EditorGUI.BeginDisabledGroup(ttf == null);
                GUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                if (GUILayout.Button("Create the Font"))
                {
                    create = Create.Dynamic;
                }
                GUILayout.Space(20f);
                GUILayout.EndHorizontal();
                EditorGUI.EndDisabledGroup();
#if UNITY_3_5
                EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
                // Helpful info
                if (ttf == null)
                {
                    EditorGUILayout.HelpBox("You don't have to create a UIFont to use dynamic fonts. You can just reference the Unity Font directly on the label.", MessageType.Info);
                }
                EditorGUILayout.HelpBox("Please note that dynamic fonts can't be made a part of an atlas, and using dynamic fonts will result in at least one extra draw call.", MessageType.Warning);
#endif
            }
            else
            {
                bool isBuiltIn = (ttf != null) && string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(ttf));

                // Draw the atlas selection only if we have the font data and texture specified, just to make it easier
                EditorGUI.BeginDisabledGroup(ttf == null || isBuiltIn || !FreeType.isPresent);
                {
                    NGUIEditorTools.DrawHeader("Output", true);
                    NGUIEditorTools.BeginContents(false);
                    ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false);
                    NGUIEditorTools.EndContents();

                    if (ttf == null)
                    {
                        EditorGUILayout.HelpBox("You can create a bitmap font by specifying a dynamic font to use as the source.", MessageType.Info);
                    }
                    else if (isBuiltIn)
                    {
                        EditorGUILayout.HelpBox("You chose an embedded font. You can't create a bitmap font from an embedded resource.", MessageType.Warning);
                    }
                    else if (NGUISettings.atlas == null)
                    {
                        EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " +
                                                "labels using this font will generate an extra draw call.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info);
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    if (GUILayout.Button("Create the Font"))
                    {
                        create = Create.Bitmap;
                    }
                    GUILayout.Space(20f);
                    GUILayout.EndHorizontal();
                }
                EditorGUI.EndDisabledGroup();
            }
        }

        if (create == Create.None)
        {
            return;
        }

        // Open the "Save As" file dialog
#if UNITY_3_5
        string prefabPath = EditorUtility.SaveFilePanel("Save As",
                                                        NGUISettings.currentPath, "New Font.prefab", "prefab");
#else
        string prefabPath = EditorUtility.SaveFilePanelInProject("Save As",
                                                                 "New Font.prefab", "prefab", "Save font as...", NGUISettings.currentPath);
#endif
        if (string.IsNullOrEmpty(prefabPath))
        {
            return;
        }
        NGUISettings.currentPath = System.IO.Path.GetDirectoryName(prefabPath);

        // Load the font's prefab
        GameObject go     = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
        Object     prefab = null;
        string     fontName;

        // Font doesn't exist yet
        if (go == null || go.GetComponent <UIFont>() == null)
        {
            // Create a new prefab for the atlas
            prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);

            fontName = prefabPath.Replace(".prefab", "");
            fontName = fontName.Substring(prefabPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Create a new game object for the font
            go     = new GameObject(fontName);
            uiFont = go.AddComponent <UIFont>();
        }
        else
        {
            uiFont   = go.GetComponent <UIFont>();
            fontName = go.name;
        }

        if (create == Create.Dynamic)
        {
            uiFont.atlas            = null;
            uiFont.dynamicFont      = NGUISettings.dynamicFont;
            uiFont.dynamicFontStyle = NGUISettings.fontStyle;
            uiFont.defaultSize      = NGUISettings.fontSize;
        }
        else if (create == Create.Import)
        {
            Material mat = null;

            if (NGUISettings.atlas != null)
            {
                // Add the font's texture to the atlas
                UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, NGUISettings.fontTexture);
            }
            else
            {
                // Create a material for the font
                string matPath = prefabPath.Replace(".prefab", ".mat");
                mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                // If the material doesn't exist, create it
                if (mat == null)
                {
                    Shader shader = Shader.Find("Unlit/Transparent Colored");
                    mat = new Material(shader);

                    // Save the material
                    AssetDatabase.CreateAsset(mat, matPath);
                    AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                    // Load the material so it's usable
                    mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                }

                mat.mainTexture = NGUISettings.fontTexture;
            }

            uiFont.dynamicFont = null;
            BMFontReader.Load(uiFont.bmFont, NGUITools.GetHierarchy(uiFont.gameObject), NGUISettings.fontData.bytes);

            if (NGUISettings.atlas == null)
            {
                uiFont.atlas    = null;
                uiFont.material = mat;
            }
            else
            {
                uiFont.spriteName = NGUISettings.fontTexture.name;
                uiFont.atlas      = NGUISettings.atlas;
            }
            NGUISettings.fontSize = uiFont.defaultSize;
        }
        else if (create == Create.Bitmap)
        {
            // Create the bitmap font
            BMFont    bmFont;
            Texture2D tex;

            if (FreeType.CreateFont(
                    NGUISettings.dynamicFont,
                    NGUISettings.fontSize, mFaceIndex,
                    NGUISettings.charsToInclude, out bmFont, out tex))
            {
                uiFont.bmFont = bmFont;
                tex.name      = fontName;

                if (NGUISettings.atlas != null)
                {
                    // Add this texture to the atlas and destroy it
                    UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, tex);
                    NGUITools.DestroyImmediate(tex);
                    NGUISettings.fontTexture = null;
                    tex = null;

                    uiFont.atlas      = NGUISettings.atlas;
                    uiFont.spriteName = fontName;
                }
                else
                {
                    string texPath = prefabPath.Replace(".prefab", ".png");
                    string matPath = prefabPath.Replace(".prefab", ".mat");

                    byte[]     png = tex.EncodeToPNG();
                    FileStream fs  = File.OpenWrite(texPath);
                    fs.Write(png, 0, png.Length);
                    fs.Close();

                    // See if the material already exists
                    Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                    // If the material doesn't exist, create it
                    if (mat == null)
                    {
                        Shader shader = Shader.Find("Unlit/Transparent Colored");
                        mat = new Material(shader);

                        // Save the material
                        AssetDatabase.CreateAsset(mat, matPath);
                        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                        // Load the material so it's usable
                        mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                    }
                    else
                    {
                        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
                    }

                    // Re-load the texture
                    tex = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture2D)) as Texture2D;

                    // Assign the texture
                    mat.mainTexture          = tex;
                    NGUISettings.fontTexture = tex;

                    uiFont.atlas    = null;
                    uiFont.material = mat;
                }
            }
            else
            {
                return;
            }
        }

        if (prefab != null)
        {
            // Update the prefab
            PrefabUtility.ReplacePrefab(go, prefab);
            DestroyImmediate(go);
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            // Select the atlas
            go     = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
            uiFont = go.GetComponent <UIFont>();
        }

        if (uiFont != null)
        {
            NGUISettings.ambigiousFont = uiFont;
        }
        MarkAsChanged();
        Selection.activeGameObject = go;
    }
Exemplo n.º 9
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UILabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            GUI.changed = false;
            fnt         = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            GUI.changed = false;
            ttf         = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }

        NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat");

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent)
                    {
                        GUILayout.Label(" Actual: " + mLabel.finalFontSize + "/" + mLabel.defaultFontSize);
                    }
                    else
                    {
                        GUILayout.Label(" Default: " + mLabel.defaultFontSize);
                    }
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier");

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;
            if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent)
            {
                NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f));
            }

            if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth");
                if (s != null && s.intValue < 1)
                {
                    GUILayout.Label("unlimited");
                }
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                GUILayout.BeginHorizontal();
                SerializedProperty colorSp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUI.SetNextControlName("Encoded Color");
                mEncodedEffectColor = EditorGUILayout.TextField("", mEncodedEffectColor, GUILayout.Width(50f));
                GUILayout.EndHorizontal();
                if (colorSp != null)
                {
                    if (GUI.GetNameOfFocusedControl() == "Encoded Color")
                    {
                        if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.Used)
                        {
                            System.Text.StringBuilder builder = new System.Text.StringBuilder();
                            for (int index = mEncodedEffectColor.Length; index < 6; ++index)
                            {
                                builder.Append('0');
                            }
                            mEncodedEffectColor += builder;
                            colorSp.colorValue   = NGUIText.ParseColor24(mEncodedEffectColor, 0);
                        }
                    }
                    else
                    {
                        mEncodedEffectColor = NGUIText.EncodeColor24(colorSp.colorValue);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 10
0
    void DrawFont()
    {
        if (NGUIEditorTools.DrawHeader("Font"))
        {
            NGUIEditorTools.BeginContents();

            SerializedProperty ttf = null;

            GUILayout.BeginHorizontal();
            {
                if (NGUIEditorTools.DrawPrefixButton("Font"))
                {
                    if (mType == FontType.Bitmap)
                    {
                        ComponentSelector.Show <UIFont>(OnBitmapFont);
                    }
                    else
                    {
                        ComponentSelector.Show <Font>(OnDynamicFont, new string[] { ".ttf", ".otf" });
                    }
                }

#if DYNAMIC_FONT
                GUI.changed = false;
                mType       = (FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f));

                if (GUI.changed)
                {
                    GUI.changed = false;

                    if (mType == FontType.Bitmap)
                    {
                        serializedObject.FindProperty("trueTypeFont").objectReferenceValue = null;
                    }
                    else
                    {
                        serializedObject.FindProperty("bitmapFont").objectReferenceValue = null;
                    }
                }
#else
                mType = FontType.Bitmap;
#endif

                if (mType == FontType.Bitmap)
                {
                    NGUIEditorTools.DrawProperty("", serializedObject, "bitmapFont", GUILayout.MinWidth(40f));
                }
                else
                {
                    ttf = NGUIEditorTools.DrawProperty("", serializedObject, "trueTypeFont", GUILayout.MinWidth(40f));
                }
            }
            GUILayout.EndHorizontal();

            if (ttf != null && ttf.objectReferenceValue != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup(ttf.hasMultipleDifferentValues);
                    NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f));
                    NGUIEditorTools.DrawProperty("", serializedObject, "fontStyle", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f));
            }

            NGUIEditorTools.DrawProperty("Text Color", serializedObject, "textColor");

            GUILayout.BeginHorizontal();
            NGUIEditorTools.SetLabelWidth(66f);
            EditorGUILayout.PrefixLabel("Padding");
            NGUIEditorTools.SetLabelWidth(14f);
            NGUIEditorTools.DrawProperty("X", serializedObject, "padding.x", GUILayout.MinWidth(30f));
            NGUIEditorTools.DrawProperty("Y", serializedObject, "padding.y", GUILayout.MinWidth(30f));
            NGUIEditorTools.DrawPadding();
            NGUIEditorTools.SetLabelWidth(80f);
            GUILayout.EndHorizontal();

            NGUIEditorTools.EndContents();
        }
    }
Exemplo n.º 11
0
    public void DrawAnchorTransform()
    {
        if (NGUIEditorTools.DrawHeader("Anchors"))
        {
            NGUIEditorTools.BeginContents();
            NGUIEditorTools.SetLabelWidth(NGUISettings.minimalisticLook ? 69f : 62f);

            EditorGUI.BeginDisabledGroup(!((target as UIRect).canBeAnchored));
            GUILayout.BeginHorizontal();
            AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType);
            NGUIEditorTools.DrawPadding();
            GUILayout.EndHorizontal();

            SerializedProperty[] tg = new SerializedProperty[4];
            for (int i = 0; i < 4; ++i)
            {
                tg[i] = serializedObject.FindProperty(FieldName[i] + ".target");
            }

            if (mAnchorType == AnchorType.None && type != AnchorType.None)
            {
                if (type == AnchorType.Unified)
                {
                    if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null)
                    {
                        UIRect rect   = target as UIRect;
                        UIRect parent = NGUITools.FindInParents <UIRect>(rect.cachedTransform.parent);

                        if (parent != null)
                        {
                            for (int i = 0; i < 4; ++i)
                            {
                                mTarget[i] = parent.cachedTransform;
                            }
                        }
                    }
                }

                for (int i = 0; i < 4; ++i)
                {
                    tg[i].objectReferenceValue = mTarget[i];
                    mTarget[i] = null;
                }
                UpdateAnchors(true);
            }

            if (type != AnchorType.None)
            {
                NGUIEditorTools.DrawPaddedProperty("Execute", serializedObject, "updateAnchors");
            }

            if (type == AnchorType.Advanced)
            {
                DrawAnchor(0, true);
                DrawAnchor(1, true);
                DrawAnchor(2, true);
                DrawAnchor(3, true);
            }
            else if (type == AnchorType.Unified)
            {
                DrawSingleAnchorSelection();

                DrawAnchor(0, false);
                DrawAnchor(1, false);
                DrawAnchor(2, false);
                DrawAnchor(3, false);
            }
            else if (type == AnchorType.None && mAnchorType != type)
            {
                // Save values to make it easy to "go back"
                for (int i = 0; i < 4; ++i)
                {
                    mTarget[i] = tg[i].objectReferenceValue as Transform;
                    tg[i].objectReferenceValue = null;
                }

                serializedObject.FindProperty("leftAnchor.relative").floatValue   = 0f;
                serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f;
                serializedObject.FindProperty("rightAnchor.relative").floatValue  = 1f;
                serializedObject.FindProperty("topAnchor.relative").floatValue    = 1f;
            }

            mAnchorType = type;
            OnDrawFinalProperties();
            EditorGUI.EndDisabledGroup();
            NGUIEditorTools.EndContents();
        }
    }
Exemplo n.º 12
0
    public override void OnInspectorGUI()
    {
        UIInput input = target as UIInput;

        serializedObject.Update();
        GUILayout.Space(3f);
        NGUIEditorTools.SetLabelWidth(110f);
        //NGUIEditorTools.DrawProperty(serializedObject, "m_Script");

        EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
        SerializedProperty label = NGUIEditorTools.DrawProperty(serializedObject, "label");

        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(label == null || label.objectReferenceValue == null);
        {
            if (Application.isPlaying)
            {
                NGUIEditorTools.DrawPaddedProperty("Value", serializedObject, "mValue");
            }
            else
            {
                NGUIEditorTools.DrawPaddedProperty("Starting Value", serializedObject, "mValue");
            }
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "savedAs");
            NGUIEditorTools.DrawProperty("Active Text Color", serializedObject, "activeTextColor");

            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            {
                if (label != null && label.objectReferenceValue != null)
                {
                    SerializedObject ob = new SerializedObject(label.objectReferenceValue);
                    ob.Update();
                    NGUIEditorTools.DrawProperty("Inactive Color", ob, "mColor");
                    ob.ApplyModifiedProperties();
                }
                else
                {
                    EditorGUILayout.ColorField("Inactive Color", Color.white);
                }
            }
            EditorGUI.EndDisabledGroup();

            NGUIEditorTools.DrawProperty("Caret Color", serializedObject, "caretColor");
            NGUIEditorTools.DrawProperty("Selection Color", serializedObject, "selectionColor");
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "inputType");
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "validation");
            NGUIEditorTools.DrawPaddedProperty("Mobile Keyboard", serializedObject, "keyboardType");
            NGUIEditorTools.DrawPaddedProperty("  Hide Input", serializedObject, "hideInput");
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "onReturnKey");

            // Deprecated, use UIKeyNavigation instead.
            //NGUIEditorTools.DrawProperty(serializedObject, "selectOnTab");

            SerializedProperty sp = serializedObject.FindProperty("characterLimit");

            GUILayout.BeginHorizontal();

            if (sp.hasMultipleDifferentValues || input.characterLimit > 0)
            {
                EditorGUILayout.PropertyField(sp);
                NGUIEditorTools.DrawPadding();
            }
            else
            {
                EditorGUILayout.PropertyField(sp);
                GUILayout.Label("unlimited");
            }
            GUILayout.EndHorizontal();

            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            NGUIEditorTools.DrawEvents("On Submit", input, input.onSubmit);
            NGUIEditorTools.DrawEvents("On Change", input, input.onChange);
            EditorGUI.EndDisabledGroup();
        }
        EditorGUI.EndDisabledGroup();
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 13
0
    public override void OnInspectorGUI()
    {
        mFont = target as UIFont;
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.Space(6f);

        if (mFont.replacement != null)
        {
            mType        = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        GUI.changed = false;
        GUILayout.BeginHorizontal();
        mType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);
        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (GUI.changed)
        {
            if (mType == FontType.Bitmap)
            {
                OnSelectFont(null);
            }

            if (mType != FontType.Dynamic && mFont.dynamicFont != null)
            {
                mFont.dynamicFont = null;
            }
        }

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one font simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "font with another one, for example for " +
                                    "swapping an SD font with an HD one, or " +
                                    "replacing an English font with a Chinese " +
                                    "one. All the labels referencing this font " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Font Change", mFont);
                mFont.replacement = mReplacement;
                NGUITools.SetDirty(mFont);
            }
            return;
        }
        else if (mType == FontType.Dynamic)
        {
#if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFont = fnt;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

            if (mFont.material != mat)
            {
                NGUIEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }

            GUILayout.BeginHorizontal();
            int       size  = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f));
            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle);
            NGUIEditorTools.DrawPadding();
            GUILayout.EndHorizontal();

            if (size != mFont.defaultSize)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.defaultSize = size;
            }

            if (style != mFont.dynamicFontStyle)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle = style;
            }
#endif
        }
        else
        {
            ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas, true);

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
                EditorGUILayout.Space();
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            // For updating the font's data when importing from an external source, such as the texture packer
            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsChanged();
                    resetWidthHeight = true;
                    Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Texture2D tex = mFont.texture;

                if (tex != null && mFont.atlas == null)
                {
                    // Pixels are easier to work with than UVs
                    Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                    // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                    if (resetWidthHeight)
                    {
                        pixels.width  = mFont.texWidth;
                        pixels.height = mFont.texHeight;
                    }

                    // Font sprite rectangle
                    pixels = EditorGUILayout.RectField("Pixel Rect", pixels);

                    // Convert the pixel coordinates back to UV coordinates
                    Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                    if (mFont.uvRect != uvRect)
                    {
                        NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                        mFont.uvRect = uvRect;
                    }
                    //NGUIEditorTools.DrawSeparator();
                    EditorGUILayout.Space();
                }
            }
        }

        // Dynamic fonts don't support emoticons
        if (!mFont.isDynamic && mFont.bmFont.isValid)
        {
            if (mFont.atlas != null)
            {
                if (NGUIEditorTools.DrawHeader("Symbols and Emoticons"))
                {
                    NGUIEditorTools.BeginContents();

                    List <BMSymbol> symbols = mFont.symbols;

                    for (int i = 0; i < symbols.Count;)
                    {
                        BMSymbol sym = symbols[i];

                        GUILayout.BeginHorizontal();
                        GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                        if (NGUIEditorTools.DrawSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite, GUILayout.MinWidth(100f)))
                        {
                            mSelectedSymbol = sym;
                        }

                        if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                        {
                            if (mFont.atlas != null)
                            {
                                NGUISettings.atlas          = mFont.atlas;
                                NGUISettings.selectedSprite = sym.spriteName;
                                NGUIEditorTools.Select(mFont.atlas.gameObject);
                            }
                        }

                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                        {
                            NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                            mSymbolSequence = sym.sequence;
                            mSymbolSprite   = sym.spriteName;
                            symbols.Remove(sym);
                            mFont.MarkAsChanged();
                        }
                        GUI.backgroundColor = Color.white;
                        GUILayout.EndHorizontal();
                        GUILayout.Space(4f);
                        ++i;
                    }

                    if (symbols.Count > 0)
                    {
                        GUILayout.Space(6f);
                    }

                    GUILayout.BeginHorizontal();
                    mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                    NGUIEditorTools.DrawSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                    bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                    GUI.backgroundColor = isValid ? Color.green : Color.grey;

                    if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                    {
                        NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                        mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                        mFont.MarkAsChanged();
                        mSymbolSequence = "";
                        mSymbolSprite   = "";
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();

                    if (symbols.Count == 0)
                    {
                        EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                    }
                    else
                    {
                        GUILayout.Space(4f);
                    }

                    NGUIEditorTools.EndContents();
                }
            }
        }

        if (mFont.bmFont != null && mFont.bmFont.isValid)
        {
            if (NGUIEditorTools.DrawHeader("Modify"))
            {
                NGUIEditorTools.BeginContents();

                UISpriteData sd = mFont.sprite;

                bool disable = (sd != null && (sd.paddingLeft != 0 || sd.paddingBottom != 0));
                EditorGUI.BeginDisabledGroup(disable || mFont.packedFontShader);

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                EditorGUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical();
                NGUISettings.foregroundColor = EditorGUILayout.ColorField("Foreground", NGUISettings.foregroundColor);
                NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);
                GUILayout.EndVertical();
                mCurve = EditorGUILayout.CurveField("", mCurve, GUILayout.Width(40f), GUILayout.Height(40f));
                GUILayout.EndHorizontal();

                if (GUILayout.Button("Add a Shadow"))
                {
                    ApplyEffect(Effect.Shadow, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Add a Soft Outline"))
                {
                    ApplyEffect(Effect.Outline, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Rebalance Colors"))
                {
                    ApplyEffect(Effect.Rebalance, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Apply Curve to Alpha"))
                {
                    ApplyEffect(Effect.AlphaCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Apply Curve to Foreground"))
                {
                    ApplyEffect(Effect.ForegroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Apply Curve to Background"))
                {
                    ApplyEffect(Effect.BackgroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }

                GUILayout.Space(10f);
                if (GUILayout.Button("Add Transparent Border (+1)"))
                {
                    ApplyEffect(Effect.Border, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Remove Border (-1)"))
                {
                    ApplyEffect(Effect.Crop, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }

                EditorGUILayout.EndVertical();
                GUILayout.Space(20f);
                EditorGUILayout.EndHorizontal();

                EditorGUI.EndDisabledGroup();

                if (disable)
                {
                    GUILayout.Space(3f);
                    EditorGUILayout.HelpBox("The sprite used by this font has been trimmed and is not suitable for modification. " +
                                            "Try re-adding this sprite with 'Trim Alpha' disabled.", MessageType.Warning);
                }

                NGUIEditorTools.EndContents();
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic || mFont.bmFont.isValid)
        {
            if (mFont.atlas == null)
            {
                mView      = View.Font;
                mUseShader = false;
            }
        }

        // Preview option
        if (!mFont.isDynamic && mFont.atlas != null)
        {
            GUILayout.BeginHorizontal();
            {
                mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                GUILayout.Label("Shader", GUILayout.Width(45f));
                mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
            }
            GUILayout.EndHorizontal();
        }
    }
Exemplo n.º 14
0
    // ========================================================================== //

    /* public - [Do] Function
     * 외부 객체가 호출                         */

    /* public - [Event] Function
     * 프랜드 객체가 호출                       */

    // ========================================================================== //

    /* protected - [abstract & virtual]         */

    /* protected - [Event] Function
     * 자식 객체가 호출                         */

    /* protected - Override & Unity API         */
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        _pTarget = target as CUIButtonMultiToggle;
        _pAtlas  = _pTarget.GetComponent <UISprite>().atlas;

        if (_pTarget.listEvent == null)
        {
            _pTarget.listEvent = new List <CUIButtonMultiToggle.SButtonToggle>();
        }

        _iOriginStateCount = _pTarget.listEvent.Count;
        _iOriginStateCount = EditorGUILayout.IntField("상태 개수", _iOriginStateCount);

        if (_pTarget.listEvent == null)
        {
            _pTarget.listEvent = new List <CUIButtonMultiToggle.SButtonToggle>();
        }

        if (_pAtlas == null)
        {
            Debug.LogWarning("UI Sprite의 Atlas가 세팅되지 않았습니다..", _pTarget);
            return;
        }

        if (_iOriginStateCount != _pTarget.listEvent.Count)
        {
            if (_iOriginStateCount < _pTarget.listEvent.Count)
            {
                int iLoopCount = _pTarget.listEvent.Count - _iOriginStateCount;
                try
                {
                    for (int i = 0; i < iLoopCount; i++)
                    {
                        _pTarget.listEvent.Remove(_pTarget.listEvent[i]);
                    }
                }
                catch (System.Exception e)
                {
                    Debug.LogWarning(e);
                }
            }
            else
            {
                int iLoopCount = _iOriginStateCount - _pTarget.listEvent.Count;
                for (int i = 0; i < iLoopCount; i++)
                {
                    _pTarget.listEvent.Add(new CUIButtonMultiToggle.SButtonToggle());
                }
            }
        }

        if (_iOriginStateCount != 0)
        {
            _pTarget.iDefaultState = EditorGUILayout.IntField(string.Format("기본 상태 1 ~ {0}", _pTarget.listEvent.Count), _pTarget.iDefaultState);
        }
        if (_pTarget.iDefaultState > _pTarget.listEvent.Count || _pTarget.iDefaultState <= 0)
        {
            Debug.LogError("상태개수 범위안의 숫자를 선택해 주십시오.");
        }

        _pTarget._eButtonToggleOption = (CUIButtonMultiToggle.EButtonToggleOption)EditorGUILayout.EnumPopup("옵션선택", _pTarget._eButtonToggleOption);

        for (int i = 0; i < _pTarget.listEvent.Count; i++)
        {
            CUIButtonMultiToggle.SButtonToggle sToggle = _pTarget.listEvent[i];
            //NGUIEditorTools.DrawEvents("On StateChange", _pTarget, sToggle.listEvent, false);

            if (NGUIEditorTools.DrawHeader(string.Format("OnChangeState_{0}", i + 1)) == false)
            {
                continue;
            }

            if (_pTarget.listEvent[i].listEvent == null)
            {
                _pTarget.listEvent[i].listEvent = new List <EventDelegate>();
            }

            EventDelegateEditor.Field(_pTarget, _pTarget.listEvent[i].listEvent, false);
            // 여기서 필요한 로직만 가져옴
            //NGUIEditorTools.DrawAdvancedSpriteField(_pAtlas, sToggle.strSpriteName, SelectSprite, false);
            GUILayout.BeginHorizontal();
            {
                if (NGUIEditorTools.DrawPrefixButton("Sprite"))
                {
                    NGUISettings.atlas          = _pAtlas;
                    NGUISettings.selectedSprite = sToggle.strSpriteName;
                    SpriteSelector.Show(SelectSprite);
                    _iCurrentEditItemIndex = i;
                }

                GUILayout.BeginHorizontal();
                GUILayout.Label(sToggle.strSpriteName, "HelpBox", GUILayout.Height(18f));
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();
            }
            GUILayout.EndHorizontal();
        }
    }
Exemplo n.º 15
0
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);

        serializedObject.Update();

        GUILayout.Space(3f);

        DrawLegacyFields();

        if (serializedObject.targetObject as UISliderLoop)
        {
            NGUIEditorTools.DrawProperty("Target Value", serializedObject, "TargetValue", GUILayout.MinWidth(20f));
        }

        GUILayout.BeginHorizontal();

        SerializedProperty sp = NGUIEditorTools.DrawProperty("Steps", serializedObject, "numberOfSteps", GUILayout.Width(110f));

        if (sp.intValue == 0)
        {
            GUILayout.Label("= unlimited");
        }
        GUILayout.EndHorizontal();
        if (serializedObject.targetObject as UISliderLoop ||
            serializedObject.targetObject as UISliderDouble ||
            serializedObject.targetObject as UISliderMove ||
            serializedObject.targetObject as UISliderNormal)
        {
            NGUIEditorTools.DrawProperty("ScheduleLabel", serializedObject, "ScheduleLabel", GUILayout.MinWidth(20f));
        }

        if (serializedObject.targetObject as UISliderLoop ||
            serializedObject.targetObject as UISliderDouble ||
            serializedObject.targetObject as UISliderMove)
        {
            NGUIEditorTools.DrawProperty("Speed", serializedObject, "Speed", GUILayout.MinWidth(20f));
        }

        if (serializedObject.targetObject as UISliderMove)
        {
            NGUIEditorTools.DrawProperty("TargetValue", serializedObject, "mTargetValue", GUILayout.MinWidth(20f));
            NGUIEditorTools.DrawProperty("MaxValue", serializedObject, "mMaxValue", GUILayout.MinWidth(20f));
            NGUIEditorTools.DrawProperty("CurrentValue", serializedObject, "mCurrentValue", GUILayout.MinWidth(20f));
        }

        OnDrawExtraFields();

        if (NGUIEditorTools.DrawHeader("Appearance", "Appearance", false, true))
        {
            NGUIEditorTools.BeginContents(true);
            NGUIEditorTools.DrawProperty("Foreground", serializedObject, "mFG");
            if (serializedObject.targetObject as UISliderDouble)
            {
                NGUIEditorTools.DrawProperty("MaskGround", serializedObject, "MaskGround");
            }
            NGUIEditorTools.DrawProperty("Background", serializedObject, "mBG");
            NGUIEditorTools.DrawProperty("Thumb", serializedObject, "thumb");

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Direction", serializedObject, "mFill");
            NGUIEditorTools.DrawPadding();
            GUILayout.EndHorizontal();

            OnDrawAppearance();
            NGUIEditorTools.EndContents();
        }

        UIProgressBar sb = target as UIProgressBar;

        NGUIEditorTools.DrawEvents("On Value Change", sb, sb.onChange);
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 16
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);

        if (mAtlas == null)
        {
            EditorGUILayout.HelpBox("Invalid asset. Please re-create it.", MessageType.Error, true);
            return;
        }

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw(mAtlas.replacement, OnSelectAtlas, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != (mAtlas as INGUIAtlas) && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object);
                mAtlas.replacement = mReplacement;
                NGUITools.SetDirty(mAtlas as Object);
            }
            return;
        }

        if (mAtlas is UIAtlas)
        {
            EditorGUILayout.HelpBox("Legacy atlas type should be upgraded in order to maintain compatibility with Unity 2018 and newer.", MessageType.Warning, true);

            if (GUILayout.Button("Upgrade"))
            {
                var path = EditorUtility.SaveFilePanelInProject("Save As", (mAtlas as Object).name + ".asset", "asset", "Save atlas as...", NGUISettings.currentPath);

                if (!string.IsNullOrEmpty(path))
                {
                    NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                    var asset = ScriptableObject.CreateInstance <NGUIAtlas>();
                    asset.spriteList     = mAtlas.spriteList;
                    asset.spriteMaterial = mAtlas.spriteMaterial;

                    var atlasName = path.Replace(".asset", "");
                    atlasName  = atlasName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
                    asset.name = atlasName;

                    var existing = AssetDatabase.LoadMainAssetAtPath(path);
                    if (existing != null)
                    {
                        EditorUtility.CopySerialized(asset, existing);
                    }
                    else
                    {
                        AssetDatabase.CreateAsset(asset, path);
                    }

                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                    asset = AssetDatabase.LoadAssetAtPath <NGUIAtlas>(path);
                    NGUISettings.atlas     = asset;
                    Selection.activeObject = NGUISettings.atlas as Object;

                    if (asset != null)
                    {
                        mAtlas.replacement = asset;
                        mAtlas.MarkAsChanged();
                    }
                }
            }
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsChanged();
        }

        if (mat != null)
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas as Object);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsChanged();
            }

            float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blueColor  = new Color(0f, 0.7f, 1f, 1f);
            Color greenColor = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
                if (sprite == null)
                {
                    sprite = mAtlas.spriteList[0];
                }
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

                Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                if (tex != null)
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = greenColor;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blueColor;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas as Object);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                        NGUITools.SetDirty(mAtlas as Object);
                    }

                    GUILayout.Space(3f);

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("Duplicate"))
                    {
                        var se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name);
                        if (se != null)
                        {
                            NGUISettings.selectedSprite = se.name;
                        }
                    }

                    if (GUILayout.Button("Save As..."))
                    {
                        var path = EditorUtility.SaveFilePanel("Save As",
                                                               NGUISettings.currentPath, sprite.name + ".png", "png");

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            var se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name);

                            if (se != null)
                            {
                                var bytes = se.tex.EncodeToPNG();
                                File.WriteAllBytes(path, bytes);
                                //AssetDatabase.ImportAsset(path);
                                if (se.temporaryTexture)
                                {
                                    DestroyImmediate(se.tex);
                                }
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.DrawHeader("Modify"))
                {
                    NGUIEditorTools.BeginContents();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    EditorGUILayout.BeginVertical();

                    NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);

                    if (GUILayout.Button("Add a Shadow"))
                    {
                        AddShadow(sprite);
                    }
                    if (GUILayout.Button("Add a Soft Outline"))
                    {
                        AddOutline(sprite);
                    }

                    if (GUILayout.Button("Add a Transparent Border"))
                    {
                        AddTransparentBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Clamped Border"))
                    {
                        AddClampedBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Tiled Border"))
                    {
                        AddTiledBorder(sprite);
                    }
                    EditorGUI.BeginDisabledGroup(!sprite.hasBorder);
                    if (GUILayout.Button("Crop Border"))
                    {
                        CropBorder(sprite);
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUILayout.EndVertical();
                    GUILayout.Space(20f);
                    EditorGUILayout.EndHorizontal();

                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUILayout.Space(3f);
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
        }
    }
Exemplo n.º 17
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UIRichText;

        GUILayout.BeginHorizontal();

        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            GUI.changed = false;
            fnt         = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            GUI.changed = false;
            ttf         = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial");
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawProperty("Resize hight", serializedObject, "mResizeHight");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 18
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mIsDynamic  = false;
        mHasSymbols = false;
        mLabel      = mWidget as UILabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                var bmf = mLabel.font;
                if (bmf != null && bmf is UIFont)
                {
                    ComponentSelector.Show <UIFont>(OnNGUIFont);
                }
                else
                {
                    ComponentSelector.Show <NGUIFont>(OnNGUIFont);
                }
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;
        GUI.changed = false;

        if (mFontType == FontType.NGUI)
        {
            fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            // Legacy font support
            if (fnt.objectReferenceValue != null && fnt.objectReferenceValue is GameObject)
            {
                fnt.objectReferenceValue = (fnt.objectReferenceValue as GameObject).GetComponent <UIFont>();
            }

            if (fnt.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

#if UNITY_5_6
        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }
#endif

        NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat");

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            var dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;
            var bmFont  = (fnt != null) ? fnt.objectReferenceValue : null;
            var bm      = bmFont as INGUIFont;

            if (bm != null && bm.isDynamic)
            {
                dynFont     = bm.dynamicFont;
                mHasSymbols = bm.hasSymbols;
                bm          = null;
            }

            if (dynFont != null)
            {
                mIsDynamic = true;

                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    var prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    if (!serializedObject.isEditingMultipleObjects)
                    {
                        var printed = mLabel.finalFontSize;

                        if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent && printed != mLabel.fontSize)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            GUILayout.Label(" Printed: " + printed);
                            EditorGUI.EndDisabledGroup();
                        }
                        else
                        {
                            NGUIEditorTools.DrawPadding();
                        }
                    }
                    else
                    {
                        NGUIEditorTools.DrawPadding();
                    }

                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else if (bmFont != null)
            {
                GUILayout.BeginHorizontal();
                var prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);

                if (!serializedObject.isEditingMultipleObjects)
                {
                    var printed = mLabel.finalFontSize;
                    var def     = mLabel.defaultFontSize;

                    if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent && printed != mLabel.fontSize)
                    {
                        GUILayout.Label(" Printed: " + printed);
                    }
                    else if (printed != def)
                    {
                        GUILayout.Label(" Default: " + def);
                    }
                }

                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier");

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;
            if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent)
            {
                NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f));
            }

            if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth");

                if (s != null)
                {
                    if (s.intValue < 0)
                    {
                        s.intValue = 0;
                    }
                    if (s.intValue == 0)
                    {
                        GUILayout.Label("unlimited");
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                s = NGUIEditorTools.DrawPaddedProperty("Max Height", serializedObject, "mOverflowHeight");

                if (s != null)
                {
                    if (s.intValue < 0)
                    {
                        s.intValue = 0;
                    }
                    if (s.intValue == 0)
                    {
                        GUILayout.Label("unlimited");
                    }
                }

                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            if (bm != null)
            {
                EditorGUI.BeginDisabledGroup(bm.packedFontShader);
            }
            else
            {
                EditorGUI.BeginDisabledGroup(false);
            }

            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));

            EditorGUI.BeginDisabledGroup(!mHasSymbols || !sp.boolValue);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 19
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        BetterList <UIDrawCall> dcs = UIDrawCall.activeList;

        dcs.Sort(delegate(UIDrawCall a, UIDrawCall b)
        {
            return(a.finalRenderQueue.CompareTo(b.finalRenderQueue));
        });

        if (dcs.size == 0)
        {
            EditorGUILayout.HelpBox("No NGUI draw calls present in the scene", MessageType.Info);
            return;
        }

        UIPanel selectedPanel = NGUITools.FindInParents <UIPanel>(Selection.activeGameObject);

        GUILayout.Space(12f);

        NGUIEditorTools.SetLabelWidth(100f);
        ShowFilter show = (NGUISettings.showAllDCs ? ShowFilter.AllPanels : ShowFilter.SelectedPanel);

        if ((ShowFilter)EditorGUILayout.EnumPopup("Draw Call Filter", show) != show)
        {
            NGUISettings.showAllDCs = !NGUISettings.showAllDCs;
        }

        GUILayout.Space(6f);

        if (selectedPanel == null && !NGUISettings.showAllDCs)
        {
            EditorGUILayout.HelpBox("No panel selected", MessageType.Info);
            return;
        }

        NGUIEditorTools.SetLabelWidth(80f);
        mScroll = GUILayout.BeginScrollView(mScroll);

        int dcCount = 0;

        for (int i = 0; i < dcs.size; ++i)
        {
            UIDrawCall dc        = dcs.buffer[i];
            string     key       = "Draw Call " + (i + 1);
            bool       highlight = (selectedPanel == null || selectedPanel == dc.manager);

            if (!highlight)
            {
                if (!NGUISettings.showAllDCs)
                {
                    continue;
                }

                if (UnityEditor.EditorPrefs.GetBool(key, true))
                {
                    GUI.color = new Color(0.85f, 0.85f, 0.85f);
                }
                else
                {
                    GUI.contentColor = new Color(0.85f, 0.85f, 0.85f);
                }
            }
            else
            {
                GUI.contentColor = Color.white;
            }

            ++dcCount;
            string name = key + " of " + dcs.size;
            if (!dc.isActive)
            {
                name = name + " (HIDDEN)";
            }
            else if (!highlight)
            {
                name = name + " (" + dc.manager.name + ")";
            }

            if (NGUIEditorTools.DrawHeader(name, key))
            {
                GUI.color = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);

                NGUIEditorTools.BeginContents();
                EditorGUILayout.ObjectField("Material", dc.dynamicMaterial, typeof(Material), false);

                int count = 0;

                for (int a = 0; a < UIPanel.list.Count; ++a)
                {
                    UIPanel p = UIPanel.list[a];

                    for (int b = 0; b < p.widgets.Count; ++b)
                    {
                        UIWidget w = p.widgets[b];
                        if (w.drawCall == dc)
                        {
                            ++count;
                        }
                    }
                }

                string   myPath = NGUITools.GetHierarchy(dc.manager.cachedGameObject);
                string   remove = myPath + "\\";
                string[] list   = new string[count + 1];
                list[0] = count.ToString();
                count   = 0;

                for (int a = 0; a < UIPanel.list.Count; ++a)
                {
                    UIPanel p = UIPanel.list[a];

                    for (int b = 0; b < p.widgets.Count; ++b)
                    {
                        UIWidget w = p.widgets[b];

                        if (w.drawCall == dc)
                        {
                            string path = NGUITools.GetHierarchy(w.cachedGameObject);
                            list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, ""));
                        }
                    }
                }

                GUILayout.BeginHorizontal();
                int sel = EditorGUILayout.Popup("Widgets", 0, list);
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (sel != 0)
                {
                    count = 0;

                    for (int a = 0; a < UIPanel.list.Count; ++a)
                    {
                        UIPanel p = UIPanel.list[a];

                        for (int b = 0; b < p.widgets.Count; ++b)
                        {
                            UIWidget w = p.widgets[b];

                            if (w.drawCall == dc && ++count == sel)
                            {
                                Selection.activeGameObject = w.gameObject;
                                break;
                            }
                        }
                    }
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Render Q", dc.finalRenderQueue.ToString(), GUILayout.Width(120f));
                bool draw = (Visibility)EditorGUILayout.EnumPopup(dc.isActive ? Visibility.Visible : Visibility.Hidden) == Visibility.Visible;
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (dc.isActive != draw)
                {
                    dc.isActive = draw;
                    NGUITools.SetDirty(dc.manager);
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f));

                if (dc.manager != selectedPanel)
                {
                    if (GUILayout.Button("Select the Panel"))
                    {
                        Selection.activeGameObject = dc.manager.gameObject;
                    }
                    NGUIEditorTools.DrawPadding();
                }
                GUILayout.EndHorizontal();

                if (dc.manager.clipping != UIDrawCall.Clipping.None && !dc.isClipped)
                {
                    EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                            MessageType.Warning);
                }

                NGUIEditorTools.EndContents();
                GUI.color = Color.white;
            }
        }

        if (dcCount == 0)
        {
            EditorGUILayout.HelpBox("No draw calls found", MessageType.Info);
        }
        GUILayout.EndScrollView();
    }
Exemplo n.º 20
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UILabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial");
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    GUILayout.Label(" Default: " + mLabel.defaultFontSize);
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;

            SerializedProperty sp = serializedObject.FindProperty("mText");
            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            SerializedProperty spDic = serializedObject.FindProperty("mDictionaryId");
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayout.Width(76f));
            GUILayout.Space(3f);
            GUILayout.Label("Dictionary");
            GUILayout.EndVertical();
            GUILayout.BeginVertical();

            Rect rectDic = EditorGUILayout.GetControlRect(GUILayout.Height(20.0f));

            GUI.changed = false;
            var textDic = EditorGUI.IntField(rectDic, spDic.intValue);
            if (GUI.changed)
            {
                if (textDic > 0)
                {
                    var str = GetDictionaryString(textDic);
                    sp.stringValue = str;
                }
                spDic.intValue = textDic;
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            GUI.skin.textField.wordWrap = ww;

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 21
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UILabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial");
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    GUILayout.Label(" Default: " + mLabel.defaultFontSize);
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;

            SerializedProperty ovNumberShowType = NGUIEditorTools.DrawPaddedProperty("NumShowType", serializedObject, "mNumShowType");
            NGUISettings.numShowTypeStyle = (UILabel.NumShowType)ovNumberShowType.intValue;

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Spacing", GUILayout.Width(56f));
            NGUIEditorTools.SetLabelWidth(20f);
            NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
            NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
            NGUIEditorTools.DrawPadding();
            NGUIEditorTools.SetLabelWidth(80f);
            GUILayout.EndHorizontal();

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 22
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mAtlas = target as UIAtlas;

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                NGUITools.SetDirty(mAtlas);
            }
            return;
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsChanged();
        }

        #region         //add by chenbin
        if (mAtlas.isBorrowSpriteMode)
        {
            GUI.color = Color.green;
        }
        else
        {
            GUI.color = Color.white;
        }
        GUILayout.Label("\n===	=========================================");
        if (GUILayout.Button("说明"))
        {
            isShowBorrowModeDesc = !isShowBorrowModeDesc;
        }
        if (isShowBorrowModeDesc)
        {
            GUILayout.Label("勾选isBorrowSpriteMode时,表明该atlas是空atlas,\n" +
                            "当有sprit对象来borrow时,atlas会根据名字从\n" +
                            "设置的路径中去取得图片资源。\n" +
                            //"其中资源必须在Resources/下,\n" +
                            "另外atlas必须要引用一个material,\n" +
                            "就算引用的是个空material也行。\n");
        }

        if (mAtlas != null && runTimes == 0)
        {
            runTimes++;
            isBorrowMode = mAtlas.isBorrowSpriteMode;
            //			isUserUnity3DType = mAtlas.useUnity3DType;
        }
        mAtlas.isBorrowSpriteMode = EditorGUILayout.Toggle("isBorrowSpriteMode", mAtlas.isBorrowSpriteMode);
        if (isBorrowMode != mAtlas.isBorrowSpriteMode)
        {
            isBorrowMode = mAtlas.isBorrowSpriteMode;
            UnityEditor.EditorUtility.SetDirty(mAtlas.gameObject);
        }
        //		if (mAtlas.isBorrowSpriteMode) {
        //			mAtlas.useUnity3DType = EditorGUILayout.Toggle ("useUnity3DType", mAtlas.useUnity3DType);
        //			if (isUserUnity3DType != mAtlas.useUnity3DType) {
        //				isUserUnity3DType = mAtlas.useUnity3DType;
        //				UnityEditor.EditorUtility.SetDirty (NGUISettings.atlas.gameObject);
        //			}
        //		}
        GUILayout.Label("============================================\n");
        GUI.color = Color.white;
        if (GUILayout.Button("Clean items if no png"))
        {
            if (EditorUtility.DisplayDialog("Alert", "Really ?", "Do it now!", "NO"))
            {
                UISpriteData        item = null;
                List <UISpriteData> list = new List <UISpriteData> ();
                for (int i = 0; i < mAtlas.spriteList.Count; i++)
                {
                    item = mAtlas.spriteList [i];
                    string path = Application.dataPath + "/" + item.path;
                    path = path.Replace("/upgradeRes/", "/upgradeRes4Dev/");
                    path = path.Replace("/upgradeRes4Publish/", "/upgradeRes4Dev/");
                    if (!File.Exists(path))
                    {
                        Debug.Log(path);
                        list.Add(item);
                    }
                }
                deleteSprites(list);
            }
        }
        #endregion                                    //end ======add by chenbin

        if (mat != null || mAtlas.isBorrowSpriteMode) // modify by chenbin
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsChanged();
            }

            float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null || mAtlas.isBorrowSpriteMode)                 //modify by chenbin
        {
            Color blueColor  = new Color(0f, 0.7f, 1f, 1f);
            Color greenColor = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
//				if (sprite == null) sprite = mAtlas.spriteList[0];  // delete by chenbin
                #region add by chenbin
                if (sprite == null)
                {
                    if (mAtlas.isBorrowSpriteMode)
                    {
                        sprite     = mAtlas.spriteList [0];
                        spriteName = sprite.name;
                        sprite     = mAtlas.borrowSpriteByname(spriteName, null);
                    }
                    else
                    {
                        sprite = mAtlas.spriteList [0];
                    }
                }
                #endregion
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

//				Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;	//delete by chenbin
                #region add by chenbin
                Texture2D tex = null;
                if (mAtlas != null)
                {
                    if (mAtlas.isBorrowSpriteMode)
                    {
                        if (sprite != null && sprite.material != null)
                        {
                            tex = sprite.material.mainTexture as Texture2D;
                        }
                    }
                    else
                    {
                        tex = mAtlas.spriteMaterial.mainTexture as Texture2D;
                    }
                }
                #endregion


//				if (tex != null)		//modify by chenbin
                if (tex != null || (mAtlas != null && mAtlas.isBorrowSpriteMode && sprite != null))                  //modify by chenbin
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = greenColor;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blueColor;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                    }

                    GUILayout.Space(3f);

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("Duplicate"))
                    {
                        string newName = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name);                         // modify by chenbin
                        if (newName != null)
                        {
                            NGUISettings.selectedSprite = newName;                                              // modify by chenbin
                        }
                    }

                    if (GUILayout.Button("Save As..."))
                    {
#if UNITY_3_5
                        string path = EditorUtility.SaveFilePanel("Save As",
                                                                  NGUISettings.currentPath, sprite.name + ".png", "png");
#else
                        string path = EditorUtility.SaveFilePanelInProject("Save As",
                                                                           sprite.name + ".png", "png",
                                                                           "Extract sprite into which file?", NGUISettings.currentPath);
#endif

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name);

                            if (se != null)
                            {
                                byte[] bytes = se.tex.EncodeToPNG();
                                File.WriteAllBytes(path, bytes);
                                AssetDatabase.ImportAsset(path);
                                if (se.temporaryTexture)
                                {
                                    DestroyImmediate(se.tex);
                                }
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.DrawHeader("Modify"))
                {
                    NGUIEditorTools.BeginContents();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    EditorGUILayout.BeginVertical();

                    NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);

                    if (GUILayout.Button("Add a Shadow"))
                    {
                        AddShadow(sprite);
                    }
                    if (GUILayout.Button("Add a Soft Outline"))
                    {
                        AddOutline(sprite);
                    }

                    if (GUILayout.Button("Add a Transparent Border"))
                    {
                        AddTransparentBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Clamped Border"))
                    {
                        AddClampedBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Tiled Border"))
                    {
                        AddTiledBorder(sprite);
                    }
                    EditorGUI.BeginDisabledGroup(!sprite.hasBorder);
                    if (GUILayout.Button("Crop Border"))
                    {
                        CropBorder(sprite);
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUILayout.EndVertical();
                    GUILayout.Space(20f);
                    EditorGUILayout.EndHorizontal();

                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUILayout.Space(3f);
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
        }
    }
Exemplo n.º 23
0
    protected override void DrawProperties()
    {
        SerializedProperty sp = serializedObject.FindProperty("dragHighlight");
        Highlight          ht = sp.boolValue ? Highlight.Press : Highlight.DoNothing;

        GUILayout.BeginHorizontal();
        bool highlight = (Highlight)EditorGUILayout.EnumPopup("Drag Over", ht) == Highlight.Press;

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();
        if (sp.boolValue != highlight)
        {
            sp.boolValue = highlight;
        }

        DrawTransition();
        DrawColors();

        UIButton btn = target as UIButton;

        if (btn.tweenTarget != null)
        {
            UISprite   sprite = btn.tweenTarget.GetComponent <UISprite>();
            UI2DSprite s2d    = btn.tweenTarget.GetComponent <UI2DSprite>();

            if (sprite != null)
            {
                if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true))
                {
                    NGUIEditorTools.BeginContents(true);
                    EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
                    {
                        SerializedObject obj = new SerializedObject(sprite);
                        obj.Update();
                        SerializedProperty atlas = obj.FindProperty("mAtlas");
                        NGUIEditorTools.DrawSpriteField("Normal", obj, atlas, obj.FindProperty("mSpriteName"));
                        obj.ApplyModifiedProperties();

                        NGUIEditorTools.DrawSpriteField("Hover", serializedObject, atlas, serializedObject.FindProperty("hoverSprite"), true);
                        NGUIEditorTools.DrawSpriteField("Pressed", serializedObject, atlas, serializedObject.FindProperty("pressedSprite"), true);
                        NGUIEditorTools.DrawSpriteField("Disabled", serializedObject, atlas, serializedObject.FindProperty("disabledSprite"), true);
                    }
                    EditorGUI.EndDisabledGroup();

                    NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap");
                    NGUIEditorTools.EndContents();
                }
            }
            else if (s2d != null)
            {
                if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true))
                {
                    NGUIEditorTools.BeginContents(true);
                    EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
                    {
                        SerializedObject obj = new SerializedObject(s2d);
                        obj.Update();
                        NGUIEditorTools.DrawProperty("Normal", obj, "mSprite");
                        obj.ApplyModifiedProperties();

                        NGUIEditorTools.DrawProperty("Hover", serializedObject, "hoverSprite2D");
                        NGUIEditorTools.DrawProperty("Pressed", serializedObject, "pressedSprite2D");
                        NGUIEditorTools.DrawProperty("Disabled", serializedObject, "disabledSprite2D");
                    }
                    EditorGUI.EndDisabledGroup();

                    NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap");
                    NGUIEditorTools.EndContents();
                }
            }
        }

        UIButton button = target as UIButton;

        NGUIEditorTools.DrawEvents("On Click", button, button.onClick, false);

        if (click_effect_prop == null)
        {
            SerializedObject serObj = new SerializedObject(target);
            click_effect_prop = serObj.FindProperty("click_effect_");
        }
        if (click_effect_prop != null)
        {
            EditorGUILayout.PropertyField(click_effect_prop, new GUIContent("Click Effect"));
        }
    }
Exemplo n.º 24
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        NGUIEditorTools.SetLabelWidth(100f);
        UIToggle toggle = target as UIToggle;

        GUILayout.Space(6f);
        GUI.changed = false;

        GUILayout.BeginHorizontal();
        SerializedProperty sp = NGUIEditorTools.DrawProperty("分组唯一标识", serializedObject, "group", GUILayout.Width(230f));

        GUILayout.Label("留空表示不分组");
        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(sp.stringValue == "");
        NGUIEditorTools.DrawProperty("是否允许空选", serializedObject, "optionCanBeNone");
        EditorGUI.EndDisabledGroup();

        NGUIEditorTools.DrawProperty("是否默认选中", serializedObject, "startsActive");
        NGUIEditorTools.SetLabelWidth(80f);

        if (NGUIEditorTools.DrawMinimalisticHeader("State Transition"))
        {
            NGUIEditorTools.BeginContents(true);

            SerializedProperty sprite    = serializedObject.FindProperty("activeSprite");
            SerializedProperty animator  = serializedObject.FindProperty("animator");
            SerializedProperty animation = serializedObject.FindProperty("activeAnimation");
            SerializedProperty tween     = serializedObject.FindProperty("tween");

            if (sprite.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Sprite", sprite, false);
            }
            else if (animator.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Animator", animator, false);
            }
            else if (animation.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Animation", animation, false);
            }
            else if (tween.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Tween", tween, false);
            }
            else
            {
                NGUIEditorTools.DrawProperty("Sprite", serializedObject, "activeSprite");
                NGUIEditorTools.DrawProperty("Animator", animator, false);
                NGUIEditorTools.DrawProperty("Animation", animation, false);
                NGUIEditorTools.DrawProperty("Tween", tween, false);
            }

            if (serializedObject.isEditingMultipleObjects)
            {
                NGUIEditorTools.DrawProperty("Instant", serializedObject, "instantTween");
            }
            else
            {
                GUI.changed = false;
                Transition tr = toggle.instantTween ? Transition.Instant : Transition.Smooth;
                GUILayout.BeginHorizontal();
                tr = (Transition)EditorGUILayout.EnumPopup("Transition", tr);
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Toggle Change", toggle);
                    toggle.instantTween = (tr == Transition.Instant);
                    NGUITools.SetDirty(toggle);
                }
            }
            NGUIEditorTools.EndContents();
        }

        //NGUIEditorTools.DrawEvents("On Value Change", toggle, toggle.onChange);
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 25
0
    /// <summary>
    /// Draw an editor field for the Unity Delegate.
    /// </summary>

    static public bool Field(Object undoObject, EventDelegate del, bool removeButton, bool minimalistic)
    {
        if (del == null)
        {
            return(false);
        }
        bool prev = GUI.changed;

        GUI.changed = false;
        bool          retVal = false;
        MonoBehaviour target = del.target;
        bool          remove = false;

        if (removeButton && (del.target != null || del.isValid))
        {
            if (!minimalistic)
            {
                NGUIEditorTools.SetLabelWidth(82f);
            }

            if (del.target == null && del.isValid)
            {
                EditorGUILayout.LabelField("Notify", del.ToString());
            }
            else
            {
                target = EditorGUILayout.ObjectField("Notify", del.target, typeof(MonoBehaviour), true) as MonoBehaviour;
            }

            GUILayout.Space(-18f);
            GUILayout.BeginHorizontal();
            GUILayout.Space(70f);

            if (GUILayout.Button("", "ToggleMixed", GUILayout.Width(20f), GUILayout.Height(16f)))
            {
                target = null;
                remove = true;
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            target = EditorGUILayout.ObjectField("Notify", del.target, typeof(MonoBehaviour), true) as MonoBehaviour;
        }

        if (remove)
        {
            NGUIEditorTools.RegisterUndo("Delegate Selection", undoObject);
            del.Clear();
            EditorUtility.SetDirty(undoObject);
        }
        else if (del.target != target)
        {
            NGUIEditorTools.RegisterUndo("Delegate Selection", undoObject);
            del.target = target;
            EditorUtility.SetDirty(undoObject);
        }

        if (del.target != null && del.target.gameObject != null)
        {
            GameObject   go   = del.target.gameObject;
            List <Entry> list = GetMethods(go);

            int      index  = 0;
            string[] names  = PropertyReferenceDrawer.GetNames(list, del.ToString(), out index);
            int      choice = 0;

            GUILayout.BeginHorizontal();
            choice = EditorGUILayout.Popup("Method", index, names);
            NGUIEditorTools.DrawPadding();
            GUILayout.EndHorizontal();

            if (choice > 0 && choice != index)
            {
                Entry entry = list[choice - 1];
                NGUIEditorTools.RegisterUndo("Delegate Selection", undoObject);
                del.target     = entry.target as MonoBehaviour;
                del.methodName = entry.name;
                EditorUtility.SetDirty(undoObject);
                retVal = true;
            }

            GUI.changed = false;
            EventDelegate.Parameter[] ps = del.parameters;

            if (ps != null)
            {
                for (int i = 0; i < ps.Length; ++i)
                {
                    EventDelegate.Parameter param = ps[i];
                    Object obj = EditorGUILayout.ObjectField("   Arg " + i, param.obj, typeof(Object), true);

                    if (GUI.changed)
                    {
                        GUI.changed = false;
                        param.obj   = obj;
                        EditorUtility.SetDirty(undoObject);
                    }

                    if (obj == null)
                    {
                        continue;
                    }

                    GameObject  selGO = null;
                    System.Type type  = obj.GetType();
                    if (type == typeof(GameObject))
                    {
                        selGO = obj as GameObject;
                    }
                    else if (type.IsSubclassOf(typeof(Component)))
                    {
                        selGO = (obj as Component).gameObject;
                    }

                    if (selGO != null)
                    {
                        // Parameters must be exact -- they can't be converted like property bindings
                        PropertyReferenceDrawer.filter     = param.expectedType;
                        PropertyReferenceDrawer.canConvert = false;
                        List <PropertyReferenceDrawer.Entry> ents = PropertyReferenceDrawer.GetProperties(selGO, true, false);

                        int      selection;
                        string[] props = GetNames(ents, NGUITools.GetFuncName(param.obj, param.field), out selection);

                        GUILayout.BeginHorizontal();
                        int newSel = EditorGUILayout.Popup(" ", selection, props);
                        NGUIEditorTools.DrawPadding();
                        GUILayout.EndHorizontal();

                        if (GUI.changed)
                        {
                            GUI.changed = false;

                            if (newSel == 0)
                            {
                                param.obj   = selGO;
                                param.field = null;
                            }
                            else
                            {
                                param.obj   = ents[newSel - 1].target;
                                param.field = ents[newSel - 1].name;
                            }
                            EditorUtility.SetDirty(undoObject);
                        }
                    }
                    else if (!string.IsNullOrEmpty(param.field))
                    {
                        param.field = null;
                        EditorUtility.SetDirty(undoObject);
                    }

                    PropertyReferenceDrawer.filter     = typeof(void);
                    PropertyReferenceDrawer.canConvert = true;
                }
            }
        }
        else
        {
            retVal = GUI.changed;
        }
        GUI.changed = prev;
        return(retVal);
    }
Exemplo n.º 26
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mAtlas = target as UIAtlas;

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                NGUITools.SetDirty(mAtlas);
            }
            return;
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsChanged();
        }

        if (mat != null)
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsChanged();
            }

            float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blueColor  = new Color(0f, 0.7f, 1f, 1f);
            Color greenColor = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
                if (sprite == null)
                {
                    sprite = mAtlas.spriteList[0];
                }
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

                Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                if (tex != null)
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = greenColor;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blueColor;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                    }

                    GUILayout.Space(3f);

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("Duplicate"))
                    {
                        UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name);
                        if (se != null)
                        {
                            NGUISettings.selectedSprite = se.name;
                        }
                    }

                    if (GUILayout.Button("Save As..."))
                    {
#if UNITY_3_5
                        string path = EditorUtility.SaveFilePanel("Save As",
                                                                  NGUISettings.currentPath, sprite.name + ".png", "png");
#else
                        string path = EditorUtility.SaveFilePanelInProject("Save As",
                                                                           sprite.name + ".png", "png",
                                                                           "Extract sprite into which file?", NGUISettings.currentPath);
#endif

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name);

                            if (se != null)
                            {
                                byte[] bytes = se.tex.EncodeToPNG();
                                File.WriteAllBytes(path, bytes);
                                AssetDatabase.ImportAsset(path);
                                if (se.temporaryTexture)
                                {
                                    DestroyImmediate(se.tex);
                                }
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.DrawHeader("Modify"))
                {
                    NGUIEditorTools.BeginContents();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    EditorGUILayout.BeginVertical();

                    NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);

                    if (GUILayout.Button("Add a Shadow"))
                    {
                        AddShadow(sprite);
                    }
                    if (GUILayout.Button("Add a Soft Outline"))
                    {
                        AddOutline(sprite);
                    }

                    if (GUILayout.Button("Add a Transparent Border"))
                    {
                        AddTransparentBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Clamped Border"))
                    {
                        AddClampedBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Tiled Border"))
                    {
                        AddTiledBorder(sprite);
                    }
                    EditorGUI.BeginDisabledGroup(!sprite.hasBorder);
                    if (GUILayout.Button("Crop Border"))
                    {
                        CropBorder(sprite);
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUILayout.EndVertical();
                    GUILayout.Space(20f);
                    EditorGUILayout.EndHorizontal();

                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUILayout.Space(3f);
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }

                if (NGUIEditorTools.DrawHeader("Texture Optimization"))
                {
                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);

                    EditorGUILayout.BeginHorizontal();
                    NGUIEditorTools.DrawPadding();
                    TextureCompressionQuality afterType = (TextureCompressionQuality)EditorGUILayout.EnumPopup("Quality Type", NGUIEditorTools.mTextureType);
                    NGUIEditorTools.DrawPadding();

                    if (afterType != NGUIEditorTools.mTextureType)
                    {
                        NGUIEditorTools.mTextureType = afterType;
                    }

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

                    NGUIEditorTools.DrawPadding();

                    EditorGUILayout.BeginVertical();
                    EditorGUI.BeginDisabledGroup(mat.shader.name != "My Shaders/UITextureBinding");
                    if (GUILayout.Button("원본 사용"))
                    {
                        NGUIEditorTools.SetTextureOptimization(mAtlas, false);
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical();
                    EditorGUI.BeginDisabledGroup(mat.shader.name != "Unlit/Transparent Colored");
                    if (GUILayout.Button("최적화 사용"))
                    {
                        NGUIEditorTools.SetTextureOptimization(mAtlas, true);
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUILayout.EndVertical();
                    NGUIEditorTools.DrawPadding();
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    NGUIEditorTools.DrawPadding();
                    EditorGUILayout.BeginVertical();
                    if (GUILayout.Button("전체 원본으로"))
                    {
                        string[] aAtlasFiles = Directory.GetFiles("Assets/Resources/Prefabs/UI_Data/UI_Atlas", "*.prefab", SearchOption.AllDirectories);

                        for (int i = 0; i < aAtlasFiles.Length; ++i)
                        {
                            EditorUtility.DisplayProgressBar("Texture Optimization", "Combine...", ((i + 1) / (float)aAtlasFiles.Length));
                            UIAtlas sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas;

                            NGUIEditorTools.SetTextureOptimization(sourceAtlas, false);
                        }
                        EditorUtility.ClearProgressBar();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical();

                    if (GUILayout.Button("전체 최적화"))
                    {
                        string[] aAtlasFiles = Directory.GetFiles("Assets/Resources/Prefabs/UI_Data/UI_Atlas", "*.prefab", SearchOption.AllDirectories);

                        for (int i = 0; i < aAtlasFiles.Length; ++i)
                        {
                            EditorUtility.DisplayProgressBar("Texture Optimization", string.Format("Devide..."), ((i + 1) / (float)aAtlasFiles.Length));

                            UIAtlas sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas;
                            shaderTextureBinding = shaderTextureBinding == null?Shader.Find("My Shaders/UITextureBinding") : shaderTextureBinding;

                            sourceAtlas.spriteMaterial.shader = shaderTextureBinding;
                            NGUIEditorTools.CopyAndChangeTexture(sourceAtlas, true);
                            sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas;
                            NGUIEditorTools.CopyAndChangeTexture(sourceAtlas, false);
                        }
                        EditorUtility.ClearProgressBar();
                    }
                    EditorGUILayout.EndVertical();
                    NGUIEditorTools.DrawPadding();
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.HelpBox("Quality Type : 텍스쳐의 Compression Quality (Best는 속도가 느리기 때문에 빌드할 때만 한다.)\n" +
                                            "원본, 최적화 사용 : 해당 아틀라스의 텍스쳐를 원본, 최적화 상태로 변경한다.\n" +
                                            "전체 원본, 전체 최적화 : UI_Atlas 폴더에 있는 모든 아틀라스를 일괄 원본, 최적화 상태로 변경한다.", MessageType.Info);

                    NGUIEditorTools.EndContents();
                }
            }
        }
    }
Exemplo n.º 27
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mAtlas = target as UIAtlas;

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                NGUITools.SetDirty(mAtlas);
            }
            return;
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsChanged();
        }

        if (mat != null)
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsChanged();
            }

            float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blueColor  = new Color(0f, 0.7f, 1f, 1f);
            Color greenColor = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
                if (sprite == null)
                {
                    sprite = mAtlas.spriteList[0];
                }
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

                Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                if (tex != null)
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = greenColor;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blueColor;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                    }

                    GUILayout.Space(3f);

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("Duplicate"))
                    {
                        UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name);
                        if (se != null)
                        {
                            NGUISettings.selectedSprite = se.name;
                        }
                    }

                    if (GUILayout.Button("Save As..."))
                    {
                        string path = EditorUtility.SaveFilePanel("Save As",
                                                                  NGUISettings.currentPath, sprite.name + ".png", "png");

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name);

                            if (se != null)
                            {
                                byte[] bytes = se.tex.EncodeToPNG();
                                File.WriteAllBytes(path, bytes);
                                AssetDatabase.ImportAsset(path);
                                if (se.temporaryTexture)
                                {
                                    DestroyImmediate(se.tex);
                                }
                            }
                        }
                    }
                    if (GUILayout.Button("Save As All"))
                    {
                        string path = EditorUtility.SaveFolderPanel("Save As All",
                                                                    NGUISettings.currentPath, "");
                        if (!string.IsNullOrEmpty(path))
                        {
                            var list = mAtlas.spriteList;
                            foreach (var uiSpriteData in list)
                            {
                                var spName = uiSpriteData.name;
                                NGUISettings.currentPath = path;
                                UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, spName);
                                if (se != null)
                                {
                                    var    filePath = string.Format("{0}/{1}.png", path, spName);
                                    byte[] bytes    = se.tex.EncodeToPNG();
                                    File.WriteAllBytes(filePath, bytes);
                                    AssetDatabase.ImportAsset(filePath);
                                    if (se.temporaryTexture)
                                    {
                                        DestroyImmediate(se.tex);
                                    }
                                }
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.DrawHeader("Modify"))
                {
                    NGUIEditorTools.BeginContents();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    EditorGUILayout.BeginVertical();

                    NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);

                    if (GUILayout.Button("Add a Shadow"))
                    {
                        AddShadow(sprite);
                    }
                    if (GUILayout.Button("Add a Soft Outline"))
                    {
                        AddOutline(sprite);
                    }

                    if (GUILayout.Button("Add a Transparent Border"))
                    {
                        AddTransparentBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Clamped Border"))
                    {
                        AddClampedBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Tiled Border"))
                    {
                        AddTiledBorder(sprite);
                    }
                    EditorGUI.BeginDisabledGroup(!sprite.hasBorder);
                    if (GUILayout.Button("Crop Border"))
                    {
                        CropBorder(sprite);
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUILayout.EndVertical();
                    GUILayout.Space(20f);
                    EditorGUILayout.EndHorizontal();

                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUILayout.Space(3f);
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
        }
    }
Exemplo n.º 28
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mRichTextLabel = mWidget as UIRichTextLabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            GUI.changed = false;
            fnt         = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            GUI.changed = false;
            ttf         = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }

        NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat");

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    if (mRichTextLabel.overflowMethod == UIRichTextLabel.Overflow.ShrinkContent)
                    {
                        GUILayout.Label(" Actual: " + mRichTextLabel.finalFontSize + "/" + mRichTextLabel.defaultFontSize);
                    }
                    else
                    {
                        GUILayout.Label(" Default: " + mRichTextLabel.defaultFontSize);
                    }
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier");

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;
            if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent)
            {
                NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f));
            }

            if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth");
                if (s != null && s.intValue < 1)
                {
                    GUILayout.Label("unlimited");
                }
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mRichTextLabel.bitmapFont != null && mRichTextLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mRichTextLabel.bitmapFont == null || !mRichTextLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();

        if (NGUIEditorTools.DrawHeader("RichTextPrefabs"))
        {
            NGUIEditorTools.BeginContents();

            List <RichTextPrefabItem> prefabs = mRichTextLabel.Prefabs;
            for (int i = prefabs.Count - 1; i >= 0; i--)
            {
                RichTextPrefabItem prefab = prefabs[i];
                if (prefab.prefabObject == null)
                {
                    prefabs.RemoveAt(i);
                }
            }
            for (int i = 0; i < prefabs.Count; i++)
            {
                RichTextPrefabItem prefab = prefabs[i];
                if (prefab.prefabObject == null)
                {
                    continue;
                }
                GUILayout.BeginHorizontal();
                GUILayout.Label(prefab.sequence, GUILayout.Width(100f));
                GUILayout.Label(prefab.prefabObject.name, GUILayout.Width(100f));
                GUILayout.Label("width:" + prefab.width);
                GUILayout.Label("height:" + prefab.height);
                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    NGUIEditorTools.RegisterUndo("Remove prefab", mRichTextLabel);
                    mPrefabSequence = prefab.sequence;
                    //mPrefabGameObject = prefab.prefab;
                    prefabs.Remove(prefab);
                    mRichTextLabel.MarkAsChanged();
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();
                GUILayout.Space(4f);
            }

            if (prefabs.Count > 0)
            {
                GUILayout.Space(6f);
            }

            GUILayout.BeginHorizontal();
            mPrefabSequence     = EditorGUILayout.TextField(mPrefabSequence, GUILayout.Width(100f));
            mPrefabGameObject   = (GameObject)EditorGUILayout.ObjectField(mPrefabGameObject, typeof(GameObject), GUILayout.Width(100f));
            mPrefabWidth        = EditorGUILayout.FloatField(mPrefabWidth);
            mPrefabHeight       = EditorGUILayout.FloatField(mPrefabHeight);
            isValid             = (!string.IsNullOrEmpty(mPrefabSequence)) && (mPrefabGameObject != null);
            GUI.backgroundColor = isValid ? Color.green : Color.grey;

            if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
            {
                NGUIEditorTools.RegisterUndo("Add prefab", mRichTextLabel);
                RichTextPrefabItem tprefab = new RichTextPrefabItem();
                tprefab.sequence     = mPrefabSequence;
                tprefab.prefabObject = mPrefabGameObject;
                tprefab.width        = mPrefabWidth;
                tprefab.height       = mPrefabHeight;
                mRichTextLabel.Prefabs.Add(tprefab);
                mRichTextLabel.MarkAsChanged();
                mPrefabSequence   = "";
                mPrefabGameObject = null;
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndHorizontal();

            if (prefabs.Count == 0)
            {
                EditorGUILayout.HelpBox("In the field above type ':)', choose a Prefab, then hit the Add button.", MessageType.Info);
            }
            else
            {
                GUILayout.Space(4f);
            }

            NGUIEditorTools.EndContents();
        }

        if (NGUIEditorTools.DrawHeader("RichTextEmotion"))
        {
            NGUIEditorTools.BeginContents();
            GUILayout.BeginHorizontal();
            if (NGUIEditorTools.DrawPrefixButton("Atlas"))
            {
                ComponentSelector.Show <UIAtlas>(OnSelectAtlas);
            }
            SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mEmotionAtlas", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mRichTextLabel.EmotionAtlas != null)
            {
                List <RichTextEmotionItem> emotions = mRichTextLabel.Emotions;
                for (int i = 0; i < emotions.Count; i++)
                {
                    RichTextEmotionItem emotion = emotions[i];

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(emotion.sequence, GUILayout.Width(40f));
                    GUILayout.Label(emotion.spriteName);
                    GUI.backgroundColor = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        NGUIEditorTools.RegisterUndo("Remove emotion", mRichTextLabel);
                        mEmotionSequence = emotion.sequence;
                        emotions.Remove(emotion);
                        mRichTextLabel.MarkAsChanged();
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                    GUILayout.Space(4f);
                }

                if (emotions.Count > 0)
                {
                    GUILayout.Space(6f);
                }

                GUILayout.BeginHorizontal();
                mEmotionSequence = EditorGUILayout.TextField(mEmotionSequence, GUILayout.Width(40f));
                NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, mSpriteName, SelectSprite, false);
                isValid             = (!string.IsNullOrEmpty(mEmotionSequence)) && (!string.IsNullOrEmpty(mSpriteName));
                GUI.backgroundColor = isValid ? Color.green : Color.grey;

                if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                {
                    NGUIEditorTools.RegisterUndo("Add Sprite", mRichTextLabel);
                    RichTextEmotionItem temotion = new RichTextEmotionItem();
                    temotion.sequence   = mEmotionSequence;
                    temotion.spriteName = mSpriteName;
                    mRichTextLabel.Emotions.Add(temotion);
                    mRichTextLabel.MarkAsChanged();
                    mEmotionSequence = "";
                    mSpriteName      = "";
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                if (emotions.Count == 0)
                {
                    EditorGUILayout.HelpBox("In the field above type ':)', choose a Sprite, then hit the Add button.", MessageType.Info);
                }
                else
                {
                    GUILayout.Space(4f);
                }
            }



            NGUIEditorTools.EndContents();
        }

        isValid = true;


        return(isValid);
    }