void RegisterUndo()
 {
     NGUIEditorTools.RegisterUndo("Select Field Change", mList);
 }
Exemplo n.º 2
0
    /// <summary>
    /// Draw an editor field for the Unity Delegate.
    /// </summary>
    public static 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.º 3
0
    /// <summary>
    /// Combine all sprites into a single texture and save it to disk.
    /// </summary>

    static public bool UpdateTexture(UIAtlas atlas, List <SpriteEntry> sprites)
    {
        // Get the texture for the atlas
        Texture2D tex     = atlas.texture as Texture2D;
        string    oldPath = (tex != null) ? AssetDatabase.GetAssetPath(tex.GetInstanceID()) : "";
        string    newPath = NGUIEditorTools.GetSaveableTexturePath(atlas);

        // Clear the read-only flag in texture file attributes
        if (System.IO.File.Exists(newPath))
        {
#if !UNITY_4_1 && !UNITY_4_0 && !UNITY_3_5
            if (!AssetDatabase.IsOpenForEdit(newPath))
            {
                Debug.LogError(newPath + " is not editable. Did you forget to do a check out?");
                return(false);
            }
#endif
            System.IO.FileAttributes newPathAttrs = System.IO.File.GetAttributes(newPath);
            newPathAttrs &= ~System.IO.FileAttributes.ReadOnly;
            System.IO.File.SetAttributes(newPath, newPathAttrs);
        }

        bool newTexture = (tex == null || oldPath != newPath);

        if (newTexture)
        {
            // Create a new texture for the atlas
            tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
        }
        else
        {
            // Make the atlas readable so we can save it
            tex = NGUIEditorTools.ImportTexture(oldPath, true, false, false);
        }

        // Pack the sprites into this texture
        if (PackTextures(tex, sprites))
        {
            byte[] bytes = tex.EncodeToPNG();
            System.IO.File.WriteAllBytes(newPath, bytes);
            bytes = null;

            // Load the texture we just saved as a Texture2D
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
            tex = NGUIEditorTools.ImportTexture(newPath, false, true, !atlas.premultipliedAlpha);

            //string strMainTexturePathName = AssetDatabase.GetAssetPath(tex.GetInstanceID());
            TextureImporter ti = AssetImporter.GetAtPath(newPath) as TextureImporter;
            ti.textureType   = TextureImporterType.Advanced;
            ti.mipmapEnabled = false;

            // Update the atlas texture
            if (newTexture)
            {
                if (tex == null)
                {
                    Debug.LogError("Failed to load the created atlas saved as " + newPath);
                }
                else
                {
                    atlas.spriteMaterial.mainTexture = tex;
                }
                ReleaseSprites(sprites);

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
            }
            return(true);
        }
        else
        {
            if (!newTexture)
            {
                NGUIEditorTools.ImportTexture(oldPath, false, true, !atlas.premultipliedAlpha);
            }

            //Debug.LogError("Operation canceled: The selected sprites can't fit into the atlas.\n" +
            //	"Keep large sprites outside the atlas (use UITexture), and/or use multiple atlases instead.");

            EditorUtility.DisplayDialog("Operation Canceled", "The selected sprites can't fit into the atlas.\n" +
                                        "Keep large sprites outside the atlas (use UITexture), and/or use multiple atlases instead", "OK");
            return(false);
        }
    }
Exemplo n.º 4
0
 protected override bool ShouldDrawProperties()
 {
     NGUIEditorTools.DrawProperty("speed", serializedObject, "speed", GUILayout.MinWidth(40f));
     return(base.ShouldDrawProperties());
 }
Exemplo n.º 5
0
    /// <summary>
    /// Draw the specified sprite.
    /// </summary>

    public static void DrawSprite(Texture2D tex, Rect rect, Rect outer, Rect inner, Rect uv, Color color, Material mat)
    {
        // Create the texture rectangle that is centered inside rect.
        Rect outerRect = rect;

        outerRect.width  = outer.width;
        outerRect.height = outer.height;

        if (outerRect.width > 0f)
        {
            float f = rect.width / outerRect.width;
            outerRect.width  *= f;
            outerRect.height *= f;
        }

        if (rect.height > outerRect.height)
        {
            outerRect.y += (rect.height - outerRect.height) * 0.5f;
        }
        else if (outerRect.height > rect.height)
        {
            float f = rect.height / outerRect.height;
            outerRect.width  *= f;
            outerRect.height *= f;
        }

        if (rect.width > outerRect.width)
        {
            outerRect.x += (rect.width - outerRect.width) * 0.5f;
        }

        // Draw the background
        NGUIEditorTools.DrawTiledTexture(outerRect, NGUIEditorTools.backdropTexture);

        // Draw the sprite
        GUI.color = color;

        if (mat == null)
        {
            GUI.DrawTextureWithTexCoords(outerRect, tex, uv, true);
        }
        else
        {
            // NOTE: There is an issue in Unity that prevents it from clipping the drawn preview
            // using BeginGroup/EndGroup, and there is no way to specify a UV rect... le'suq.
            UnityEditor.EditorGUI.DrawPreviewTexture(outerRect, tex, mat);
        }

        // Draw the border indicator lines
        GUI.BeginGroup(outerRect);
        {
            tex       = NGUIEditorTools.contrastTexture;
            GUI.color = Color.white;

            if (inner.xMin != outer.xMin)
            {
                float x0 = (inner.xMin - outer.xMin) / outer.width * outerRect.width - 1;
                NGUIEditorTools.DrawTiledTexture(new Rect(x0, 0f, 1f, outerRect.height), tex);
            }

            if (inner.xMax != outer.xMax)
            {
                float x1 = (inner.xMax - outer.xMin) / outer.width * outerRect.width - 1;
                NGUIEditorTools.DrawTiledTexture(new Rect(x1, 0f, 1f, outerRect.height), tex);
            }

            if (inner.yMin != outer.yMin)
            {
                float y0 = (inner.yMin - outer.yMin) / outer.height * outerRect.height - 1;
                NGUIEditorTools.DrawTiledTexture(new Rect(0f, y0, outerRect.width, 1f), tex);
            }

            if (inner.yMax != outer.yMax)
            {
                float y1 = (inner.yMax - outer.yMin) / outer.height * outerRect.height - 1;
                NGUIEditorTools.DrawTiledTexture(new Rect(0f, y1, outerRect.width, 1f), tex);
            }
        }
        GUI.EndGroup();

        // Draw the lines around the sprite
        Handles.color = Color.black;
        Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMin, outerRect.yMax));
        Handles.DrawLine(new Vector3(outerRect.xMax, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMax));
        Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMin));
        Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMax), new Vector3(outerRect.xMax, outerRect.yMax));

        // Sprite size label
        string text = string.Format("Sprite Size: {0}x{1}",
                                    Mathf.RoundToInt(Mathf.Abs(outer.width)),
                                    Mathf.RoundToInt(Mathf.Abs(outer.height)));

        EditorGUI.DropShadowLabel(GUILayoutUtility.GetRect(Screen.width, 18f), text);
    }
Exemplo n.º 6
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        GUILayout.Label(mTitle, "LODLevelNotifyText");
        GUILayout.Space(6f);

        if (mObjects == null || mObjects.Length == 0)
        {
            EditorGUILayout.HelpBox("No " + GetName(mType) + " components found.\nTry creating a new one.", MessageType.Info);

            bool isDone = false;

            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (mType == typeof(UIFont))
            {
                if (GUILayout.Button("Open the Font Maker", GUILayout.Width(150f)))
                {
                    EditorWindow.GetWindow <UIFontMaker>(false, "Font Maker", true);
                    isDone = true;
                }
            }
            else if (mType == typeof(UIAtlas))
            {
                if (GUILayout.Button("Open the Atlas Maker", GUILayout.Width(150f)))
                {
                    EditorWindow.GetWindow <UIAtlasMaker>(false, "Atlas Maker", true);
                    isDone = true;
                }
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            if (isDone)
            {
                Close();
            }
        }
        else
        {
            Object sel = null;
            mScroll = GUILayout.BeginScrollView(mScroll);

            foreach (Object o in mObjects)
            {
                if (DrawObject(o))
                {
                    sel = o;
                }
            }

            GUILayout.EndScrollView();

            if (sel != null)
            {
                mCallback(sel);
                Close();
            }
        }

        if (!mSearched)
        {
            GUILayout.Space(6f);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            bool search = GUILayout.Button("Show All", "LargeButton", GUILayout.Width(120f));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            if (search)
            {
                Search();
            }
        }
    }
