コード例 #1
0
        public static Texture2D CombineTextures(Texture2D aBaseTexture, Texture2D aToCopyTexture)
        {
            GravityTurner.Log("CombineTextures");
            Texture2D baseTexture = ReadTexture(aBaseTexture);

            if (baseTexture == null)
            {
                GravityTurner.Log("read texture failed");
                return(aBaseTexture);
            }

            int       aWidth         = aBaseTexture.width;
            int       aHeight        = aBaseTexture.height;
            Texture2D aReturnTexture = new Texture2D(aWidth, aHeight, TextureFormat.RGBA32, false);

            GravityTurner.Log("create arrays {0}:{1} {2}", aWidth.ToString(), aHeight.ToString(), aToCopyTexture.width);
            Color[] aBaseTexturePixels = baseTexture.GetPixels();
            Color[] aCopyTexturePixels = aToCopyTexture.GetPixels();
            Color[] aColorList         = new Color[aBaseTexturePixels.Length];
            int     aPixelLength       = aBaseTexturePixels.Length;

            for (int p = 0; p < aPixelLength; p++)
            {
                aColorList[p] = Color.Lerp(aBaseTexturePixels[p], aCopyTexturePixels[p], aCopyTexturePixels[p].a);
            }

            GravityTurner.Log("SetPixels");
            aReturnTexture.SetPixels(aColorList);
            aReturnTexture.Apply(false);

            return(aReturnTexture);
        }
コード例 #2
0
        public static Texture2D ReadTexture(Texture2D texture)
        {
            GravityTurner.Log("ReadTexture");
            // Create a temporary RenderTexture of the same size as the texture
            RenderTexture tmp = RenderTexture.GetTemporary(
                texture.width,
                texture.height,
                0,
                RenderTextureFormat.Default,
                RenderTextureReadWrite.Linear);

            GravityTurner.Log("  Blit");
            // Blit the pixels on texture to the RenderTexture
            Graphics.Blit(texture, tmp);
            // Backup the currently set RenderTexture
            RenderTexture previous = RenderTexture.active;

            // Set the current RenderTexture to the temporary one we created
            RenderTexture.active = tmp;
            // Create a new readable Texture2D to copy the pixels to it
            Texture2D myTexture2D = new Texture2D(texture.width, texture.width);

            // Copy the pixels from the RenderTexture to the new Texture
            GravityTurner.Log("  Readpixels");
            myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
            myTexture2D.Apply();
            // Reset the active RenderTexture
            RenderTexture.active = previous;
            // Release the temporary RenderTexture
            GravityTurner.Log("  Release");
            RenderTexture.ReleaseTemporary(tmp);

            // "myTexture2D" now has the same pixels from "texture" and it's readable.
            return(myTexture2D);
        }
コード例 #3
0
ファイル: BaseWindow.cs プロジェクト: Mecripp/GravityTurn
 public void Load()
 {
     try
     {
         ConfigNode root = ConfigNode.Load(filename);
         if (root != null)
         {
             ConfigNode.LoadObjectFromConfig(this, root);
         }
     }
     catch (Exception ex)
     {
         GravityTurner.Log("Window Load error {0}", ex.ToString());
     }
 }