コード例 #1
0
        private static void SetGO(SpriteInfo spriteInfo, GameObject go)
        {
            Transform goTransform = go.transform;
            Vector2   goPos       = PixelToCoord(spriteInfo.Pos);
            Vector2   goSize      = PixelToCoord(spriteInfo.Size);

            goTransform.localScale = new Vector3(goSize.x, goSize.y, 1);
            goTransform.position   = new Vector3(goPos.x + goSize.x / 2, goPos.y + goSize.y / 2, 1);
        }
コード例 #2
0
        public RenderTexture RenderToRT(List <SpriteInfo> spriteInfoList, Vector2Int size, List <Texture2D> texture2DList, List <Sprite> spriteList)
        {
            templateGO.SetActive(true);
            List <GameObject> goList       = new List <GameObject>(spriteInfoList.Count); // todo : can be cached
            List <Material>   materialList = new List <Material>(spriteInfoList.Count);   // todo : cam be cached
            RenderTexture     rt           = new RenderTexture(size.x, size.y, 0, RenderTextureFormat.ARGB32);

            rt.useMipMap = useMiniMap;
            SetCamera(rt);

            for (int i = 0; i < spriteInfoList.Count; ++i)
            {
                SpriteInfo spriteInfo = spriteInfoList[i];
                Texture2D  texture2D  = texture2DList[spriteInfo.ID];
                Material   material   = UnityEngine.Object.Instantiate(templateMaterial);
                material.SetTexture(mainTexPropertyID, texture2D);
                GameObject go = UnityEngine.Object.Instantiate(templateGO);
                go.GetComponent <MeshRenderer>().sharedMaterial = material;
                SetGO(spriteInfo, go);
                materialList.Add(material);
                goList.Add(go);
            }

            camera.Render();
            camera.targetTexture = null;

            foreach (Material material in materialList)
            {
                UnityEngine.Object.Destroy(material);
            }

            foreach (GameObject gameObject in goList)
            {
                UnityEngine.Object.Destroy(gameObject);
            }

            templateGO.SetActive(false);
            return(rt);
        }