Exemplo n.º 7
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();
                }
            }
            btn.EnabledLabel = (UILabel)EditorGUILayout.ObjectField("EnabledLabel", btn.EnabledLabel, typeof(UILabel));
            btn.EnabelColor  = EditorGUILayout.ColorField("Enabel Color", btn.EnabelColor);;
        }

        UIButton button = target as UIButton;

        NGUIEditorTools.DrawEvents("On Click", button, button.onClick, false);
    }
Exemplo n.º 8
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.º 9
0
 void RegisterUndo()
 {
     NGUIEditorTools.RegisterUndo("Popup List Change", mList);
 }
Exemplo n.º 10
0
 void OnDisabled(string spriteName)
 {
     NGUIEditorTools.RegisterUndo("Image Button Change", mButton, mButton.gameObject, mSprite);
     mButton.disabledSprite = spriteName;
     Repaint();
 }
Exemplo n.º 11
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

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

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

        NGUIEditorTools.DrawSeparator();

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

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

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

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

            NGUIEditorTools.DrawSeparator();
            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;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        if (!mConfirmDelete)
        {
            NGUIEditorTools.DrawSeparator();
            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.MarkAsDirty();
                mConfirmDelete = false;
            }

            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);
                    }

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

                UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

                if (coords != mAtlas.coordinates)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.coordinates = coords;
                    mConfirmDelete     = false;
                }

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

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

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

            if (mConfirmDelete)
            {
                if (sprite != null)
                {
                    // Show the confirmation dialog
                    NGUIEditorTools.DrawSeparator();
                    GUILayout.Label("Are you sure you want to delete '" + sprite.name + "'?");
                    NGUIEditorTools.DrawSeparator();

                    GUILayout.BeginHorizontal();
                    {
                        GUI.backgroundColor = Color.green;
                        if (GUILayout.Button("Cancel"))
                        {
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("Delete"))
                        {
                            NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas);
                            mAtlas.spriteList.Remove(sprite);
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    mConfirmDelete = false;
                }
            }
            else
            {
                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 (!mConfirmDelete && sprite != null)
                {
                    NGUIEditorTools.DrawSeparator();
                    NGUIEditorTools.AdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);

                    if (sprite == null)
                    {
                        return;
                    }

                    Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                    if (tex != null)
                    {
                        Rect inner = sprite.inner;
                        Rect outer = sprite.outer;

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            GUI.backgroundColor = green;
                            outer = NGUIEditorTools.IntRect("Dimensions", sprite.outer);

                            Vector4 border = new Vector4(
                                sprite.inner.xMin - sprite.outer.xMin,
                                sprite.inner.yMin - sprite.outer.yMin,
                                sprite.outer.xMax - sprite.inner.xMax,
                                sprite.outer.yMax - sprite.inner.yMax);

                            GUI.backgroundColor = blue;
                            border = NGUIEditorTools.IntPadding("Border", border);
                            GUI.backgroundColor = Color.white;

                            inner.xMin = sprite.outer.xMin + border.x;
                            inner.yMin = sprite.outer.yMin + border.y;
                            inner.xMax = sprite.outer.xMax - border.z;
                            inner.yMax = sprite.outer.yMax - border.w;
                        }
                        else
                        {
                            // Draw the inner and outer rectangle dimensions
                            GUI.backgroundColor = green;
                            outer = EditorGUILayout.RectField("Outer Rect", sprite.outer);
                            GUI.backgroundColor = blue;
                            inner = EditorGUILayout.RectField("Inner Rect", sprite.inner);
                            GUI.backgroundColor = Color.white;
                        }

                        if (outer.xMax < outer.xMin)
                        {
                            outer.xMax = outer.xMin;
                        }
                        if (outer.yMax < outer.yMin)
                        {
                            outer.yMax = outer.yMin;
                        }

                        if (outer != sprite.outer)
                        {
                            float x = outer.xMin - sprite.outer.xMin;
                            float y = outer.yMin - sprite.outer.yMin;

                            inner.x += x;
                            inner.y += y;
                        }

                        // Sanity checks to ensure that the inner rect is always inside the outer
                        inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax);
                        inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax);
                        inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax);
                        inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax);

                        bool changed = false;

                        if (sprite.inner != inner || sprite.outer != outer)
                        {
                            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                            sprite.inner = inner;
                            sprite.outer = outer;
                            MarkSpriteAsDirty();
                            changed = true;
                        }

                        EditorGUILayout.Separator();

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            int left   = Mathf.RoundToInt(sprite.paddingLeft * sprite.outer.width);
                            int right  = Mathf.RoundToInt(sprite.paddingRight * sprite.outer.width);
                            int top    = Mathf.RoundToInt(sprite.paddingTop * sprite.outer.height);
                            int bottom = Mathf.RoundToInt(sprite.paddingBottom * sprite.outer.height);

                            NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top);
                            NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom);

                            if (changed || a.x != left || a.y != top || b.x != right || b.y != bottom)
                            {
                                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                                sprite.paddingLeft   = a.x / sprite.outer.width;
                                sprite.paddingTop    = a.y / sprite.outer.height;
                                sprite.paddingRight  = b.x / sprite.outer.width;
                                sprite.paddingBottom = b.y / sprite.outer.height;
                                MarkSpriteAsDirty();
                            }
                        }
                        else
                        {
                            // Create a button that can make the coordinates pixel-perfect on click
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Label("Correction", GUILayout.Width(75f));

                                Rect corrected0 = outer;
                                Rect corrected1 = inner;

                                if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1);
                                }
                                else
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height);
                                }

                                if (corrected0 == sprite.outer && corrected1 == sprite.inner)
                                {
                                    GUI.color = Color.grey;
                                    GUILayout.Button("Make Pixel-Perfect");
                                    GUI.color = Color.white;
                                }
                                else if (GUILayout.Button("Make Pixel-Perfect"))
                                {
                                    outer       = corrected0;
                                    inner       = corrected1;
                                    GUI.changed = true;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }

                    // This functionality is no longer used. It became obsolete when the Atlas Maker was added.

                    /*NGUIEditorTools.DrawSeparator();
                     *
                     * GUILayout.BeginHorizontal();
                     * {
                     *      EditorGUILayout.PrefixLabel("Add/Delete");
                     *
                     *      if (GUILayout.Button("Clone Sprite"))
                     *      {
                     *              NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas);
                     *              UIAtlas.Sprite newSprite = new UIAtlas.Sprite();
                     *
                     *              if (sprite != null)
                     *              {
                     *                      newSprite.name = "Copy of " + sprite.name;
                     *                      newSprite.outer = sprite.outer;
                     *                      newSprite.inner = sprite.inner;
                     *              }
                     *              else
                     *              {
                     *                      newSprite.name = "New Sprite";
                     *              }
                     *
                     *              mAtlas.spriteList.Add(newSprite);
                     *              sprite = newSprite;
                     *      }
                     *
                     *      // Show the delete button
                     *      GUI.backgroundColor = Color.red;
                     *
                     *      if (sprite != null && GUILayout.Button("Delete", GUILayout.Width(55f)))
                     *      {
                     *              mConfirmDelete = true;
                     *      }
                     *      GUI.backgroundColor = Color.white;
                     * }
                     * GUILayout.EndHorizontal();*/

                    if (NGUIEditorTools.previousSelection != null)
                    {
                        NGUIEditorTools.DrawSeparator();

                        GUI.backgroundColor = Color.green;

                        if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                        {
                            NGUIEditorTools.SelectPrevious();
                        }
                        GUI.backgroundColor = Color.white;
                    }
                }
            }
        }
    }
Exemplo n.º 12
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)
                {
                    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");
            }

            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.º 13
