UpdateAtlas() private method

Update the sprites within the texture atlas, preserving the sprites that have not been selected.
private UpdateAtlas ( List textures, bool keepSprites ) : void
textures List
keepSprites bool
return void
Exemplo n.º 1
0
    /// <summary>
    /// Add a dark shadow below and to the right of the sprite.
    /// </summary>

    void AddShadow(UISpriteData sprite)
    {
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width;
            int h1 = se.tex.height;

            int w2 = w1 + 2;
            int h2 = h1 + 2;

            Color32[] c2 = NGUIEditorTools.AddBorder(se.tex.GetPixels32(), w1, h1);
            NGUIEditorTools.AddShadow(c2, w2, h2, NGUISettings.backgroundColor);

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            if ((se.borderLeft | se.borderRight | se.borderBottom | se.borderTop) != 0)
            {
                ++se.borderLeft;
                ++se.borderRight;
                ++se.borderTop;
                ++se.borderBottom;
            }

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Add a transparent border around the sprite.
    /// </summary>

    void AddTransparentBorder(UISpriteData sprite)
    {
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width;
            int h1 = se.tex.height;

            int w2 = w1 + 2;
            int h2 = h1 + 2;

            var c2 = NGUIEditorTools.AddBorder(se.tex.GetPixels32(), w1, h1);

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            ++se.borderLeft;
            ++se.borderRight;
            ++se.borderTop;
            ++se.borderBottom;

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            var before = NGUISettings.atlasTrimming;
            NGUISettings.atlasTrimming = false;
            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);
            NGUISettings.atlasTrimming = before;

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Delete the sprite (context menu selection)
    /// </summary>
    void DeleteSprite(object obj)
    {
        if (this == null) return;
        UISpriteData sd = obj as UISpriteData;

        List<UIAtlasMaker.SpriteEntry> sprites = new List<UIAtlasMaker.SpriteEntry>();
        UIAtlasMaker.ExtractSprites(NGUISettings.atlas, sprites);

        for (int i = sprites.Count; i > 0; )
        {
            UIAtlasMaker.SpriteEntry ent = sprites[--i];
            if (ent.name == sd.name)
                sprites.RemoveAt(i);
        }
        UIAtlasMaker.UpdateAtlas(NGUISettings.atlas, sprites);
        NGUIEditorTools.RepaintSprites();
    }
Exemplo n.º 4
0
    void DeleteSprite(SpriteInfo info)
    {
        if (this == null)
        {
            return;
        }
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(info.Atlas, sprites);

        for (int i = sprites.Count; i > 0;)
        {
            UIAtlasMaker.SpriteEntry ent = sprites[--i];
            if (ent.name == info.Data.name)
            {
                sprites.RemoveAt(i);
            }
        }
        UIAtlasMaker.UpdateAtlas(info.Atlas, sprites);
        NGUIEditorTools.RepaintSprites();
    }
Exemplo n.º 5
0
	/// <summary>
	/// Duplicate the specified sprite.
	/// </summary>

	static public SpriteEntry DuplicateSprite (UIAtlas atlas, string spriteName)
	{
		if (atlas == null || atlas.texture == null) return null;
		UISpriteData sd = atlas.GetSprite(spriteName);
		if (sd == null) return null;

		Texture2D tex = NGUIEditorTools.ImportTexture(atlas.texture, true, true, false);
		SpriteEntry se = ExtractSprite(sd, tex);

		if (se != null)
		{
			se.name = se.name + " (Copy)";

			List<UIAtlasMaker.SpriteEntry> sprites = new List<UIAtlasMaker.SpriteEntry>();
			UIAtlasMaker.ExtractSprites(atlas, sprites);
			sprites.Add(se);
			UIAtlasMaker.UpdateAtlas(atlas, sprites);
			se.Release();
		}
		else NGUIEditorTools.ImportTexture(atlas.texture, false, false, !atlas.premultipliedAlpha);
		return se;
	}
    /// <summary>
    /// Add a dark shadowy outline around the sprite, giving it some visual depth.
    /// </summary>

    void AddDepth(UISpriteData sprite)
    {
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width;
            int h1 = se.tex.height;

            int w2 = w1 + 2;
            int h2 = h1 + 2;

            Color32[] c1 = se.tex.GetPixels32();
            Color32[] c2 = new Color32[w2 * h2];

            for (int y2 = 0; y2 < h2; ++y2)
            {
                int y1 = NGUIMath.ClampIndex(y2 - 1, h1);

                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int x1 = NGUIMath.ClampIndex(x2 - 1, w1);
                    int i2 = x2 + y2 * w2;
                    c2[i2] = c1[x1 + y1 * w1];

                    if (x2 == 0 || x2 + 1 == w2 || y2 == 0 || y2 + 1 == h2)
                    {
                        c2[i2].a = 0;
                    }
                }
            }

            for (int y2 = 0; y2 < h2; ++y2)
            {
                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int     index = x2 + y2 * w2;
                    Color32 uc    = c2[index];
                    if (uc.a == 255)
                    {
                        continue;
                    }

                    Color original = uc;
                    float val      = original.a * 4f;
                    int   count    = 4;
                    float div1     = 1f / 255f;
                    float div2     = 2f / 255f;

                    if (x2 != 0)
                    {
                        val   += c2[x2 - 1 + y2 * w2].a * div2;
                        count += 2;
                    }

                    if (x2 + 1 != w2)
                    {
                        val   += c2[x2 + 1 + y2 * w2].a * div2;
                        count += 2;
                    }

                    if (y2 != 0)
                    {
                        val   += c2[x2 + (y2 - 1) * w2].a * div2;
                        count += 2;
                    }

                    if (y2 + 1 != h2)
                    {
                        val   += c2[x2 + (y2 + 1) * w2].a * div2;
                        count += 2;
                    }

                    if (x2 != 0 && y2 != 0)
                    {
                        val += c2[x2 - 1 + (y2 - 1) * w2].a * div1;
                        ++count;
                    }

                    if (x2 != 0 && y2 + 1 != h2)
                    {
                        val += c2[x2 - 1 + (y2 + 1) * w2].a * div1;
                        ++count;
                    }

                    if (x2 + 1 != w2 && y2 != 0)
                    {
                        val += c2[x2 + 1 + (y2 - 1) * w2].a * div1;
                        ++count;
                    }

                    if (x2 + 1 != w2 && y2 + 1 != h2)
                    {
                        val += c2[x2 + 1 + (y2 + 1) * w2].a * div1;
                        ++count;
                    }

                    val /= count;

                    Color shadow = new Color(0f, 0f, 0f, val);
                    shadow    = Color.Lerp(original, shadow, mAlpha);
                    c2[index] = Color.Lerp(shadow, original, original.a);
                }
            }

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            ++se.borderLeft;
            ++se.borderRight;
            ++se.borderTop;
            ++se.borderBottom;

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
    /// <summary>
    /// Add a transparent border around the sprite.
    /// </summary>

    void AddTransparentBorder(UISpriteData sprite)
    {
        List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width;
            int h1 = se.tex.height;

            int w2 = w1 + 2;
            int h2 = h1 + 2;

            Color32[] c1 = se.tex.GetPixels32();
            Color32[] c2 = new Color32[w2 * h2];

            for (int y2 = 0; y2 < h2; ++y2)
            {
                int y1 = NGUIMath.ClampIndex(y2 - 1, h1);

                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int x1 = NGUIMath.ClampIndex(x2 - 1, w1);
                    int i2 = x2 + y2 * w2;
                    c2[i2] = c1[x1 + y1 * w1];

                    if (x2 == 0 || x2 + 1 == w2 || y2 == 0 || y2 + 1 == h2)
                    {
                        c2[i2].a = 0;
                    }
                }
            }

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            ++se.borderLeft;
            ++se.borderRight;
            ++se.borderTop;
            ++se.borderBottom;

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
    /// <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);

        GUILayout.Space(18f);
        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.ExtractSprite(mAtlas, sprite.name);

                        if (se != null)
                        {
                            se.name = se.name + " (Copy)";

                            List <UIAtlasMaker.SpriteEntry> sprites = new List <UIAtlasMaker.SpriteEntry>();
                            UIAtlasMaker.ExtractSprites(mAtlas, sprites);
                            sprites.Add(se);
                            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);
                            if (se.temporaryTexture)
                            {
                                DestroyImmediate(se.tex);
                            }
                            NGUISettings.selectedSprite = se.name;
                        }
                    }

                    if (GUILayout.Button("Save As..."))
                    {
                        string path = EditorUtility.SaveFilePanelInProject("Save As", sprite.name + ".png", "png", "Extract sprite into which file?");

                        if (!string.IsNullOrEmpty(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();

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

                    //GUILayout.BeginHorizontal();
                    mAlpha = GUILayout.HorizontalSlider(mAlpha, 0f, 1f);
                    string cap = Mathf.RoundToInt(mAlpha * 100f) + "%";
                    //GUILayout.Label(cap, GUILayout.Width(40f));
                    //GUILayout.EndHorizontal();

                    if (GUILayout.Button("Add a Shadow (" + cap + ")"))
                    {
                        AddShadow(sprite);
                    }
                    if (GUILayout.Button("Add Visual Depth (" + cap + ")"))
                    {
                        AddDepth(sprite);
                    }

                    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.º 9
0
    private bool DrawAdvancedMenu()
    {
        if (Application.isPlaying == true)
        {
            return(true);
        }

        if (NGUIEditorTools.DrawHeader("Advanced menu") == false)
        {
            return(true);
        }

        NGUIEditorTools.BeginContents();
        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        _texToSprite = EditorGUILayout.ObjectField(_texToSprite, typeof(Texture), false) as Texture;

        if (GUILayout.Button("Add", GUILayout.Width(40f)))
        {
            if (_texToSprite == null)
            {
                Debug.LogError("Select a texture first.");
                return(false);
            }

            UIAtlas curAtlas = GetAtlas();

            if (curAtlas == null)
            {
                if (CreateOwnAtlas() == false)
                {
                    return(false);
                }

                curAtlas = GetAtlas();
            }

            List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>()
            {
                _texToSprite
            });
            UIAtlasMaker.ExtractSprites(curAtlas, entries);
            UIAtlasMaker.UpdateAtlas(curAtlas, entries);

            SelectSprite(_texToSprite.name);

            return(false);
        }

        if (GUILayout.Button("New") == true)
        {
            if (_texToSprite == null)
            {
                Debug.LogError("Select a texture first.");
                return(false);
            }

            if (CreateOwnAtlas() == false)
            {
                return(false);
            }

            UIAtlas curAtlas = GetAtlas();

            List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>()
            {
                _texToSprite
            });
            UIAtlasMaker.ExtractSprites(curAtlas, entries);
            UIAtlasMaker.UpdateAtlas(curAtlas, entries);

            SelectSprite(_texToSprite.name);

            return(false);
        }

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Delete sprite") == true)
        {
            UIAtlas curAtlas   = GetAtlas();
            string  curSprName = GetSpriteName();

            if (curAtlas == null)
            {
                Debug.LogError("No atlas in this UISprite");
                return(false);
            }

            if (string.IsNullOrEmpty(curSprName) == true)
            {
                Debug.LogError("No sprite in this UISprite");
                return(false);
            }

            List <UIAtlasMaker.SpriteEntry> lstSprites = new List <UIAtlasMaker.SpriteEntry>();
            UIAtlasMaker.ExtractSprites(curAtlas, lstSprites);

            for (int i = lstSprites.Count; i > 0;)
            {
                UIAtlasMaker.SpriteEntry entry = lstSprites[--i];

                if (entry.name == curSprName)
                {
                    lstSprites.RemoveAt(i);
                }
            }
            UIAtlasMaker.UpdateAtlas(curAtlas, lstSprites);
            NGUIEditorTools.RepaintSprites();

            return(false);
        }

        if (GUILayout.Button("Atlas Maker") == true)
        {
            EditorWindow.GetWindow <UIAtlasMaker>(false, "Atlas Maker", true).Show();

            return(false);
        }

        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        NGUIEditorTools.EndContents();

        return(true);
    }
Exemplo n.º 10
0
    protected override bool ShouldDrawProperties()
    {
        if (target == null)
        {
            return(false);
        }

        if (Application.isPlaying == false && NGUIEditorTools.DrawHeader("Tex to Spr"))
        {
            NGUIEditorTools.BeginContents();
            GUILayout.BeginHorizontal();

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

            UIAtlas curAtlas = NGUISettings.atlas;

            if (curAtlas != null)
            {
                GUILayout.Label(curAtlas.name, "HelpBox", GUILayout.Height(18f));
            }
            else
            {
                GUILayout.Label("No Atlas", "HelpBox", GUILayout.Height(18f));
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("ToS", GUILayout.Width(40f)))
            {
                if (curAtlas == null)
                {
                    CreateOwnAtlas();

                    curAtlas = NGUISettings.atlas;
                }

                List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>()
                {
                    mTex.mainTexture
                });
                UIAtlasMaker.ExtractSprites(curAtlas, entries);
                UIAtlasMaker.UpdateAtlas(curAtlas, entries);

                UISprite sprite = mTex.gameObject.AddComponent <UISprite>();
                sprite.atlas      = curAtlas;
                sprite.spriteName = mTex.mainTexture.name;

                sprite.type = mTex.type;

                UISpriteData data = sprite.GetAtlasSprite();
                data.SetBorder((int)mTex.border.w, (int)mTex.border.y, (int)mTex.border.x, (int)mTex.border.z);

                sprite.depth  = mTex.depth;
                sprite.width  = mTex.width;
                sprite.height = mTex.height;

                UITexture.DestroyImmediate(mTex);

                EditorGUIUtility.ExitGUI();

                return(false);
            }

            GUILayout.EndHorizontal();
            NGUIEditorTools.EndContents();
        }

        SerializedProperty sp = NGUIEditorTools.DrawProperty("Texture", serializedObject, "mTexture");

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

        if (sp != null)
        {
            NGUISettings.texture = sp.objectReferenceValue as Texture;
        }

        if (mTex != null && (mTex.material == null || serializedObject.isEditingMultipleObjects))
        {
            NGUIEditorTools.DrawProperty("Shader", serializedObject, "mShader");
        }

        EditorGUI.BeginDisabledGroup(mTex == null || mTex.mainTexture == null || serializedObject.isEditingMultipleObjects);

        NGUIEditorTools.DrawRectProperty("UV Rect", serializedObject, "mRect");

        sp = serializedObject.FindProperty("mFixedAspect");
        bool before = sp.boolValue;

        NGUIEditorTools.DrawProperty("Fixed Aspect", sp);
        if (sp.boolValue != before)
        {
            (target as UIWidget).drawRegion = new Vector4(0f, 0f, 1f, 1f);
        }

        if (sp.boolValue)
        {
            EditorGUILayout.HelpBox("Note that Fixed Aspect mode is not compatible with Draw Region modifications done by sliders and progress bars.", MessageType.Info);
        }

        EditorGUI.EndDisabledGroup();

        return(true);
    }
