示例#1
0
        /// <summary>
        /// Decodes the GIF file at the provided filepath into an array to textures.
        /// If framesToRead is smaller than 1 or bigger than the total number of frames in the GIF, the whole file will be read.
        /// Otherwise, only the number of frames determined by framesToRead will be decoded.
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="framesToRead"></param>
        /// <param name="threadPriority"></param>
        /// <param name="completeCallback"></param>
        public static void DecodeGif(string filepath, int framesToRead, System.Threading.ThreadPriority threadPriority, Action <Texture[]> completeCallback)
        {
#if UNITY_EDITOR
            Debug.LogWarning("DecodeGif is not supported in Unity editor. Please test on an iOS or Android device.");
#elif UNITY_IOS
            // Read the GIF partially.
            iOSNativeGif.DecodeGif(curDecodeId++, filepath, framesToRead, threadPriority,
                                   (int taskId, GifMetadata gifMetadata, GifFrameMetadata[] gifFrameMetadata, Color32[][] imageData) =>
            {
                if (completeCallback != null)
                {
                    completeCallback(ToTextureArray(gifMetadata, gifFrameMetadata, imageData));
                }
            });
#elif UNITY_ANDROID
            // Read the GIF partially.
            AndroidNativeGif.DecodeGif(curDecodeId++, filepath, framesToRead, threadPriority,
                                       (int taskId, GifMetadata gifMetadata, GifFrameMetadata[] gifFrameMetadata, Color32[][] imageData) =>
            {
                if (completeCallback != null)
                {
                    completeCallback(ToTextureArray(gifMetadata, gifFrameMetadata, imageData));
                }
            });
#endif
        }
示例#2
0
        /// <summary>
        /// Decodes the GIF file at the provided filepath into an <see cref="AnimatedClip"/> object.
        /// If framesToRead is smaller than 1 or bigger than the total number of frames in the GIF, the whole file will be read.
        /// Otherwise, only the number of frames determined by framesToRead will be decoded.
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="framesToRead"></param>
        /// <param name="threadPriority"></param>
        /// <param name="completeCallback"></param>
        public static void DecodeGif(string filepath, int framesToRead, System.Threading.ThreadPriority threadPriority, Action <AnimatedClip> completeCallback)
        {
#if UNITY_EDITOR
            EM_3DI70R_GIF.DecodeRequest request = new EM_3DI70R_GIF.DecodeRequest(filepath)
            {
                frameToRead    = framesToRead,
                threadPriority = threadPriority
            };
            request.Completed += () => {
                if (completeCallback != null)
                {
                    completeCallback(request.AnimatedClip);
                }
            };
            request.Request();
            // Debug.LogWarning("DecodeGif is not supported in Unity editor. Please test on an iOS or Android device.");
#elif UNITY_IOS
            // Read the GIF partially.
            iOSNativeGif.DecodeGif(curDecodeId++, filepath, framesToRead, threadPriority,
                                   (int taskId, GifMetadata gifMetadata, GifFrameMetadata[] gifFrameMetadata, Color32[][] imageData) =>
            {
                if (completeCallback != null)
                {
                    completeCallback(ToAnimatedClip(gifMetadata, gifFrameMetadata, imageData));
                }
            });
#elif UNITY_ANDROID
            // Read the GIF partially.
            AndroidNativeGif.DecodeGif(curDecodeId++, filepath, framesToRead, threadPriority,
                                       (int taskId, GifMetadata gifMetadata, GifFrameMetadata[] gifFrameMetadata, Color32[][] imageData) =>
            {
                if (completeCallback != null)
                {
                    completeCallback(ToAnimatedClip(gifMetadata, gifFrameMetadata, imageData));
                }
            });
#endif
        }