Exemple #1
0
    private void ExecuteNextBlock(CommandBuffer commandBuffer, CalcRenderTexSize calcRenderTex)
    {
        int currentIdx = 0;
        int currentNum = 0;

        Rect right = new Rect(0.9f - scaleP * 0.5f, 0.6f - scaleP * 0.5f, scaleP, scaleP);
        Rect left  = new Rect(0.1f - scaleP * 0.5f, right.y, right.width, right.height);

        for (int i = 0; i < tileX * tileY; ++i)
        {
            for (int j = currentIdx; j < textures.Length - 1; ++j)
            {
                if (textures[currentIdx].num <= currentNum)
                {
                    currentNum = 0;
                    ++currentIdx;
                }
            }
            if (currentIdx >= textures.Length)
            {
                currentIdx = textures.Length - 1;
            }
            if (currentIdx > 0)
            {
                AddCommandBuffer(commandBuffer, textures[currentIdx - 1].texture, i, calcRenderTex, left);
            }
            if (currentIdx < textures.Length - 1)
            {
                AddCommandBuffer(commandBuffer, textures[currentIdx + 1].texture, i, calcRenderTex, right);
            }
            currentNum++;
        }
    }
Exemple #2
0
    private void AddCommandBuffer(CommandBuffer commandBuffer, Texture src, int idx, CalcRenderTexSize calcRenderTex, Rect drawRect)
    {
        Vector2 scale  = new Vector2(calcRenderTex.tileSizeX, calcRenderTex.tileSizeY);
        Vector2 offset = new Vector2((idx % tileX) * calcRenderTex.tileSizeX, (idx / tileX) * calcRenderTex.tileSizeY + calcRenderTex.paddingY);

        scale.x  /= (renderTexture.width);
        scale.y  /= (renderTexture.height);
        offset.x /= (renderTexture.width);
        offset.y /= (renderTexture.height);

        // offset
        Matrix4x4 matrix = Matrix4x4.identity;

        var mesh     = CreateQuadMesh(scale, offset, drawRect);
        var material = new Material(Shader.Find("Unlit/Texture"));

        material.mainTexture = src;
        commandBuffer.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
        commandBuffer.DrawMesh(mesh, matrix, material);
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        this.UpdateAnimation();


        CommandBuffer commandBuffer = new CommandBuffer();

        commandBuffer.SetRenderTarget(renderTexture);
        commandBuffer.ClearRenderTarget(true, true, Color.black);

        CalcRenderTexSize calcRenderTex = new CalcRenderTexSize(renderTexture.width, renderTexture.height, tileX, tileY);
        int  currentIdx = 0;
        int  currentNum = 0;
        Rect r          = new Rect(0, 0, 1, 1);

        for (int i = 0; i < tileX * tileY; ++i)
        {
            for (int j = currentIdx; j < textures.Length - 1; ++j)
            {
                if (textures[currentIdx].num <= currentNum)
                {
                    currentNum = 0;
                    ++currentIdx;
                }
            }
            if (currentIdx >= textures.Length)
            {
                currentIdx = textures.Length - 1;
            }
            AddCommandBuffer(commandBuffer, textures[currentIdx].texture, i, calcRenderTex, r);
            currentNum++;
        }
        if (this.scaleP > 0.0f)
        {
            ExecuteNextBlock(commandBuffer, calcRenderTex);
        }

        Graphics.ExecuteCommandBuffer(commandBuffer);
        commandBuffer.Clear();
    }