Exemplo n.º 11
0
    /// <summary>
    /// Crop the border pixels around the sprite.
    /// </summary>

    void CropBorder(UISpriteData sprite)
    {
        var sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width;
            int h1 = se.tex.height;

            int w2 = w1 - se.borderLeft - se.borderRight;
            int h2 = h1 - se.borderTop - se.borderBottom;

            var c1 = se.tex.GetPixels32();
            var c2 = new Color32[w2 * h2];

            for (int y2 = 0; y2 < h2; ++y2)
            {
                int y1 = y2 + se.borderBottom;

                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int x1 = x2 + se.borderLeft;
                    c2[x2 + y2 * w2] = c1[x1 + y1 * w1];
                }
            }

            se.borderLeft   = 0;
            se.borderRight  = 0;
            se.borderTop    = 0;
            se.borderBottom = 0;

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            var before = NGUISettings.atlasTrimming;
            NGUISettings.atlasTrimming = false;
            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);
            NGUISettings.atlasTrimming = before;

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
Exemplo n.º 12
0
    /// <summary>
    /// Add a border around the sprite that copies the pixels from the opposite side, making it possible for the sprite to tile without seams.
    /// </summary>

    void AddTiledBorder(UISpriteData sprite)
    {
        var sprites = new List <UIAtlasMaker.SpriteEntry>();

        UIAtlasMaker.ExtractSprites(mAtlas, sprites);
        UIAtlasMaker.SpriteEntry se = null;

        for (int i = 0; i < sprites.Count; ++i)
        {
            if (sprites[i].name == sprite.name)
            {
                se = sprites[i];
                break;
            }
        }

        if (se != null)
        {
            int w1 = se.tex.width - se.borderLeft - se.borderRight;
            int h1 = se.tex.height - se.borderBottom - se.borderTop;

            int w2 = se.tex.width + 2;
            int h2 = se.tex.height + 2;

            var c1 = se.tex.GetPixels32();
            var c2 = new Color32[w2 * h2];

            for (int y2 = 0; y2 < h2; ++y2)
            {
                int y1 = se.borderBottom + NGUIMath.RepeatIndex(y2 - se.borderBottom - 1, h1);

                for (int x2 = 0; x2 < w2; ++x2)
                {
                    int x1 = se.borderLeft + NGUIMath.RepeatIndex(x2 - se.borderLeft - 1, w1);
                    c2[x2 + y2 * w2] = c1[x1 + y1 * se.tex.width];
                }
            }

            if (se.temporaryTexture)
            {
                DestroyImmediate(se.tex);
            }

            ++se.borderLeft;
            ++se.borderRight;
            ++se.borderTop;
            ++se.borderBottom;

            se.tex      = new Texture2D(w2, h2);
            se.tex.name = sprite.name;
            se.tex.SetPixels32(c2);
            se.tex.Apply();
            se.temporaryTexture = true;

            var before = NGUISettings.atlasTrimming;
            NGUISettings.atlasTrimming = false;
            UIAtlasMaker.UpdateAtlas(mAtlas, sprites);
            NGUISettings.atlasTrimming = before;

            DestroyImmediate(se.tex);
            se.tex = null;
        }
    }
