/// <summary>
        ///
        /// </summary>
        /// <param name="swfInfoAsset"></param>
        /// <param name="swfUri"></param>
        /// <param name="useAssetBundle"></param>
        /// <param name="texSize"></param>
        /// <returns></returns>
        private SwfAssetContext _loadFromTextAsset(TextAsset swfInfoAsset, string swfUri, IAssetBundle useAssetBundle, Vector2 texSize)
        {
            ByteArray       b       = new ByteArray(swfInfoAsset.bytes);
            MovieClipReader reader2 = new MovieClipReader();
            SwfAssetContext context = null;

            try
            {
                context = reader2.readSwfAssetContext(b, texSize);
            }
            catch (EndOfStreamException)
            {
                Debug.LogError("MovieClip() corrupt swf '" + swfUri + "'");
                return(null);
            }
            catch (Exception exception)
            {
                Debug.LogError("MovieClip() corrupt swf '" + swfUri + "', " + exception.Message);
                return(null);
            }
            if (context == null)
            {
                Debug.LogError("MovieClip() Invalid swf '" + swfUri + "'");
                return(null);
            }
            context.swfPrefix    = swfUri;
            contextCache[swfUri] = context;
            return(context);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="swfUri"></param>
        /// <param name="useAssetBundle"></param>
        /// <returns></returns>
        internal SwfAssetContext loadSWF(string swfUri, IAssetBundle useAssetBundle)
        {
            if (swfUri.EndsWith(".swf"))
            {
                swfUri = swfUri.Substring(0, swfUri.IndexOf(".swf"));
            }
            if (contextCache.ContainsKey(swfUri))
            {
                return(contextCache[swfUri]);
            }
            string uri = swfUri;

            if (useAssetBundle == null)
            {
                return(null);
            }
            TextAsset swfInfoAsset = useAssetBundle.Load <TextAsset>(uri);

            if (swfInfoAsset == null)
            {
                Debug.LogError("MovieClip() Invalid asset url '" + swfUri + "' actual url loaded '" + uri + "'");
                return(null);
            }
            string  texuri  = swfUri + "_tex";
            Texture texture = useAssetBundle.Load <Texture>(texuri);

            if (texture == null)
            {
                Debug.Log(string.Concat("Failed to load texture: ", texuri, " from bundle: ", useAssetBundle));
                return(null);
            }
            Material material = new Material(baseBitmapShader)
            {
                color = Color.white,
                name  = texuri
            };

            texture.name         = texuri;
            material.mainTexture = texture;

            SwfAssetContext context = _loadFromTextAsset(swfInfoAsset, uri, useAssetBundle, new Vector2(texture.width, texture.height));

            if (context != null)
            {
                context.texture  = texture;
                context.material = material;
            }

            useAssetBundle.Unload(uri);
            return(context);
        }
Beispiel #3
0
        /// <summary>
        /// The read swf asset context method
        /// </summary>
        /// <param name="b"></param>
        /// <param name="texSize"></param>
        /// <returns></returns>
        public SwfAssetContext readSwfAssetContext(ByteArray b, Vector2 texSize)
        {
            SwfAssetContext context = new SwfAssetContext();
            //read version number
            int num = b.ReadByte();

            //read bitmap clip asset info list
            int bitmapSize = b.ReadShort();

            for (int i = 0; i < bitmapSize; ++i)
            {
                BitmapAssetInfo info = new BitmapAssetInfo();
                //int cip = b.ReadShort();
                info.srcRect = new Rect()
                {
                    x      = b.ReadShort(),
                    y      = b.ReadShort(),
                    width  = b.ReadShort(),
                    height = b.ReadShort()
                };
                info.uvRect = new Rect()
                {
                    x      = info.srcRect.x / texSize.x,
                    y      = info.srcRect.y / texSize.y,
                    width  = info.srcRect.width / texSize.x,
                    height = info.srcRect.height / texSize.y,
                };
                context.bitmaps.Add(info);
            }

            //read movie clip asset info list
            int movieClipsLen = b.ReadShort();

            for (int i = 0; i < movieClipsLen; i++)
            {
                string             str  = b.ReadUTF();
                MovieClipAssetInfo info = this.readMovieClipAssetInfo(b);
                if (info != null)
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        info.className = str;
                    }
                    info.assetContext = context;
                    context.exports.Add(info);
                }
            }
            return(context);
        }