0
 void RegisterUndo()
 {
     NGUIEditorTools.RegisterUndo("Label Change", mLabel);
 }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.BeginHorizontal();
        GUILayout.Space(6f);
        GUILayout.Label("Options");
        GUILayout.EndHorizontal();

        string text = "";

        foreach (string s in mList.items)
        {
            text += s + "\n";
        }

        GUILayout.Space(-14f);
        GUILayout.BeginHorizontal();
        GUILayout.Space(84f);
        string modified = EditorGUILayout.TextArea(text, GUI.skin.textArea, GUILayout.Height(100f));

        GUILayout.EndHorizontal();

        if (modified != text)
        {
            RegisterUndo();
            string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
            mList.items.Clear();
            foreach (string s in split)
            {
                mList.items.Add(s);
            }

            if (string.IsNullOrEmpty(mList.value) || !mList.items.Contains(mList.value))
            {
                mList.value = mList.items.Count > 0 ? mList.items[0] : "";
            }
        }

        GUI.changed = false;
        string sel = NGUIEditorTools.DrawList("Default", mList.items.ToArray(), mList.value);

        if (GUI.changed)
        {
            serializedObject.FindProperty("mSelectedItem").stringValue = sel;
        }

        NGUIEditorTools.DrawProperty("Position", serializedObject, "position");
        NGUIEditorTools.DrawProperty("Localized", serializedObject, "isLocalized");

        EditorGUILayout.Space();

        DrawLabelLayout();
        DrawSelectField();
        DrawArrowSprites();
        DrawListLayout();
        DrawListHighlightLayout();
        DrawFont();

        NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange);

        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 15
0
 static public GameObject SelectedRoot()
 {
     return(NGUIEditorTools.SelectedRoot());
 }
Exemplo n.º 16
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;
        BetterList <UIDrawCall> drawcalls = panel.drawCalls;

        EditorGUIUtility.LookLikeControls(80f, 80f);

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f);

        if (alpha != panel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", panel);
            panel.alpha = alpha;
        }

        if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
        {
            panel.showInPanelTool = !panel.showInPanelTool;
            EditorUtility.SetDirty(panel);
            EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
        }

        GUILayout.BeginHorizontal();
        bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f));

        GUILayout.Label("Needed for lit shaders");
        GUILayout.EndHorizontal();

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));

        GUILayout.Label("Doubles draw calls, saves fillrate");
        GUILayout.EndHorizontal();

        if (panel.depthPass != depth)
        {
            panel.depthPass = depth;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (depth)
        {
            UICamera cam = UICamera.FindCameraForLayer(panel.gameObject.layer);

            if (cam == null || cam.camera.isOrthoGraphic)
            {
                EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D UIs, and only UIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
            }
        }

        GUILayout.BeginHorizontal();
        bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f));

        GUILayout.Label("Check if widgets won't move");
        GUILayout.EndHorizontal();

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
        EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

        UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping);

        if (panel.clipping != clipping)
        {
            panel.clipping = clipping;
            EditorUtility.SetDirty(panel);
        }

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

            if (panel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (panel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                    panel.clipSoftness = soft;
                    EditorUtility.SetDirty(panel);
                }
            }

#if !UNITY_3_5 && (UNITY_ANDROID || UNITY_IPHONE)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x)
            {
                EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
            }
#endif
        }

        if (clipping == UIDrawCall.Clipping.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(panel.gameObject);
            }
        }

        foreach (UIDrawCall dc in drawcalls)
        {
            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
            EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

            if (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);
            }
        }
    }
Exemplo n.º 17
0
    static void AddPanel()
    {
        UIPanel panel = NGUISettings.AddPanel(SelectedRoot());

        Selection.activeGameObject = (panel == null) ? NGUIEditorTools.SelectedRoot(true) : panel.gameObject;
    }
Exemplo n.º 18
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }

                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.baseClipRegion;

            // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable
            //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null);
            GUI.changed = false;
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipOffset = off;
                EditorUtility.SetDirty(mPanel);
            }
            //EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.baseClipRegion != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.baseClipRegion = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f));
                GUILayout.EndHorizontal();

                if (soft.x < 0f)
                {
                    soft.x = 0f;
                }
                if (soft.y < 0f)
                {
                    soft.y = 0f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
            else if (mPanel.clipping == UIDrawCall.Clipping.TextureMask)
            {
                NGUIEditorTools.SetLabelWidth(0f);
                GUILayout.Space(-90f);
                Texture2D tex = (Texture2D)EditorGUILayout.ObjectField(mPanel.clipTexture,
                                                                       typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(70f));
                GUILayout.Space(20f);

                if (mPanel.clipTexture != tex)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipTexture = tex;
                    EditorUtility.SetDirty(mPanel);
                }
                NGUIEditorTools.SetLabelWidth(80f);
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue);

            if (mPanel.renderQueue != rq)
            {
                mPanel.renderQueue = rq;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }

            if (rq != UIPanel.RenderQueue.Automatic)
            {
                int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f));

                if (mPanel.startingRenderQueue != sq)
                {
                    mPanel.startingRenderQueue = sq;
                    mPanel.RebuildAllDrawCalls();
                    EditorUtility.SetDirty(mPanel);
                    if (UIDrawCallViewer.instance != null)
                    {
                        UIDrawCallViewer.instance.Repaint();
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUI.changed = false;
            int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
            if (GUI.changed)
            {
                mPanel.sortingOrder = so;
            }

            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f));
            GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIRoot>() != null);
            bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset && mPanel.GetComponent <UIRoot>() == null, GUILayout.Width(100f));
            GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f));
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            if (mPanel.anchorOffset != off)
            {
                mPanel.anchorOffset = off;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }
        return(true);
    }
Exemplo n.º 19
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.º 20
0
 protected override void OnDisable()
 {
     base.OnDisable();
     NGUIEditorTools.HideMoveTool(false);
 }
Exemplo n.º 21
0
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        UIButtonColor button = target as UIButtonColor;

        GUILayout.Space(6f);

        GUI.changed = false;
        GameObject tt = (GameObject)EditorGUILayout.ObjectField("Target", button.tweenTarget, typeof(GameObject), true);

        if (GUI.changed)
        {
            NGUIEditorTools.RegisterUndo("Button Change", button);
            button.tweenTarget = tt;
            UnityEditor.EditorUtility.SetDirty(button);
        }

        if (tt != null)
        {
            UIWidget w = tt.GetComponent <UIWidget>();

            if (w != null)
            {
                GUI.changed = false;
                Color c = EditorGUILayout.ColorField("Normal", w.color);

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Button Change", w);
                    w.color = c;
                    UnityEditor.EditorUtility.SetDirty(w);
                }
            }
        }

        GUI.changed = false;
        Color hover   = EditorGUILayout.ColorField("Hover", button.hover);
        Color pressed = EditorGUILayout.ColorField("Pressed", button.pressed);

        GUILayout.BeginHorizontal();
        float duration = EditorGUILayout.FloatField("Duration", button.duration, GUILayout.Width(120f));

        GUILayout.Label("seconds");
        GUILayout.EndHorizontal();

        GUILayout.Space(3f);

        if (GUI.changed)
        {
            NGUIEditorTools.RegisterUndo("Button Change", button);
            button.hover    = hover;
            button.pressed  = pressed;
            button.duration = duration;
            UnityEditor.EditorUtility.SetDirty(button);
        }

        if (GUILayout.Button("Upgrade to a Button"))
        {
            NGUIEditorTools.ReplaceClass(serializedObject, typeof(UIButton));
            Selection.activeGameObject = null;
        }
    }