Exemplo n.º 13
0
    public static UIAtlas CreateAtlas(string atlasName, Device device, AtlasType atlasType)
    {
        List <UISpriteData> oldSpriteData;

#if RSATLASHELPER_DEBUG
        Debug.Log(string.Format("AddNewAtlas; atlasName = {0}, device = {1}, atlasType = {2}", atlasName, device, atlasType));
#endif

        string texturesDir = GetAtlasTexturesDirectory(atlasName, device, atlasType);

        DirectoryInfo dirInfo = new DirectoryInfo("Assets/" + texturesDir);
        if (dirInfo == null || !dirInfo.Exists)
        {
            Debug.LogWarning("Directory does not exist; " + atlasName + ", for device: " + device + " " + texturesDir);
            return(null);
        }
        List <FileInfo> fis;
        GetTextureAssets(dirInfo, out fis);

        if (fis == null && fis.Count == 0)
        {
            Debug.LogWarning("Directory empty; " + atlasName + ", for device: " + device);
            return(null);
        }

        UIAtlas newAtlas = CreateAtlasInternal(atlasName, device, atlasType, out oldSpriteData);
        if (newAtlas == null)
        {
            Debug.LogWarning("Could not create atlas for " + atlasName + ", device = " + device);
            return(null);
        }

        NGUISettings.atlas            = newAtlas;
        NGUISettings.atlasPadding     = 2;
        NGUISettings.atlasTrimming    = false;
        NGUISettings.forceSquareAtlas = true;
        NGUISettings.allow4096        = (atlasType == AtlasType.HD);
        NGUISettings.fontTexture      = null;
        NGUISettings.unityPacking     = false;

        if (device == Device.Tablet || device == Device.Standalone)
        {
            newAtlas.pixelSize = (atlasType == AtlasType.HD) ? 1f : 2f;
        }
        else
        {
            newAtlas.pixelSize = 1f;
        }

        EditorUtility.SetDirty(newAtlas.gameObject);

        List <Texture> textures = new List <Texture>();

        foreach (FileInfo fi in fis)
        {
            string textureName = "Assets" + texturesDir + fi.Name;

            Texture2D tex = AssetDatabase.LoadAssetAtPath(textureName, typeof(Texture2D)) as Texture2D;

            TextureImporter texImporter = AssetImporter.GetAtPath(textureName) as TextureImporter;
            texImporter.textureType         = TextureImporterType.Default;
            texImporter.npotScale           = TextureImporterNPOTScale.None;
            texImporter.generateCubemap     = TextureImporterGenerateCubemap.None;
            texImporter.normalmap           = false;
            texImporter.linearTexture       = true;
            texImporter.alphaIsTransparency = true;
            texImporter.convertToNormalmap  = false;
            texImporter.grayscaleToAlpha    = false;
            texImporter.lightmap            = false;
            texImporter.npotScale           = TextureImporterNPOTScale.None;
            texImporter.filterMode          = FilterMode.Point;
            texImporter.wrapMode            = TextureWrapMode.Clamp;
            texImporter.maxTextureSize      = 4096;
            texImporter.mipmapEnabled       = false;
            texImporter.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
            AssetDatabase.ImportAsset(textureName, ImportAssetOptions.ForceUpdate);

            tex.filterMode = FilterMode.Bilinear;
            tex.wrapMode   = TextureWrapMode.Clamp;

            textures.Add(tex);

#if RSATLASHELPER_DEBUG
            Debug.Log("- added tex: " + textureName);
#endif
        }

        List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures);
        UIAtlasMaker.ExtractSprites(newAtlas, sprites);
        UIAtlasMaker.UpdateAtlas(newAtlas, sprites);
        AssetDatabase.SaveAssets();

        {
            string resourceDir = GetAtlasResourceFolder(device, atlasType);
            string atlasName2  = GetAtlasName(atlasName, device, atlasType);
            string newTex      = "Assets" + resourceDir + atlasName2 + ".png";

            TextureImporter texImporter    = AssetImporter.GetAtPath(newTex) as TextureImporter;
            int             maxTextureSize = atlasType == AtlasType.HD ? 4096 : 2048;
            texImporter.maxTextureSize = maxTextureSize;
            texImporter.textureFormat  = TextureImporterFormat.AutomaticCompressed;
            if (device == Device.Phone)
            {
                texImporter.mipmapEnabled = true;
                texImporter.borderMipmap  = true;
                texImporter.mipmapFilter  = TextureImporterMipFilter.BoxFilter;
            }
            else
            {
                texImporter.mipmapEnabled = false;
            }
            texImporter.alphaIsTransparency = true;
            texImporter.filterMode          = FilterMode.Bilinear;
            texImporter.wrapMode            = TextureWrapMode.Clamp;
            texImporter.anisoLevel          = 1;
            texImporter.SetPlatformTextureSettings("iPhone", maxTextureSize, TextureImporterFormat.PVRTC_RGBA4);
            texImporter.SetPlatformTextureSettings("Android", maxTextureSize, TextureImporterFormat.PVRTC_RGBA4);
            AssetDatabase.ImportAsset(newTex, ImportAssetOptions.ForceUpdate);
        }

        UpdateAtlasSpriteData(ref newAtlas, ref oldSpriteData);

