public IEnumerator Save(EdgeTexture EdgeTex)
    {
        yield return(new WaitForEndOfFrame());

        var texRate = (float)EdgeTex.Texture.width / EdgeTex.Texture.height;
        // スクショは画面全体ではなく表示されている書き込み用キャンバスと同サイズにする
        var height     = Screen.height;
        var width      = Mathf.RoundToInt(Screen.height * texRate * EdgeTexture.RESOLUTION_RATE);
        var canvasRate = 1820f / 1920f;
        var left       = (Screen.width * canvasRate - width) * 0.5f;

        // 横長の画像の場合
        var bottom = 0f;

        if (width > Screen.width)
        {
            // 画面幅以上のwidthを画面幅に合わせる
            var applyRate = Screen.width * canvasRate / width;
            width  = Mathf.RoundToInt(applyRate * width);
            height = Mathf.RoundToInt(applyRate * height);
            left   = 0;
            bottom = EdgeTex.RectTransformBottom * 0.5f;
        }

        var tex = new Texture2D(width, height, TextureFormat.RGB24, false);

        tex.name = EdgeTex.Texture.name;
        tex.ReadPixels(new Rect(left, bottom, width, height), 0, 0);
        tex.Apply();

        TextureScale.Point(tex, Mathf.RoundToInt(Screen.height * texRate), height);
        yield return(EdgeTex.StartCoroutine(WriteFile(tex)));
    }
Exemple #2
0
        protected override void HandleDraw(SpriteBatch spriteBatch, Rectangle scissorRectangle, DrawSpecifics drawSpecifics)
        {
            //Draw tiles
            spriteBatch.End();
            spriteBatch.Begin(samplerState: SamplerState.PointClamp);
            for (int i = 0; i < tileWidth; i++)
            {
                for (int j = 0; j < tileHeight; j++)
                {
                    bool        isEdge      = false;
                    EdgeTexture edgeTexture = EdgeTexture.DownLeft;
                    if (i == 0)
                    {
                        isEdge = true;
                        if (j == 0)
                        {
                            edgeTexture = EdgeTexture.UpLeft;
                        }
                        else if (j == tileHeight - 1)
                        {
                            edgeTexture = EdgeTexture.DownLeft;
                        }
                        else
                        {
                            edgeTexture = EdgeTexture.LeftMiddle;
                        }
                    }
                    else if (i == tileWidth - 1)
                    {
                        isEdge = true;
                        if (j == 0)
                        {
                            edgeTexture = EdgeTexture.UpRight;
                        }
                        else if (j == tileHeight - 1)
                        {
                            edgeTexture = EdgeTexture.DownRight;
                        }
                        else
                        {
                            edgeTexture = EdgeTexture.RightMiddle;
                        }
                    }
                    else if (j == 0)
                    {
                        isEdge = true;
                        if (i == 1)
                        {
                            edgeTexture = EdgeTexture.UpTextLeft;
                        }
                        else if (i == tileWidth - 2)
                        {
                            edgeTexture = EdgeTexture.UpTextRight;
                        }
                        else
                        {
                            edgeTexture = EdgeTexture.UpMiddle;
                        }
                    }
                    else if (j == tileHeight - 1)
                    {
                        isEdge = true;
                        if (i == 1)
                        {
                            edgeTexture = EdgeTexture.DownTextLeft;
                        }
                        else if (i == tileWidth - 2)
                        {
                            edgeTexture = EdgeTexture.DownTextRight;
                        }
                        else
                        {
                            edgeTexture = EdgeTexture.DownMiddle;
                        }
                    }

                    if (isEdge)
                    {
                        spriteBatch.Draw(edgeTextures[(int)edgeTexture], new Vector2(xOffset + (tileSize * (i + .5F)), yOffset + (tileSize * (j + .5F))), null, Color.White, 0, new Vector2(edgeTextures[(int)edgeTexture].Width / 2, edgeTextures[(int)edgeTexture].Height / 2), (float)tileSize / edgeTextures[(int)edgeTexture].Width, SpriteEffects.None, 0);
                    }
                    else
                    {
                        spriteBatch.Draw(inventorySlot, new Vector2(xOffset + (tileSize * (i + .5F)), yOffset + (tileSize * (j + .5F))), null, Color.White, 0, new Vector2(edgeTextures[(int)edgeTexture].Width / 2, edgeTextures[(int)edgeTexture].Height / 2), (float)tileSize / edgeTextures[(int)edgeTexture].Width, SpriteEffects.None, 0);
                    }
                }
            }

            base.HandleDraw(spriteBatch, scissorRectangle, drawSpecifics);
        }