Exemplo n.º 1
0
        public static Texture2D ProcessTexture(
            EmbeddedTextureData embeddedTextureData,
            string name,
            ref bool hasAlphaChannel,
            bool isNormalMap = false,
            TextureWrapMode textureWrapMode       = TextureWrapMode.Repeat,
            FilterMode textureFilterMode          = FilterMode.Bilinear,
            TextureCompression textureCompression = TextureCompression.None,
            bool checkAlphaChannel = false,
            bool generateMipMaps   = true
            )
        {
            Texture2D finalTexture2D = null;

            if (embeddedTextureData.DataPointer == IntPtr.Zero || embeddedTextureData.DataLength <= 0)
            {
#if TRILIB_OUTPUT_MESSAGES
                Debug.LogWarningFormat("Texture '{0}' not found", path);
#endif
            }
            else
            {
                Texture2D tempTexture2D;
                if (ApplyTextureData(embeddedTextureData, out tempTexture2D))
                {
                    finalTexture2D = ProcessTextureData(tempTexture2D, name, ref hasAlphaChannel, textureWrapMode, textureFilterMode, textureCompression, isNormalMap, checkAlphaChannel, generateMipMaps);
                }
#if TRILIB_OUTPUT_MESSAGES
                Debug.LogErrorFormat("Unable to load texture '{0}'", path);
#endif
            }
            embeddedTextureData.Dispose();
            return(finalTexture2D);
        }
Exemplo n.º 2
0
        private static bool ApplyTextureData(EmbeddedTextureData embeddedTextureData, out Texture2D outputTexture2D)
        {
            if (embeddedTextureData.Data == null && embeddedTextureData.DataPointer == IntPtr.Zero)
            {
                outputTexture2D = null;
                return(false);
            }
            try
            {
                outputTexture2D = new Texture2D(embeddedTextureData.Width, embeddedTextureData.Height, TextureFormat.RGBA32, false);
                if (embeddedTextureData.DataPointer != IntPtr.Zero)
                {
                    outputTexture2D.LoadRawTextureData(embeddedTextureData.DataPointer, embeddedTextureData.DataLength);
                }
                else
                {
                    outputTexture2D.LoadRawTextureData(embeddedTextureData.Data);
                }
                outputTexture2D.Apply();
                return(true);
            }
#if TRILIB_OUTPUT_MESSAGES
            catch (Exception e)
            {
                outputTexture2D = null;
                Debug.LogError("Invalid embedded texture data" + e);
                return(false);
            }
#else
            catch
            {
                outputTexture2D = null;
                return(false);
            }
#endif
        }