private static List <Sprite> Build(string[] texturePaths, float uvInset = 0, bool square = false, int sizeLimit = 8,
                                           int unitSize = 1, int padding = 0, float ppu = 1, Vector2 pivot = default, bool keepOriginalPivot = false)
        {
            // TODO: Don't use loader, dicer and packer here; create mock atlas textures instead.
            var textureLoader  = new TextureLoader();
            var sourceTextures = texturePaths.Select(textureLoader.Load);
            var dicer          = new TextureDicer(unitSize, padding);
            var dicedTextures  = sourceTextures.Select(dicer.Dice);
            var serializer     = new MockTextureSerializer();
            var packer         = new TexturePacker(serializer, uvInset, square, sizeLimit, unitSize, padding);
            var atlasTextures  = packer.Pack(dicedTextures);
            var builder        = new SpriteBuilder(ppu, pivot, keepOriginalPivot);
            var sprites        = new List <Sprite>();

            foreach (var atlasTexture in atlasTextures)
            {
                foreach (var dicedTexture in atlasTexture.DicedTextures)
                {
                    sprites.Add(builder.Build(atlasTexture, dicedTexture));
                }
            }
            return(sprites);
        }
    public void Voxelate()
    {
        if (m_pixels3DContainer == null) {
            m_spriteRenderer = GetComponent<SpriteRenderer> ();
            m_spriteBuilder = GetComponent<SpriteBuilder> ();
            m_spriteBuilder.Build ();
            var pixels = m_spriteBuilder.ToPixels ();
            m_spriteRenderer.enabled = false;

            var localScale = transform.localScale;
            var tempScale = new Vector3 (Scale.x * localScale.x, Scale.y * localScale.y, Scale.z * localScale.z);
            var rect = m_spriteBuilder.Sprite.rect;
            var halfWidth = (rect.width / 2) * tempScale.x;
            var halfHeight = (rect.height / 2) * tempScale.y;
            m_pixels3DContainer = new GameObject ("Pixels3DContainer");

            if (KeepContainerParent) {
                m_pixels3DContainer.transform.parent = transform;
            }

            foreach (var p in pixels) {
                if (p.Color.a >= MinAlphaToVoxel) {
                    var pixel3D = Instantiate (Pixel3DPrefab, new Vector3 (
                        transform.position.x + p.X * tempScale.x - halfWidth,
                        transform.position.y + p.Y * tempScale.y - halfHeight,
                        0)
                        , Quaternion.identity) as GameObject;

                    var luminance = 0.2126f * p.Color.r + 0.7152f * p.Color.g + 0.0722f * p.Color.b;
                    pixel3D.transform.localScale = new Vector3(tempScale.x, tempScale.y, tempScale.z + luminance * ZScaleByColorLuminance);
                    var cubeRenderer = pixel3D.GetComponent<MeshRenderer> ();
                    cubeRenderer.material.color = p.Color;
                    pixel3D.transform.parent = m_pixels3DContainer.transform;
                }
            }
        }
    }
Example #3
0
    void Start()
    {
        m_spriteBuilder = GetComponentInChildren<SpriteBuilder> ();
        m_spriteBuilder.Build ();

        m_spriteDestruction = GetComponentInChildren<SpriteDestruction> ();
        m_collider = GetComponent<BoxCollider2D> ();

        m_audioSource = GetComponent<AudioSource> ();
        m_lensFlare = GetComponent<LensFlare> ();
        m_trail = GetComponentInChildren<TrailRenderer> ();

        StartCoroutine (Deploy ());
    }