Пример #1
0
 void OnEnable()
 {
     mAtlas = (GiraffeAtlas)this.target;
     mAtlas.RefreshSprites();
     TryResolveEditorData(mAtlas);
     mMode = 0;
 }
Пример #2
0
    public void Begin(int nbQuads)
    {
        if (mLayer == null)
        {
            if (mAtlas == null)
            {
                throw new Exception("An atlas must be given to a GiraffeLayer before drawing to it");
            }

            mLayer = new Layer(mesh, mAtlas.material, mScale);
            mAtlas.RefreshSprites();
        }

        mLayer.Begin(nbQuads);
    }
Пример #3
0
    void BuildAtlas()
    {
        mAtlas._importData.atlasOutOfDate = false;

        Texture2D           whiteTex = null;
        GiraffeAtlasBuilder builder  = new GiraffeAtlasBuilder();

        builder.Begin(mAtlas.texture, mAtlas._importData.border, mAtlas._importData.padding);

        if (mAtlas._importData.generateWhiteTexture)
        {
            whiteTex = new Texture2D(kWhiteTexSize, kWhiteTexSize, TextureFormat.ARGB32, false);

            whiteTex.name = "Giraffe/White";
            Color32[] col = new Color32[kWhiteTexSize * kWhiteTexSize];
            for (int i = 0; i < kWhiteTexSize * kWhiteTexSize; i++)
            {
                col[i] = new Color32(255, 255, 255, 255);
            }
            whiteTex.SetPixels32(col);
            whiteTex.Apply(true, false);

            builder.Add(whiteTex.name, whiteTex);
        }

        foreach (var p in mAtlas._importData.parts)
        {
            switch (p.type)
            {
            case GiraffeAtlasImportDataType.None:
                break;

            case GiraffeAtlasImportDataType.Texture2D:
            {
                if (p.textureAsset != null)
                {
                    builder.Add(p.textureAsset.name, p.textureAsset);
                }
            }
            break;

            case GiraffeAtlasImportDataType.TileSheetSquare:
            case GiraffeAtlasImportDataType.TilesheetRectangular:
            {
                if (p.textureAsset != null)
                {
                    var input = builder.Add(p.textureAsset.name, p.textureAsset, false);
                    int x     = 0;
                    int y     = p.textureAsset.height - p.height;
                    for (int i = 0; i < p.count; i++)
                    {
                        input.Add(x, y, p.width, p.height);
                        x += p.width;
                        if (x >= p.textureAsset.width)
                        {
                            x  = 0;
                            y -= p.height;
                        }
                    }
                }
            }
            break;
            }
        }

        var sprites = builder.End();

        if (whiteTex != null)
        {
            Object.DestroyImmediate(whiteTex);
        }

        mAtlas.ClearSprites();
        foreach (var s in sprites)
        {
            var sprite = new GiraffeSprite();
            sprite.name          = s.name;
            sprite.left          = s.x;
            sprite.top           = s.y;
            sprite.width         = s.w;
            sprite.height        = s.h;
            sprite.refreshNeeded = true;
            mAtlas.AddSprite(sprite);
        }

        EditorUtility.SetDirty(mAtlas._importData);
        EditorUtility.SetDirty(mAtlas);

        mAtlas.RefreshSprites();

        AssetDatabase.Refresh();
    }