Exemplo n.º 22
0
    /// <summary>
    /// Handles & interaction.
    /// </summary>

    public void OnSceneGUI()
    {
        if (Selection.objects.Length > 1)
        {
            return;
        }

        UICamera cam = UICamera.FindCameraForLayer(mPanel.gameObject.layer);

#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        if (cam == null || !cam.cachedCamera.isOrthoGraphic)
        {
            return;
        }
#else
        if (cam == null || !cam.cachedCamera.orthographic)
        {
            return;
        }
#endif

        NGUIEditorTools.HideMoveTool(true);
        if (!UIWidget.showHandles)
        {
            return;
        }

        Event     e    = Event.current;
        int       id   = GUIUtility.GetControlID(s_Hash, FocusType.Passive);
        EventType type = e.GetTypeForControl(id);
        Transform t    = mPanel.cachedTransform;

        Vector3[] handles = UIWidgetInspector.GetHandles(mPanel.worldCorners);

        // Time to figure out what kind of action is underneath the mouse
        UIWidgetInspector.Action actionUnderMouse = mAction;

        Color handlesColor = new Color(0.5f, 0f, 0.5f);
        NGUIHandles.DrawShadowedLine(handles, handles[0], handles[1], handlesColor);
        NGUIHandles.DrawShadowedLine(handles, handles[1], handles[2], handlesColor);
        NGUIHandles.DrawShadowedLine(handles, handles[2], handles[3], handlesColor);
        NGUIHandles.DrawShadowedLine(handles, handles[0], handles[3], handlesColor);

        if (mPanel.isAnchored)
        {
            UIWidgetInspector.DrawAnchorHandle(mPanel.leftAnchor, mPanel.cachedTransform, handles, 0, id);
            UIWidgetInspector.DrawAnchorHandle(mPanel.topAnchor, mPanel.cachedTransform, handles, 1, id);
            UIWidgetInspector.DrawAnchorHandle(mPanel.rightAnchor, mPanel.cachedTransform, handles, 2, id);
            UIWidgetInspector.DrawAnchorHandle(mPanel.bottomAnchor, mPanel.cachedTransform, handles, 3, id);
        }

        if (type == EventType.Repaint)
        {
            bool showDetails = (mAction == UIWidgetInspector.Action.Scale) || NGUISettings.drawGuides;
            if (mAction == UIWidgetInspector.Action.None && e.modifiers == EventModifiers.Control)
            {
                showDetails = true;
            }
            if (NGUITools.GetActive(mPanel) && mPanel.parent == null)
            {
                showDetails = true;
            }
            if (showDetails)
            {
                NGUIHandles.DrawSize(handles, Mathf.RoundToInt(mPanel.width), Mathf.RoundToInt(mPanel.height));
            }
        }

        bool canResize = (mPanel.clipping != UIDrawCall.Clipping.None);

        // NOTE: Remove this part when it's possible to neatly resize rotated anchored panels.
        if (canResize && mPanel.isAnchored)
        {
            Quaternion rot = mPanel.cachedTransform.localRotation;
            if (Quaternion.Angle(rot, Quaternion.identity) > 0.01f)
            {
                canResize = false;
            }
        }

        bool[] resizable = new bool[8];

        resizable[4] = canResize;                    // left
        resizable[5] = canResize;                    // top
        resizable[6] = canResize;                    // right
        resizable[7] = canResize;                    // bottom

        resizable[0] = resizable[7] && resizable[4]; // bottom-left
        resizable[1] = resizable[5] && resizable[4]; // top-left
        resizable[2] = resizable[5] && resizable[6]; // top-right
        resizable[3] = resizable[7] && resizable[6]; // bottom-right

        UIWidget.Pivot pivotUnderMouse = UIWidgetInspector.GetPivotUnderMouse(handles, e, resizable, true, ref actionUnderMouse);

        switch (type)
        {
        case EventType.Repaint:
        {
            Vector3 v0 = HandleUtility.WorldToGUIPoint(handles[0]);
            Vector3 v2 = HandleUtility.WorldToGUIPoint(handles[2]);

            if ((v2 - v0).magnitude > 60f)
            {
                Vector3 v1 = HandleUtility.WorldToGUIPoint(handles[1]);
                Vector3 v3 = HandleUtility.WorldToGUIPoint(handles[3]);

                Handles.BeginGUI();
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        DrawKnob(handles[i], id, resizable[i]);
                    }

                    if (Mathf.Abs(v1.y - v0.y) > 80f)
                    {
                        if (mPanel.leftAnchor.target == null || mPanel.leftAnchor.absolute != 0)
                        {
                            DrawKnob(handles[4], id, resizable[4]);
                        }

                        if (mPanel.rightAnchor.target == null || mPanel.rightAnchor.absolute != 0)
                        {
                            DrawKnob(handles[6], id, resizable[6]);
                        }
                    }

                    if (Mathf.Abs(v3.x - v0.x) > 80f)
                    {
                        if (mPanel.topAnchor.target == null || mPanel.topAnchor.absolute != 0)
                        {
                            DrawKnob(handles[5], id, resizable[5]);
                        }

                        if (mPanel.bottomAnchor.target == null || mPanel.bottomAnchor.absolute != 0)
                        {
                            DrawKnob(handles[7], id, resizable[7]);
                        }
                    }
                }
                Handles.EndGUI();
            }
        }
        break;

        case EventType.MouseDown:
        {
            if (actionUnderMouse != UIWidgetInspector.Action.None)
            {
                mStartMouse     = e.mousePosition;
                mAllowSelection = true;

                if (e.button == 1)
                {
                    if (e.modifiers == 0)
                    {
                        GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                        e.Use();
                    }
                }
                else if (e.button == 0 && actionUnderMouse != UIWidgetInspector.Action.None &&
                         UIWidgetInspector.Raycast(handles, out mStartDrag))
                {
                    mWorldPos             = t.position;
                    mLocalPos             = t.localPosition;
                    mStartRot             = t.localRotation.eulerAngles;
                    mStartDir             = mStartDrag - t.position;
                    mStartCR              = mPanel.baseClipRegion;
                    mDragPivot            = pivotUnderMouse;
                    mActionUnderMouse     = actionUnderMouse;
                    GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                    e.Use();
                }
            }
        }
        break;

        case EventType.MouseUp:
        {
            if (GUIUtility.hotControl == id)
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;

                if (e.button < 2)
                {
                    bool handled = false;

                    if (e.button == 1)
                    {
                        // Right-click: Open a context menu listing all widgets underneath
                        NGUIEditorTools.ShowSpriteSelectionMenu(e.mousePosition);
                        handled = true;
                    }
                    else if (mAction == UIWidgetInspector.Action.None)
                    {
                        if (mAllowSelection)
                        {
                            // Left-click: Select the topmost widget
                            NGUIEditorTools.SelectWidget(e.mousePosition);
                            handled = true;
                        }
                    }
                    else
                    {
                        // Finished dragging something
                        Vector3 pos = t.localPosition;
                        pos.x           = Mathf.Round(pos.x);
                        pos.y           = Mathf.Round(pos.y);
                        pos.z           = Mathf.Round(pos.z);
                        t.localPosition = pos;
                        handled         = true;
                    }

                    if (handled)
                    {
                        e.Use();
                    }
                }

                // Clear the actions
                mActionUnderMouse = UIWidgetInspector.Action.None;
                mAction           = UIWidgetInspector.Action.None;
            }
            else if (mAllowSelection)
            {
                List <UIWidget> widgets = NGUIEditorTools.SceneViewRaycast(e.mousePosition);
                if (widgets.Count > 0)
                {
                    Selection.activeGameObject = widgets[0].gameObject;
                }
            }
            mAllowSelection = true;
        }
        break;

        case EventType.MouseDrag:
        {
            // Prevent selection once the drag operation begins
            bool dragStarted = (e.mousePosition - mStartMouse).magnitude > 3f;
            if (dragStarted)
            {
                mAllowSelection = false;
            }

            if (GUIUtility.hotControl == id)
            {
                e.Use();

                if (mAction != UIWidgetInspector.Action.None || mActionUnderMouse != UIWidgetInspector.Action.None)
                {
                    Vector3 pos;

                    if (UIWidgetInspector.Raycast(handles, out pos))
                    {
                        if (mAction == UIWidgetInspector.Action.None && mActionUnderMouse != UIWidgetInspector.Action.None)
                        {
                            // Wait until the mouse moves by more than a few pixels
                            if (dragStarted)
                            {
                                if (mActionUnderMouse == UIWidgetInspector.Action.Move)
                                {
                                    NGUISnap.Recalculate(mPanel);
                                }
                                else if (mActionUnderMouse == UIWidgetInspector.Action.Rotate)
                                {
                                    mStartRot = t.localRotation.eulerAngles;
                                    mStartDir = mStartDrag - t.position;
                                }
                                else if (mActionUnderMouse == UIWidgetInspector.Action.Scale)
                                {
                                    mStartCR   = mPanel.baseClipRegion;
                                    mDragPivot = pivotUnderMouse;
                                }
                                mAction = actionUnderMouse;
                            }
                        }

                        if (mAction != UIWidgetInspector.Action.None)
                        {
                            NGUIEditorTools.RegisterUndo("Change Rect", t);
                            NGUIEditorTools.RegisterUndo("Change Rect", mPanel);

                            if (mAction == UIWidgetInspector.Action.Move)
                            {
                                Vector3 before      = t.position;
                                Vector3 beforeLocal = t.localPosition;
                                t.position = mWorldPos + (pos - mStartDrag);
                                pos        = NGUISnap.Snap(t.localPosition, mPanel.localCorners,
                                                           e.modifiers != EventModifiers.Control) - beforeLocal;
                                t.position = before;

                                NGUIMath.MoveRect(mPanel, pos.x, pos.y);
                            }
                            else if (mAction == UIWidgetInspector.Action.Rotate)
                            {
                                Vector3 dir   = pos - t.position;
                                float   angle = Vector3.Angle(mStartDir, dir);

                                if (angle > 0f)
                                {
                                    float dot = Vector3.Dot(Vector3.Cross(mStartDir, dir), t.forward);
                                    if (dot < 0f)
                                    {
                                        angle = -angle;
                                    }
                                    angle = mStartRot.z + angle;
                                    angle = (NGUISnap.allow && e.modifiers != EventModifiers.Control) ?
                                            Mathf.Round(angle / 15f) * 15f : Mathf.Round(angle);
                                    t.localRotation = Quaternion.Euler(mStartRot.x, mStartRot.y, angle);
                                }
                            }
                            else if (mAction == UIWidgetInspector.Action.Scale)
                            {
                                // World-space delta since the drag started
                                Vector3 delta = pos - mStartDrag;

                                // Adjust the widget's position and scale based on the delta, restricted by the pivot
                                AdjustClipping(mPanel, mLocalPos, mStartCR, delta, mDragPivot);
                            }
                        }
                    }
                }
            }
        }
        break;

        case EventType.KeyDown:
        {
            if (e.keyCode == KeyCode.UpArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mPanel);
                NGUIMath.MoveRect(mPanel, 0f, 1f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.DownArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mPanel);
                NGUIMath.MoveRect(mPanel, 0f, -1f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.LeftArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mPanel);
                NGUIMath.MoveRect(mPanel, -1f, 0f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.RightArrow)
            {
                NGUIEditorTools.RegisterUndo("Nudge Rect", t);
                NGUIEditorTools.RegisterUndo("Nudge Rect", mPanel);
                NGUIMath.MoveRect(mPanel, 1f, 0f);
                e.Use();
            }
            else if (e.keyCode == KeyCode.Escape)
            {
                if (GUIUtility.hotControl == id)
                {
                    if (mAction != UIWidgetInspector.Action.None)
                    {
                        Undo.PerformUndo();
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;

                    mActionUnderMouse = UIWidgetInspector.Action.None;
                    mAction           = UIWidgetInspector.Action.None;
                    e.Use();
                }
                else
                {
                    Selection.activeGameObject = null;
                }
            }
        }
        break;
        }
    }
    public override void OnInspectorGUI()
    {
        GUILayout.Space(6f);
        NGUIEditorTools.SetLabelWidth(90f);

        string       fieldName = "Item Size";
        string       error     = null;
        UIScrollView sv        = null;

        if (!serializedObject.isEditingMultipleObjects)
        {
            UIWrapContent list = target as UIWrapContent;
            sv = NGUITools.FindInParents <UIScrollView>(list.gameObject);

            if (sv == null)
            {
                error = "UIWrappedList needs a Scroll View on its parent in order to work properly";
            }
            else if (sv.movement == UIScrollView.Movement.Horizontal)
            {
                fieldName = "Item Width";
            }
            else if (sv.movement == UIScrollView.Movement.Vertical)
            {
                fieldName = "Item Height";
            }
            else
            {
                error = "Scroll View needs to be using Horizontal or Vertical movement";
            }
        }

        serializedObject.Update();
        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty(fieldName, serializedObject, "itemSize", GUILayout.Width(130f));
        GUILayout.Label("pixels");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        SerializedProperty sp1 = NGUIEditorTools.DrawProperty("Range Limit", serializedObject, "minIndex", GUILayout.Width(130f));

        NGUIEditorTools.SetLabelWidth(20f);
        SerializedProperty sp2 = NGUIEditorTools.DrawProperty("to", serializedObject, "maxIndex", GUILayout.Width(60f));

        NGUIEditorTools.SetLabelWidth(90f);
        if (sp1.intValue == sp2.intValue)
        {
            GUILayout.Label("unlimited");
        }
        GUILayout.EndHorizontal();

        NGUIEditorTools.DrawProperty("Cull Content", serializedObject, "cullContent");

        if (!string.IsNullOrEmpty(error))
        {
            EditorGUILayout.HelpBox(error, MessageType.Error);
            if (sv != null && GUILayout.Button("Select the Scroll View"))
            {
                Selection.activeGameObject = sv.gameObject;
            }
        }

        serializedObject.ApplyModifiedProperties();

        if (sp1.intValue != sp2.intValue)
        {
            if ((target as UIWrapContent).GetComponent <UICenterOnChild>() != null)
            {
                EditorGUILayout.HelpBox("Limiting indices doesn't play well with UICenterOnChild. You should either not limit the indices, or not use UICenterOnChild.", MessageType.Warning);
            }
        }
    }
