Ejemplo n.º 1
0
        public static object GetAMF(string fullPath, bool deflate = true)
        {
            if (File.Exists(fullPath) == false)
            {
                return(null);
            }
            byte[] bytes;
            using (FileStream fileStream = File.OpenRead(fullPath))
            {
                bytes = new byte[fileStream.Length];
                fileStream.Read(bytes, 0, bytes.Length);
                fileStream.Close();
            }
            if (bytes.Length < 1)
            {
                return(null);
            }

            object result = null;

            if (bytes != null)
            {
                ByteArray bytesArray = new ByteArray(bytes);
                if (deflate)
                {
                    try
                    {
                        bytesArray.Inflate();
                    }
                    catch (Exception)
                    {
                        bytesArray.Position = 0;
                    }
                    if (bytesArray.BytesAvailable > 0)
                    {
                        result = bytesArray.ReadObject();
                    }
                }
                else
                {
                    try
                    {
                        result = bytesArray.ReadObject();
                    }
                    catch (Exception)
                    {
                        bytesArray.Position = 0;
                        bytesArray.Inflate();
                        result = bytesArray.ReadObject();
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static ByteArray getByteArray(string fullPath)
        {
            if (File.Exists(fullPath) == false)
            {
                return(null);
            }

            byte[] bytes;

            using (FileStream fileStream = File.OpenRead(fullPath))
            {
                bytes = new byte[fileStream.Length];
                fileStream.Read(bytes, 0, bytes.Length);
            }

            if (bytes != null)
            {
                ByteArray bytesArray = new ByteArray(bytes);
                try
                {
                    bytesArray.Inflate();
                }
                catch (Exception)
                {
                    bytesArray.Position = 0;
                }

                return(bytesArray);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public override object parser(LoaderXDataType parserType)
        {
            switch (parserType)
            {
            case LoaderXDataType.BYTES:
                _data = www.bytes;
                break;

            case LoaderXDataType.MANIFEST:
                if (assetBundle == null)
                {
                    assetBundle = www.assetBundle;
                }
                if (assetBundle != null)
                {
                    _data = assetBundle.LoadAsset("AssetBundleManifest");
                }
                else
                {
                    _data = null;
                    Debug.Log("No this Manisfest");
                }
                break;

            case LoaderXDataType.TEXTURE:
                texture2D = www.texture;
                if (www.assetBundle != null)
                {
                    www.assetBundle.Unload(false);
                }
                _data = texture2D;
                break;

            case LoaderXDataType.SOUND:
                _data = www.audioClip;
                break;

            case LoaderXDataType.ASSETBUNDLE:
                if (assetBundle == null)
                {
                    assetBundle = www.assetBundle;
                }
                _data = assetBundle;
                break;

            case LoaderXDataType.SPRITE:
                if (assetBundle == null)
                {
                    assetBundle = www.assetBundle;
                }
                if (assetBundle != null)
                {
                    _data = assetBundle.LoadAllAssets <Sprite>();    //assetBundle.LoadAll(typeof (Sprite));
                }
                break;

            case LoaderXDataType.AMF:
                ByteArray bytes = new ByteArray(www.bytes);
                if (bytes.BytesAvailable > 0)
                {
                    try
                    {
                        bytes.Inflate();
                    }
                    catch (Exception)
                    {
                        bytes.Position = 0;
                    }
                    _data = bytes.ReadObject();
                }
                else
                {
                    _data = null;
                }
                break;
            }

            return(_data);
        }
Ejemplo n.º 4
0
        protected virtual object parserData(object data)
        {
            switch (parserType)
            {
            case LoaderXDataType.AMF:

                ByteArray bytes = new ByteArray((byte[])data);
                if (bytes.BytesAvailable > 0)
                {
                    try
                    {
                        data = bytes.ReadObject();
                    }
                    catch (Exception ex)
                    {
                        data = null;
                        try
                        {
                            bytes.Inflate();
                            data = bytes.ReadObject();
                        }
                        catch (Exception)
                        {
                            bytes.Position = 0;
                            DebugX.Log("amfError:" + _url + " \tmsg:" + ex);
                        }
                    }
                }
                else
                {
                    data = null;
                }
                break;

            case LoaderXDataType.MANIFEST:
                AssetBundle         assetBundle = (AssetBundle)data;
                AssetBundleManifest manifest    = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                data = manifest;
                assetBundleManifestDef.manifest = manifest;

//                    string[] allAssetBundles = manifest.GetAllAssetBundles();
//                    foreach (string item in allAssetBundles)
//                    {
//                        Hash128 hash128 = manifest.GetAssetBundleHash(item);
//                        Hash128Link oldLink;
//                        if (allManifesMaping.TryGetValue(hash128, out oldLink))
//                        {
//                            UnityEngine.Debug.Log(item + " routerPath:" + oldLink.manifestDef + " new:" +
//                                                  assetBundleManifestDef);
//                        }
//                        else
//                        {
//                            Hash128Link link = new Hash128Link();
//                            link.hash128 = hash128;
//                            link.key = item;
//                            link.manifestDef = assetBundleManifestDef;
//                            allManifesMaping.Add(hash128, link);
//                        }
//                    }
                break;
            }
            return(data);
        }