コード例 #1
0
            public IEnumerator LoadBundle()
            {
                yield return(new WaitForEndOfFrame());

                yield return(FileLoader.Instance._loadAssetBundleFromFileAsync(this.m_path));

                this.m_bundle = FileLoader.Instance.loadAssetBundleFromCache(this.m_path, false);
                if (this.OnLoadOver != null && this.OnLoadOver.GetInvocationList().Length > 0)
                {
                    this.OnLoadOver(this.m_bundle.MainAsset5(), this.m_path);
                }
                if (this.OnLoadOverInstantiate != null)
                {
                    foreach (Action <UnityEngine.Object, string> func in this.OnLoadOverInstantiate.GetInvocationList())
                    {
                        UnityEngine.Object obj = null;
                        if (this.m_bundle.MainAsset5() == null)
                        {
                            UnityEngine.Debug.LogError("AssetBundleLoader.LoadBundle: object to instantiate is null, path = " + this.m_path);
                            obj = null;
                        }
                        else
                        {
                            obj = UnityEngine.Object.Instantiate(this.m_bundle.MainAsset5());
                        }
                        yield return(null);

                        func(obj, this.m_path);
                        yield return(null);
                    }
                    FileLoader.UnloadAssetBundle(this.m_path);
                }
                FileLoader.AssetBundleLoader.Loaders.Remove(this.m_path);
                yield break;
            }
コード例 #2
0
        public static T LoadComponentFromFile <T>(string path, bool instantiate) where T : Component
        {
            System.Console.WriteLine(string.Concat(new object[]
            {
                "Static: LoadComponentFromFile<",
                typeof(T).ToString(),
                ">(",
                path,
                ", ",
                instantiate,
                ")"
            }));
            AssetBundle assetBundle = FileLoader.Instance._loadAssetBundleFromFile(path);
            GameObject  gameObject  = null;

            if (assetBundle != null)
            {
                if (instantiate)
                {
                    if (assetBundle.MainAsset5() == null)
                    {
                        UnityEngine.Debug.LogError("FileLoader.LoadComponentFromFile<" + typeof(T).ToString() + ">: object to instantiate is null, path = " + path);
                        gameObject = null;
                    }
                    else
                    {
                        gameObject = (UnityEngine.Object.Instantiate(assetBundle.MainAsset5()) as GameObject);
                    }
                    FileLoader.UnloadAssetBundle(path);
                }
                else
                {
                    gameObject = (assetBundle.MainAsset5() as GameObject);
                }
            }
            T result = (T)((object)null);

            if (gameObject != null)
            {
                result = gameObject.GetComponent <T>();
            }
            return(result);
        }
コード例 #3
0
 private void loadAssetBundleFromFileAsync(string path, Action <UnityEngine.Object, string> onLoadOver, bool instantiate)
 {
     if (FileLoader.Instance.m_loadedAssetBundles.ContainsKey(path))
     {
         AssetBundle        bundle = FileLoader.Instance.loadAssetBundleFromCache(path, true);
         UnityEngine.Object arg;
         if (instantiate)
         {
             if (bundle.MainAsset5() == null)
             {
                 UnityEngine.Debug.LogError("FileLoader.loadAssetBundleFromFileAsync: object to instantiate is null, path = " + path);
                 arg = null;
             }
             else
             {
                 arg = UnityEngine.Object.Instantiate(bundle.MainAsset5());
             }
             FileLoader.UnloadAssetBundle(path);
         }
         else
         {
             arg = bundle.MainAsset5();
         }
         onLoadOver(arg, path);
     }
     else if (FileLoader.AssetBundleLoader.Loaders.ContainsKey(path))
     {
         if (instantiate)
         {
             FileLoader.AssetBundleLoader.Loaders[path].OnLoadOverInstantiate += onLoadOver;
         }
         else
         {
             FileLoader.AssetBundleLoader.Loaders[path].OnLoadOver += onLoadOver;
         }
     }
     else
     {
         FileLoader.AssetBundleLoader assetBundleLoader = new FileLoader.AssetBundleLoader(path, onLoadOver, instantiate);
     }
 }
コード例 #4
0
        public static T LoadObjectFromFile <T>(string path, bool instantiate, bool unloadAfterIns = true) where T : UnityEngine.Object
        {
            System.Console.WriteLine(string.Concat(new object[]
            {
                "Static: LoadObjectFromFile<",
                typeof(T).ToString(),
                ">(",
                path,
                ", ",
                instantiate,
                ")"
            }));
            AssetBundle assetBundle = FileLoader.Instance._loadAssetBundleFromFile(path);
            T           result      = (T)((object)null);

            if (assetBundle != null)
            {
                if (instantiate)
                {
                    if (assetBundle.MainAsset5() == null)
                    {
                        UnityEngine.Debug.LogError("FileLoader.LoadObjectFromFile<" + typeof(T).ToString() + ">: object to instantiate is null, path = " + path);
                        result = (T)((object)null);
                    }
                    else
                    {
                        result = (UnityEngine.Object.Instantiate(assetBundle.MainAsset5()) as T);
                    }
                    if (unloadAfterIns)
                    {
                        FileLoader.UnloadAssetBundle(path);
                    }
                }
                else
                {
                    result = (assetBundle.MainAsset5() as T);
                }
            }
            return(result);
        }