Exemplo n.º 24
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;
                }
            }
        }
    }
Exemplo n.º 25
0
    /// <summary>
    /// Convenience function that displays a list of sprites and returns the selected value.
    /// </summary>

    static public void AdvancedSpriteField(UIAtlas atlas, string spriteName, SpriteSelector.Callback callback, bool editable,
                                           params GUILayoutOption[] options)
    {
        // Give the user a warning if there are no sprites in the atlas
        if (atlas.spriteList.Count == 0)
        {
            EditorGUILayout.HelpBox("No sprites found", MessageType.Warning);
            return;
        }

        // Sprite selection drop-down list
        GUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Sprite", "DropDownButton", GUILayout.Width(76f)))
            {
                SpriteSelector.Show(atlas, spriteName, callback);
            }

            if (editable)
            {
                if (!string.Equals(spriteName, mLastSprite))
                {
                    mLastSprite = spriteName;
                    mEditedName = null;
                }

                string newName = GUILayout.TextField(string.IsNullOrEmpty(mEditedName) ? spriteName : mEditedName);

                if (newName != spriteName)
                {
                    mEditedName = newName;

                    if (GUILayout.Button("Rename", GUILayout.Width(60f)))
                    {
                        UIAtlas.Sprite sprite = atlas.GetSprite(spriteName);

                        if (sprite != null)
                        {
                            NGUIEditorTools.RegisterUndo("Edit Sprite Name", atlas);
                            sprite.name = newName;

                            List <UISprite> sprites = FindAll <UISprite>();

                            for (int i = 0; i < sprites.Count; ++i)
                            {
                                UISprite sp = sprites[i];

                                if (sp.atlas == atlas && sp.spriteName == spriteName)
                                {
                                    NGUIEditorTools.RegisterUndo("Edit Sprite Name", sp);
                                    sp.spriteName = newName;
                                }
                            }

                            mLastSprite = newName;
                            spriteName  = newName;
                            mEditedName = null;

                            NGUISettings.selectedSprite = spriteName;
                        }
                    }
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(spriteName, "HelpBox", GUILayout.Height(18f));
                GUILayout.Space(18f);
                GUILayout.EndHorizontal();

                if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                {
                    NGUISettings.selectedSprite = spriteName;
                    Select(atlas.gameObject);
                }
            }
        }
        GUILayout.EndHorizontal();
    }