#if RSATLASHELPER_DEBUG
        DebugAtlasSpriteData(ref newAtlas);
#endif

        newAtlas.MarkAsChanged();
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        return(newAtlas);
    }
Exemplo n.º 14
0
    void OnInspectorUpdate()
    {
        bool refresh = false;

        switch (retinaProState.state)
        {
        default:
        case retinaProState.rpState.kWaiting:
            break;

        case retinaProState.rpState.kGen:
        {
            deviceIndex    = 0;
            fileIndex      = 0;
            progressPeriod = 0.0f;
            progressString = "Atlas " + genAtlasItem.atlasName;

#if RETINAPRO_DEBUGLOG
            Debug.Log(progressString);
#endif

            if (genAtlasItem.isFont)
            {
                retinaProState.state = retinaProState.rpState.kFont;
            }
            else
            {
                // create atlas that will be used as the reference for the device specific atlas
                UIAtlas atlasRef = retinaProNGTools.createAtlas(genAtlasItem.atlasName, null, out oldSpriteData);
                oldSpriteData = null;
                if (atlasRef == null)
                {
                    Debug.LogWarning("Could not create atlas reference for " + genAtlasItem.atlasName);
                    retinaProState.state = retinaProState.rpState.kDone;
                    break;
                }

                retinaProParent parent = atlasRef.gameObject.GetComponent <retinaProParent>();
                if (parent == null)
                {
                    atlasRef.gameObject.AddComponent <retinaProParent>();
                }

                EditorUtility.SetDirty(atlasRef.gameObject);
                retinaProState.state = retinaProState.rpState.kAtlas;
            }

            break;
        }


        case retinaProState.rpState.kAtlas: {
            retinaProDevice deviceItem = retinaProDataSerialize.sharedInstance.deviceList[deviceIndex];
            progressString       = "Atlas " + genAtlasItem.atlasName + " / " + deviceItem.name + " - Processing images";
            retinaProState.state = retinaProState.rpState.kAtlasProcess;
            break;
        }


        case retinaProState.rpState.kAtlasProcess: {
            retinaProDevice deviceItem = retinaProDataSerialize.sharedInstance.deviceList[deviceIndex];

#if RETINAPRO_DEBUGLOG
            Debug.Log("addNewAtlas; " + genAtlasItem.atlasName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
#endif
            // gather textures for this atlas / device
            DirectoryInfo dinfo = new DirectoryInfo(retinaProFileLock.baseDataPath + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName);
            if (dinfo == null || !dinfo.Exists)
            {
                Debug.LogWarning("Folder does not exist; " + genAtlasItem.atlasName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
            }
            else
            {
                List <FileInfo> fis;
                retinaProConfig.getValidArtFiles(dinfo, out fis);

                if (fis != null && fis.Count > 0)
                {
                    genAtlas = retinaProNGTools.createAtlas(genAtlasItem.atlasName, deviceItem.name, out oldSpriteData);
                    if (genAtlas == null)
                    {
                        Debug.LogWarning("Could not create atlas for " + genAtlasItem.atlasName + ", device = " + deviceItem.name);
                        retinaProState.state = retinaProState.rpState.kDone;
                        break;
                    }

                    NGUISettings.atlas         = genAtlas;
                    NGUISettings.atlasPadding  = genAtlasItem.atlasPadding;
                    NGUISettings.atlasTrimming = false;
                    NGUISettings.allow4096     = true;
                    NGUISettings.fontTexture   = null;
                    NGUISettings.unityPacking  = true;

                    genAtlas.pixelSize = deviceItem.pixelSize;
                    EditorUtility.SetDirty(genAtlas.gameObject);

                    // add all art files into the atlas (one-pass)
                    List <Texture> textures = new List <Texture>();

                    foreach (FileInfo fi in fis)
                    {
                        // check to see if this file has a corresponding .txt file (i.e. it's a font)
                        bool isFont = false;
                        {
                            string fontName = Path.GetFileNameWithoutExtension(fi.Name);
                            if (dinfo != null && dinfo.Exists)
                            {
                                FileInfo [] fontTextFile = dinfo.GetFiles(fontName + ".txt");
                                if (fontTextFile != null && fontTextFile.Length == 1)
                                {
                                    isFont = true;
                                }
                            }
                        }

                        if (isFont)
                        {
                            progressString = "Atlas " + genAtlasItem.atlasName + " / " + deviceItem.name + " - Fonts in a sprite atlas are not supported!";
                            string fontName = Path.GetFileNameWithoutExtension(fi.Name);
                            Debug.LogWarning("Fonts (" + fontName + ") in a sprite atlas is not supported. Use a font atlas instead, see the example scene.");
                        }
                        else
                        {
                            {
                                string textureName = "Assets" + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName + "/" + fi.Name;

                                // source texture
                                Texture2D tex = AssetDatabase.LoadAssetAtPath(textureName, typeof(Texture2D)) as Texture2D;
                                if (retinaProDataSerialize.sharedInstance.getUtilityRefreshSourceTextures())                                            // refresh importer settings on source texture?
                                // update texture importer settings on source artwork
                                // this ensures that we don't bring in assets into the atlas that are too small (for their given size)
                                {
                                    TextureImporter tImporter = AssetImporter.GetAtPath(textureName) as TextureImporter;
                                    if (tImporter != null)
                                    {
                                        tImporter.textureType         = TextureImporterType.Advanced;
                                        tImporter.normalmap           = false;
                                        tImporter.linearTexture       = true;
                                        tImporter.alphaIsTransparency = true;
                                        tImporter.convertToNormalmap  = false;
                                        tImporter.grayscaleToAlpha    = false;
                                        tImporter.lightmap            = false;
                                        tImporter.npotScale           = TextureImporterNPOTScale.None;
                                        tImporter.filterMode          = FilterMode.Point;
                                        tImporter.maxTextureSize      = 4096;
                                        tImporter.mipmapEnabled       = false;
                                        tImporter.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
                                        AssetDatabase.ImportAsset(textureName, ImportAssetOptions.ForceUpdate);
                                    }
                                }

                                tex.filterMode = genAtlasItem.atlasFilterMode;
                                tex.wrapMode   = TextureWrapMode.Clamp;
                                textures.Add(tex);

#if RETINAPRO_DEBUGLOG
                                Debug.Log("- added tex: " + textureName);
#endif
                            }
                        }
                    }

                    List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures);
                    UIAtlasMaker.ExtractSprites(genAtlas, sprites);
                    UIAtlasMaker.UpdateAtlas(genAtlas, sprites);
                    AssetDatabase.SaveAssets();

                    // set texture filter mode
                    {
                        string          newTex    = "Assets" + retinaProConfig.atlasResourceFolder + deviceItem.name + "/" + genAtlasItem.atlasName + "~" + deviceItem.name + ".png";
                        TextureImporter tImporter = AssetImporter.GetAtPath(newTex) as TextureImporter;

                        if (tImporter != null)
                        {
                            tImporter.filterMode    = genAtlasItem.atlasFilterMode;
                            tImporter.textureFormat = genAtlasItem.atlasTextureFormat;
                            AssetDatabase.ImportAsset(newTex, ImportAssetOptions.ForceUpdate);
                        }
                    }

                    // restore the sprite data within the atlas
                    // update the new atlas with the old sprite data
                    retinaProNGTools.updateAtlasSpriteData(ref genAtlas, ref oldSpriteData);
#if RETINAPRO_DEBUGLOG
                    retinaProNGTools.debugAtlasSpriteData(ref genAtlas);
#endif

                    genAtlas.MarkAsChanged();
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();


                    // continue with next device
                    deviceIndex++;
                    if (deviceIndex >= retinaProDataSerialize.sharedInstance.deviceList.Count)
                    {
                        retinaProState.state = retinaProState.rpState.kDone;
                        break;
                    }
                    else
                    {
                        retinaProState.state = retinaProState.rpState.kAtlas;
                    }

                    progressPortion = 0.0f;
                    break;
                }
            }
            break;
        }

        case retinaProState.rpState.kFont:
        {
            retinaProDevice deviceItem = retinaProDataSerialize.sharedInstance.deviceList[deviceIndex];

            DirectoryInfo dinfo = new DirectoryInfo(retinaProFileLock.baseDataPath + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName);
            if (dinfo == null || !dinfo.Exists)
            {
                Debug.LogWarning("Folder does not exist; " + genAtlasItem.atlasName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
                retinaProState.state = retinaProState.rpState.kDone;
                break;
            }

            FileInfo [] fis    = dinfo.GetFiles("*.png");
            FileInfo [] fisTxt = dinfo.GetFiles("*.txt");

            if (fis == null || fis.Length != 1 || fisTxt == null || fisTxt.Length != 1)
            {
                Debug.LogWarning("Font atlases should contain two files; thefont.png / thefont.txt");
                fileIndex            = fis.Length;
                retinaProState.state = retinaProState.rpState.kDone;
                break;
            }

            FileInfo fi = fis[fileIndex];

            {
                string fontName = Path.GetFileNameWithoutExtension(fi.Name);
                progressString = "Atlas " + genAtlasItem.atlasName + " / " + deviceItem.name + " / " + fontName;

#if RETINAPRO_DEBUGLOG
                Debug.Log("addNewFont; " + fontName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
#endif

                UIFont font = retinaProNGTools.createFont(genAtlasItem.atlasName, fontName, deviceItem.name);
                //font.pixelSize = deviceItem.pixelSize;
                EditorUtility.SetDirty(font.gameObject);

                // create the reference font version
                UIFont fontRef = retinaProNGTools.createFont(genAtlasItem.atlasName, fontName, null);
                fontRef.replacement = font;
                //fontRef.pixelSize = deviceItem.pixelSize;

                retinaProParent parent = fontRef.gameObject.GetComponent <retinaProParent>();
                if (parent == null)
                {
                    fontRef.gameObject.AddComponent <retinaProParent>();
                }

                EditorUtility.SetDirty(fontRef.gameObject);
            }

            // set texture filter mode
            {
                string          newTex    = "Assets" + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName + "/" + fis[0].Name;
                TextureImporter tImporter = AssetImporter.GetAtPath(newTex) as TextureImporter;

                if (tImporter != null)
                {
                    tImporter.filterMode    = genAtlasItem.atlasFilterMode;
                    tImporter.textureFormat = genAtlasItem.atlasTextureFormat;
                    AssetDatabase.ImportAsset(newTex, ImportAssetOptions.ForceUpdate);
                }
            }


            fileIndex++;
            if (fileIndex >= fis.Length)
            {
                fileIndex = 0;

                deviceIndex++;
                if (deviceIndex >= retinaProDataSerialize.sharedInstance.deviceList.Count)
                {
                    fileIndex            = fis.Length;
                    retinaProState.state = retinaProState.rpState.kDone;
                }
            }
            progressPortion = (((float)(fileIndex + 1)) / ((float)fis.Length));
            progressPortion = Mathf.Clamp01(progressPortion);
            break;
        }

        case retinaProState.rpState.kDone:
        {
            EditorUtility.ClearProgressBar();
            refresh = true;
            retinaProState.state = retinaProState.rpState.kWaiting;
            Repaint();
            break;
        }
        }

        if (refresh)
        {
#if RETINAPRO_DEBUGLOG
            Debug.Log("refresh called");
#endif
            int             idx = retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx();
            retinaProDevice di  = retinaProDataSerialize.sharedInstance.deviceList[idx];
            if (di.isDeviceValid())
            {
                retinaProNGTools.refreshReferencesForDevice(di, retinaProDataSerialize.sharedInstance.getPreviewScreenIdx(), retinaProDataSerialize.sharedInstance.getPreviewGameViewIdx());
                retinaProNGTools.refresh();
            }
        }

        if (retinaProState.state != retinaProState.rpState.kWaiting)
        {
            Repaint();
        }
    }
Exemplo n.º 15
0
    /// <summary>
    /// 传进文件夹,将本文件夹下的所有文件打成以本文件夹为名的Atlas
    /// </summary>
    /// <param name="dir"></param>
    private static void GetNewAtlas(DirectoryInfo dir)
    {
        FileInfo[] infos = dir.GetFiles();

        bool haveInfo = false;

        List <string> list = new List <string>();

        foreach (var item in infos)
        {
            if (item.FullName.Contains(".png") && !item.FullName.Contains(".png.meta"))
            {
                haveInfo = true;
                string str = "";
                str = item.FullName;
                str = str.Replace(@"\", @"/");
                str = str.Replace(Application.dataPath, "Assets");

                list.Add(str);
            }
        }

        if (!haveInfo)
        {
            DirectoryInfo[] infos1 = dir.GetDirectories();
            for (int i = 0; i < infos1.Length; i++)
            {
                GetNewAtlas(infos1[i]);
            }
            return;
        }


        List <Texture> texTures = new List <Texture>();

        for (int i = 0; i < list.Count; i++)
        {
            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(list[i], typeof(Texture));
            FileImporterSetting.SetFileImporterSetting(EFileImporterSettingType.TextureForRGBA32, 1024, AssetDatabase.GetAssetPath(obj));
            texTures.Add(obj as Texture);
            //Debug.LogError("Texture:" +i+":"+ list[i]);
        }

        string dirPath = dir.FullName.Replace(@"\", @"/");

        dirPath = dirPath.Replace(Application.dataPath + "/BreakAtlasPic/", "Assets/TGameResources/");


        string[] dirPaths = dirPath.Split('/');

        dirPath = "Assets";
        for (int i = 1; i < dirPaths.Length - 1; i++)
        {
            dirPath += "/";
            dirPath += dirPaths[i];
        }


        //Debug.LogError("dirPath:" + dirPath);
        //return;
        //Debug.LogError("dirPath:" + dirPath);


        UnityEngine.Object obj1 = AssetDatabase.LoadAssetAtPath(dirPath + "/" + dirPaths[dirPaths.Length - 1] + ".prefab", typeof(UIAtlas));
        ua = obj1 as UIAtlas;

        UIAtlasUtil.UncompressAtlas(dirPath + "/" + dirPaths[dirPaths.Length - 1] + ".prefab");

        FileImporterSetting.SetFileImporterSetting(EFileImporterSettingType.TextureForRGBA32, 1024, AssetDatabase.GetAssetPath(ua.spriteMaterial.mainTexture));
        //(ua.spriteMaterial.mainTexture);


        spriteList = ua.spriteList;
        List <UIAtlasMaker.SpriteEntry> ui = UIAtlasMaker.CreateSprites(texTures);

        for (int i = 0; i < ui.Count; i++)
        {
            for (int j = 0; j < spriteList.Count; j++)
            {
                if (ui[i].name == spriteList[j].name)
                {
                    ui[i].borderLeft   = spriteList[j].borderLeft;
                    ui[i].borderRight  = spriteList[j].borderRight;
                    ui[i].borderBottom = spriteList[j].borderBottom;
                    ui[i].borderTop    = spriteList[j].borderTop;
                }
            }
        }
        //ua.UpdateAtlas();
        UIAtlasMaker.UpdateAtlas(ua, ui);

        UIAtlasUtil.CompressAtlas(dirPath + "/" + dirPaths[dirPaths.Length - 1] + ".prefab");


        //UnityEngine.Object obj1 = AssetDatabase.LoadAssetAtPath("Assets/zcyAtlas/LobbySys_Atlas1.prefab", typeof(UIAtlas));
        //ua = obj1 as UIAtlas;
        AssetDatabase.Refresh();
        Debug.Log("---------图集打包完毕-----------");
    }