Exemplo n.º 26
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.º 27
0
    /// <summary>
    /// Create a list of sprites using the specified list of textures.
    /// </summary>

    static public List <SpriteEntry> CreateSprites(List <Texture> textures)
    {
        List <SpriteEntry> list = new List <SpriteEntry>();

        foreach (Texture tex in textures)
        {
            Texture2D oldTex = NGUIEditorTools.ImportTexture(tex, true, false, true);
            if (oldTex == null)
            {
                oldTex = tex as Texture2D;
            }
            if (oldTex == null)
            {
                continue;
            }

            // If we aren't doing trimming, just use the texture as-is
            if (!NGUISettings.atlasTrimming && !NGUISettings.atlasPMA)
            {
                SpriteEntry sprite = new SpriteEntry();
                sprite.SetRect(0, 0, oldTex.width, oldTex.height);
                sprite.tex              = oldTex;
                sprite.name             = oldTex.name;
                sprite.temporaryTexture = false;
                list.Add(sprite);
                continue;
            }

            // If we want to trim transparent pixels, there is more work to be done
            Color32[] pixels = oldTex.GetPixels32();

            int xmin      = oldTex.width;
            int xmax      = 0;
            int ymin      = oldTex.height;
            int ymax      = 0;
            int oldWidth  = oldTex.width;
            int oldHeight = oldTex.height;

            // Find solid pixels
            if (NGUISettings.atlasTrimming)
            {
                for (int y = 0, yw = oldHeight; y < yw; ++y)
                {
                    for (int x = 0, xw = oldWidth; x < xw; ++x)
                    {
                        Color32 c = pixels[y * xw + x];

                        if (c.a != 0)
                        {
                            if (y < ymin)
                            {
                                ymin = y;
                            }
                            if (y > ymax)
                            {
                                ymax = y;
                            }
                            if (x < xmin)
                            {
                                xmin = x;
                            }
                            if (x > xmax)
                            {
                                xmax = x;
                            }
                        }
                    }
                }
            }
            else
            {
                xmin = 0;
                xmax = oldWidth - 1;
                ymin = 0;
                ymax = oldHeight - 1;
            }

            int newWidth  = (xmax - xmin) + 1;
            int newHeight = (ymax - ymin) + 1;

            if (newWidth > 0 && newHeight > 0)
            {
                SpriteEntry sprite = new SpriteEntry();
                sprite.x      = 0;
                sprite.y      = 0;
                sprite.width  = oldTex.width;
                sprite.height = oldTex.height;

                // If the dimensions match, then nothing was actually trimmed
                if (!NGUISettings.atlasPMA && (newWidth == oldWidth && newHeight == oldHeight))
                {
                    sprite.tex              = oldTex;
                    sprite.name             = oldTex.name;
                    sprite.temporaryTexture = false;
                }
                else
                {
                    // Copy the non-trimmed texture data into a temporary buffer
                    Color32[] newPixels = new Color32[newWidth * newHeight];

                    for (int y = 0; y < newHeight; ++y)
                    {
                        for (int x = 0; x < newWidth; ++x)
                        {
                            int newIndex = y * newWidth + x;
                            int oldIndex = (ymin + y) * oldWidth + (xmin + x);
                            if (NGUISettings.atlasPMA)
                            {
                                newPixels[newIndex] = NGUITools.ApplyPMA(pixels[oldIndex]);
                            }
                            else
                            {
                                newPixels[newIndex] = pixels[oldIndex];
                            }
                        }
                    }

                    // Create a new texture
                    sprite.name = oldTex.name;
                    sprite.SetTexture(newPixels, newWidth, newHeight);

                    // Remember the padding offset
                    sprite.SetPadding(xmin, ymin, oldWidth - newWidth - xmin, oldHeight - newHeight - ymin);
                }
                list.Add(sprite);
            }
        }
        return(list);
    }
Exemplo n.º 28
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

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

        NGUIEditorTools.DrawSeparator();

        InvBaseItem item = null;

        if (db.items == null || db.items.Count == 0)
        {
            mIndex = 0;
        }
        else
        {
            mIndex = Mathf.Clamp(mIndex, 0, db.items.Count - 1);
            item   = db.items[mIndex];
        }

        if (mConfirmDelete)
        {
            // Show the confirmation dialog
            GUILayout.Label("Are you sure you want to delete '" + item.name + "'?");
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            {
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Cancel"))
                {
                    mConfirmDelete = false;
                }
                GUI.backgroundColor = Color.red;

                if (GUILayout.Button("Delete"))
                {
                    NGUIEditorTools.RegisterUndo("Delete Inventory Item", db);
                    db.items.RemoveAt(mIndex);
                    mConfirmDelete = false;
                }
                GUI.backgroundColor = Color.white;
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            // Database icon atlas
            var atlas = db.iconAtlas;
            if (atlas is UIAtlas)
            {
                atlas = EditorGUILayout.ObjectField("Icon Atlas", atlas, typeof(UIAtlas), false) as UIAtlas;
            }
            else
            {
                atlas = EditorGUILayout.ObjectField("Icon Atlas", atlas, typeof(NGUIAtlas), false) as NGUIAtlas;
            }

            if (atlas != db.iconAtlas)
            {
                NGUIEditorTools.RegisterUndo("Databse Atlas change", db);
                db.iconAtlas = atlas;
                foreach (InvBaseItem i in db.items)
                {
                    i.iconAtlas = atlas;
                }
            }

            // Database ID
            int dbID = EditorGUILayout.IntField("Database ID", db.databaseID);

            if (dbID != db.databaseID)
            {
                NGUIEditorTools.RegisterUndo("Database ID change", db);
                db.databaseID = dbID;
            }

            // "New" button
            GUI.backgroundColor = Color.green;

            if (GUILayout.Button("New Item"))
            {
                NGUIEditorTools.RegisterUndo("Add Inventory Item", db);

                InvBaseItem bi = new InvBaseItem();
                bi.iconAtlas = db.iconAtlas;
                bi.id16      = (db.items.Count > 0) ? db.items[db.items.Count - 1].id16 + 1 : 0;
                db.items.Add(bi);
                mIndex = db.items.Count - 1;

                if (item != null)
                {
                    bi.name         = "Copy of " + item.name;
                    bi.description  = item.description;
                    bi.slot         = item.slot;
                    bi.color        = item.color;
                    bi.iconName     = item.iconName;
                    bi.attachment   = item.attachment;
                    bi.minItemLevel = item.minItemLevel;
                    bi.maxItemLevel = item.maxItemLevel;

                    foreach (InvStat stat in item.stats)
                    {
                        InvStat copy = new InvStat();
                        copy.id       = stat.id;
                        copy.amount   = stat.amount;
                        copy.modifier = stat.modifier;
                        bi.stats.Add(copy);
                    }
                }
                else
                {
                    bi.name        = "New Item";
                    bi.description = "Item Description";
                }

                item = bi;
            }
            GUI.backgroundColor = Color.white;

            if (item != null)
            {
                NGUIEditorTools.DrawSeparator();

                // Navigation section
                GUILayout.BeginHorizontal();
                {
                    if (mIndex == 0)
                    {
                        GUI.color = Color.grey;
                    }
                    if (GUILayout.Button("<<"))
                    {
                        mConfirmDelete = false; --mIndex;
                    }
                    GUI.color = Color.white;
                    mIndex    = EditorGUILayout.IntField(mIndex + 1, GUILayout.Width(40f)) - 1;
                    GUILayout.Label("/ " + db.items.Count, GUILayout.Width(40f));
                    if (mIndex + 1 == db.items.Count)
                    {
                        GUI.color = Color.grey;
                    }
                    if (GUILayout.Button(">>"))
                    {
                        mConfirmDelete = false; ++mIndex;
                    }
                    GUI.color = Color.white;
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawSeparator();

                // Item name and delete item button
                GUILayout.BeginHorizontal();
                {
                    string itemName = EditorGUILayout.TextField("Item Name", item.name);

                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("Delete", GUILayout.Width(55f)))
                    {
                        mConfirmDelete = true;
                    }
                    GUI.backgroundColor = Color.white;

                    if (!itemName.Equals(item.name))
                    {
                        NGUIEditorTools.RegisterUndo("Rename Item", db);
                        item.name = itemName;
                    }
                }
                GUILayout.EndHorizontal();

                string           itemDesc   = GUILayout.TextArea(item.description, 200, GUILayout.Height(100f));
                InvBaseItem.Slot slot       = (InvBaseItem.Slot)EditorGUILayout.EnumPopup("Slot", item.slot);
                string           iconName   = "";
                float            iconSize   = 64f;
                bool             drawIcon   = false;
                float            extraSpace = 0f;
                var ia = item.iconAtlas as INGUIAtlas;

                if (ia != null)
                {
                    var sprites = ia.GetListOfSprites();
                    sprites.Insert(0, "<None>");

                    int    index      = 0;
                    string spriteName = (item.iconName != null) ? item.iconName : sprites.buffer[0];

                    // We need to find the sprite in order to have it selected
                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        for (int i = 1; i < sprites.size; ++i)
                        {
                            if (spriteName.Equals(sprites.buffer[i], System.StringComparison.OrdinalIgnoreCase))
                            {
                                index = i;
                                break;
                            }
                        }
                    }

                    // Draw the sprite selection popup
                    index = EditorGUILayout.Popup("Icon", index, sprites.ToArray());
                    UISpriteData sprite = (index > 0) ? ia.GetSprite(sprites.buffer[index]) : null;

                    if (sprite != null)
                    {
                        iconName = sprite.name;

                        var mat = ia.spriteMaterial;

                        if (mat != null)
                        {
                            Texture2D tex = mat.mainTexture as Texture2D;

                            if (tex != null)
                            {
                                drawIcon = true;
                                Rect rect = new Rect(sprite.x, sprite.y, sprite.width, sprite.height);
                                rect = NGUIMath.ConvertToTexCoords(rect, tex.width, tex.height);

                                GUILayout.Space(4f);
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(Screen.width - iconSize);
                                    DrawSprite(tex, rect, null, false);
                                }
                                GUILayout.EndHorizontal();

                                extraSpace = iconSize * (float)sprite.height / sprite.width;
                            }
                        }
                    }
                }

                // Item level range
                GUILayout.BeginHorizontal();
                GUILayout.Label("Level Range", GUILayout.Width(77f));
                int min = EditorGUILayout.IntField(item.minItemLevel, GUILayout.MinWidth(40f));
                int max = EditorGUILayout.IntField(item.maxItemLevel, GUILayout.MinWidth(40f));
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Game Object attachment field, left of the icon
                GUILayout.BeginHorizontal();
                GameObject go = (GameObject)EditorGUILayout.ObjectField("Attachment", item.attachment, typeof(GameObject), false);
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Color tint field, left of the icon
                GUILayout.BeginHorizontal();
                Color color = EditorGUILayout.ColorField("Color", item.color);
                if (drawIcon)
                {
                    GUILayout.Space(iconSize);
                }
                GUILayout.EndHorizontal();

                // Calculate the extra spacing necessary for the icon to show up properly and not overlap anything
                if (drawIcon)
                {
                    extraSpace = Mathf.Max(0f, extraSpace - 60f);
                    GUILayout.Space(extraSpace);
                }

                // Item stats
                NGUIEditorTools.DrawSeparator();

                if (item.stats != null)
                {
                    for (int i = 0; i < item.stats.Count; ++i)
                    {
                        InvStat stat = item.stats[i];

                        GUILayout.BeginHorizontal();
                        {
                            InvStat.Identifier iden = (InvStat.Identifier)EditorGUILayout.EnumPopup(stat.id, GUILayout.Width(80f));

                            // Color the field red if it's negative, green if it's positive
                            if (stat.amount > 0)
                            {
                                GUI.backgroundColor = Color.green;
                            }
                            else if (stat.amount < 0)
                            {
                                GUI.backgroundColor = Color.red;
                            }
                            int amount = EditorGUILayout.IntField(stat.amount, GUILayout.Width(40f));
                            GUI.backgroundColor = Color.white;

                            InvStat.Modifier mod = (InvStat.Modifier)EditorGUILayout.EnumPopup(stat.modifier);

                            GUI.backgroundColor = Color.red;
                            if (GUILayout.Button("X", GUILayout.Width(20f)))
                            {
                                NGUIEditorTools.RegisterUndo("Delete Item Stat", db);
                                item.stats.RemoveAt(i);
                                --i;
                            }
                            else if (iden != stat.id || amount != stat.amount || mod != stat.modifier)
                            {
                                NGUIEditorTools.RegisterUndo("Item Stats", db);
                                stat.id       = iden;
                                stat.amount   = amount;
                                stat.modifier = mod;
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                if (GUILayout.Button("Add Stat", GUILayout.Width(80f)))
                {
                    NGUIEditorTools.RegisterUndo("Add Item Stat", db);
                    InvStat stat = new InvStat();
                    stat.id = InvStat.Identifier.Armor;
                    item.stats.Add(stat);
                }

                // Save all values
                if (!itemDesc.Equals(item.description) ||
                    slot != item.slot ||
                    go != item.attachment ||
                    color != item.color ||
                    min != item.minItemLevel ||
                    max != item.maxItemLevel ||
                    !iconName.Equals(item.iconName))
                {
                    NGUIEditorTools.RegisterUndo("Item Properties", db);
                    item.description  = itemDesc;
                    item.slot         = slot;
                    item.attachment   = go;
                    item.color        = color;
                    item.iconName     = iconName;
                    item.minItemLevel = min;
                    item.maxItemLevel = max;
                }
            }
        }
    }
Exemplo n.º 29
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

    void OnGUI()
    {
        if (mLastAtlas != NGUISettings.atlas)
        {
            mLastAtlas = NGUISettings.atlas;
        }

        bool update  = false;
        bool replace = false;

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

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

        GUILayout.BeginHorizontal();
        {
            ComponentSelector.Draw <UIAtlas>("Atlas", NGUISettings.atlas, OnSelectAtlas, true, GUILayout.MinWidth(80f));

            EditorGUI.BeginDisabledGroup(NGUISettings.atlas == null);
            if (GUILayout.Button("New", GUILayout.Width(40f)))
            {
                NGUISettings.atlas = null;
            }
            EditorGUI.EndDisabledGroup();
        }
        GUILayout.EndHorizontal();

        List <Texture> textures = GetSelectedTextures();

        if (NGUISettings.atlas != null)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;
            Texture  tex = NGUISettings.atlas.texture;

            // Material information
            GUILayout.BeginHorizontal();
            {
                if (mat != null)
                {
                    if (GUILayout.Button("Material", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = mat;
                    }
                    GUILayout.Label(" " + mat.name);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Material", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();

            // Texture atlas information
            GUILayout.BeginHorizontal();
            {
                if (tex != null)
                {
                    if (GUILayout.Button("Texture", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = tex;
                    }
                    GUILayout.Label(" " + tex.width + "x" + tex.height);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Texture", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8);
        GUILayout.Label((NGUISettings.atlasPadding == 1 ? "pixel" : "pixels") + " between sprites");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f));
        GUILayout.Label("Remove empty space");
        GUILayout.EndHorizontal();

        bool fixedShader = false;

        if (NGUISettings.atlas != null)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;

            if (mat != null)
            {
                Shader shader = mat.shader;

                if (shader != null)
                {
                    if (shader.name == "Unlit/Transparent Colored")
                    {
                        NGUISettings.atlasPMA = false;
                        fixedShader           = true;
                    }
                    else if (shader.name == "Unlit/Premultiplied Colored")
                    {
                        NGUISettings.atlasPMA = true;
                        fixedShader           = true;
                    }
                }
            }
        }

        if (!fixedShader)
        {
            GUILayout.BeginHorizontal();
            NGUISettings.atlasPMA = EditorGUILayout.Toggle("PMA Shader", NGUISettings.atlasPMA, GUILayout.Width(100f));
            GUILayout.Label("Pre-multiplied alpha", GUILayout.MinWidth(70f));
            GUILayout.EndHorizontal();
        }

        //GUILayout.BeginHorizontal();
        //NGUISettings.keepPadding = EditorGUILayout.Toggle("Keep Padding", NGUISettings.keepPadding, GUILayout.Width(100f));
        //GUILayout.Label("or replace with trimmed pixels", GUILayout.MinWidth(70f));
        //GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f));
        GUILayout.Label("or custom packer", GUILayout.MinWidth(70f));
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.trueColorAtlas = EditorGUILayout.Toggle("Truecolor", NGUISettings.trueColorAtlas, GUILayout.Width(100f));
        GUILayout.Label("force ARGB32 textures", GUILayout.MinWidth(70f));
        GUILayout.EndHorizontal();

        if (!NGUISettings.unityPacking)
        {
            GUILayout.BeginHorizontal();
            NGUISettings.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", NGUISettings.forceSquareAtlas, GUILayout.Width(100f));
            GUILayout.Label("if on, forces a square atlas texture", GUILayout.MinWidth(70f));
            GUILayout.EndHorizontal();
        }

#if UNITY_IPHONE || UNITY_ANDROID
        GUILayout.BeginHorizontal();
        NGUISettings.allow4096 = EditorGUILayout.Toggle("4096x4096", NGUISettings.allow4096, GUILayout.Width(100f));
        GUILayout.Label("if off, limit atlases to 2048x2048");
        GUILayout.EndHorizontal();
#endif
        NGUIEditorTools.EndContents();

        if (NGUISettings.atlas != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(20f);

            if (textures.Count > 0)
            {
                update = GUILayout.Button("Add/Update");
            }
            else if (GUILayout.Button("View Sprites"))
            {
                SpriteSelector.ShowSelected();
            }

            GUILayout.Space(20f);
            GUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.HelpBox("You can create a new atlas by selecting one or more textures in the Project View window, then clicking \"Create\".", MessageType.Info);

            EditorGUI.BeginDisabledGroup(textures.Count == 0);
            GUILayout.BeginHorizontal();
            GUILayout.Space(20f);
            bool create = GUILayout.Button("Create");
            GUILayout.Space(20f);
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            if (create)
            {
                string path = EditorUtility.SaveFilePanelInProject("Save As",
                                                                   "New Atlas.prefab", "prefab", "Save atlas as...", NGUISettings.currentPath);

                if (!string.IsNullOrEmpty(path))
                {
                    NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                    GameObject go      = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                    string     matPath = path.Replace(".prefab", ".mat");
                    replace = true;

                    // Try to load the material
                    Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                    // If the material doesn't exist, create it
                    if (mat == null)
                    {
                        Shader shader = Shader.Find(NGUISettings.atlasPMA ? "Unlit/Premultiplied Colored" : "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;
                    }

                    // Create a new prefab for the atlas
                    Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(path);

                    // Create a new game object for the atlas
                    string atlasName = path.Replace(".prefab", "");
                    atlasName = atlasName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
                    go        = new GameObject(atlasName);
                    go.AddComponent <UIAtlas>().spriteMaterial = mat;

                    // Update the prefab
                    PrefabUtility.ReplacePrefab(go, prefab);
                    DestroyImmediate(go);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                    // Select the atlas
                    go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                    NGUISettings.atlas         = go.GetComponent <UIAtlas>();
                    Selection.activeGameObject = go;
                }
            }
        }

        string selection = null;
        Dictionary <string, int> spriteList = GetSpriteList(textures);

        if (spriteList.Count > 0)
        {
            NGUIEditorTools.DrawHeader("Sprites", true);
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginVertical();

                mScroll = GUILayout.BeginScrollView(mScroll);

                bool delete = false;
                int  index  = 0;
                foreach (KeyValuePair <string, int> iter in spriteList)
                {
                    ++index;

                    GUILayout.Space(-1f);
                    bool highlight = (UIAtlasInspector.instance != null) && (NGUISettings.selectedSprite == iter.Key);
                    GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);
                    GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f));
                    GUI.backgroundColor = Color.white;
                    GUILayout.Label(index.ToString(), GUILayout.Width(24f));

                    if (GUILayout.Button(iter.Key, "OL TextField", GUILayout.Height(20f)))
                    {
                        selection = iter.Key;
                    }

                    if (iter.Value == 2)
                    {
                        GUI.color = Color.green;
                        GUILayout.Label("Add", GUILayout.Width(27f));
                        GUI.color = Color.white;
                    }
                    else if (iter.Value == 1)
                    {
                        GUI.color = Color.cyan;
                        GUILayout.Label("Update", GUILayout.Width(45f));
                        GUI.color = Color.white;
                    }
                    else
                    {
                        if (mDelNames.Contains(iter.Key))
                        {
                            GUI.backgroundColor = Color.red;

                            if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                            {
                                delete = true;
                            }
                            GUI.backgroundColor = Color.green;
                            if (GUILayout.Button("X", GUILayout.Width(22f)))
                            {
                                mDelNames.Remove(iter.Key);
                                delete = false;
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        else
                        {
                            // If we have not yet selected a sprite for deletion, show a small "X" button
                            if (GUILayout.Button("X", GUILayout.Width(22f)))
                            {
                                mDelNames.Add(iter.Key);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
                GUILayout.Space(3f);
                GUILayout.EndHorizontal();

                // If this sprite was marked for deletion, remove it from the atlas
                if (delete)
                {
                    NGUIEditorTools.m_Shader = NGUISettings.atlas.spriteMaterial.shader;
                    NGUIEditorTools.SetTextureOptimization(NGUISettings.atlas, false);
                    List <SpriteEntry> sprites = new List <SpriteEntry>();
                    ExtractSprites(NGUISettings.atlas, sprites);

                    for (int i = sprites.Count; i > 0;)
                    {
                        SpriteEntry ent = sprites[--i];
                        if (mDelNames.Contains(ent.name))
                        {
                            sprites.RemoveAt(i);
                        }
                    }
                    UpdateAtlas(NGUISettings.atlas, sprites);
                    mDelNames.Clear();
                    NGUIEditorTools.RepaintSprites();
                }
                else if (update)
                {
                    UpdateAtlas(textures, true);
                }
                else if (replace)
                {
                    UpdateAtlas(textures, false);
                }

                if (NGUISettings.atlas != null && !string.IsNullOrEmpty(selection))
                {
                    NGUIEditorTools.SelectSprite(selection);
                }
                else if (update || replace)
                {
                    NGUIEditorTools.m_Shader = NGUISettings.atlas.spriteMaterial.shader;
                    NGUIEditorTools.SetTextureOptimization(NGUISettings.atlas, false);
                    NGUIEditorTools.UpgradeTexturesToSprites(NGUISettings.atlas);
                    NGUIEditorTools.RepaintSprites();
                }
            }
        }

        if (NGUISettings.atlas != null && textures.Count == 0)
        {
            EditorGUILayout.HelpBox("You can reveal more options by selecting one or more textures in the Project View window.", MessageType.Info);
        }

        // Uncomment this line if you want to be able to force-sort the atlas
        //if (NGUISettings.atlas != null && GUILayout.Button("Sort Alphabetically")) NGUISettings.atlas.SortAlphabetically();
    }
    void DrawListLayout()
    {
        NGUIEditorTools.SetLabelWidth(80f);

        if (NGUIEditorTools.DrawHeader("List Layout"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();

            if (NGUIEditorTools.DrawPrefixButton("Atlas"))
            {
                ComponentSelector.Show <UIAtlas>(OnSelectAtlas);
            }

            NGUIEditorTools.DrawProperty("", serializedObject, "atlas", GUILayout.MinWidth(20f));

            GUILayout.EndHorizontal();

            if (mList.atlas != null)
            {
                EditorGUILayout.Space();

                NGUIEditorTools.DrawSpriteField("Background", serializedObject, serializedObject.FindProperty("atlas"), serializedObject.FindProperty("listBackgroundSprite"), true);
                NGUIEditorTools.DrawProperty("BG Color", serializedObject, "listBackgroundColor");

                EditorGUILayout.Space();

                NGUIEditorTools.DrawProperty("Offset", serializedObject, "listOffset");

                EditorGUILayout.Space();
                GUI.changed = false;

                NGUIEditorTools.IntVector paddingA = NGUIEditorTools.IntPair("Padding", "Left", "Right", mList.listPaddingLeft, mList.listPaddingRight);
                NGUIEditorTools.IntVector paddingB = NGUIEditorTools.IntPair(null, "Bottom", "Top", mList.listPaddingBottom, mList.listPaddingTop);

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Select Field Padding Changed", mList);

                    mList.listPaddingLeft   = paddingA.x;
                    mList.listPaddingRight  = paddingA.y;
                    mList.listPaddingBottom = paddingB.x;
                    mList.listPaddingTop    = paddingB.y;
                }

                EditorGUILayout.Space();

                NGUIEditorTools.DrawProperty("Add to Size", serializedObject, "listAdditionalSize");

                EditorGUILayout.Space();

                NGUIEditorTools.DrawSpriteField("Separator", serializedObject, serializedObject.FindProperty("atlas"), serializedObject.FindProperty("listSeparatorSprite"), true);

                EditorGUILayout.Space();
                GUI.changed = false;

                NGUIEditorTools.IntVector sepMarginA = NGUIEditorTools.IntPair("Sep margin", "Left", "Right", mList.listSepMarginLeft, mList.listSepMarginRight);
                NGUIEditorTools.IntVector sepMarginB = NGUIEditorTools.IntPair(null, "Bottom", "Top", mList.listSepMarginBottom, mList.listSepMarginTop);

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Select Field Separator Margin Changed", mList);

                    mList.listSepMarginLeft   = sepMarginA.x;
                    mList.listSepMarginRight  = sepMarginA.y;
                    mList.listSepMarginBottom = sepMarginB.x;
                    mList.listSepMarginTop    = sepMarginB.y;
                }
            }

            EditorGUILayout.Space();

            NGUIEditorTools.DrawProperty("Animation", serializedObject, "listAnimation");
            NGUIEditorTools.DrawProperty("An. Duration", serializedObject, "listAnimationDuration");

            NGUIEditorTools.EndContents();
        }
    }