Exemple #1
0
        public override void LoadAsync()
        {
            State = ResState.Loading;

            mResLoader.LoadAsync <AssetBundle>(mOwnerBundleName, ownerBundle =>
            {
                if (ResMgr.IsSimulationModeLogic)
                {
#if UNITY_EDITOR
                    var assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(mOwnerBundleName, Name);
                    Asset          = UnityEditor.AssetDatabase.LoadAssetAtPath <Object>(assetPaths[0]);
                    State          = ResState.Loaded;
#endif
                }
                else
                {
                    var assetBundleRequest = ownerBundle.LoadAssetAsync(Name);

                    assetBundleRequest.completed += operation =>
                    {
                        Asset = assetBundleRequest.asset;

                        State = ResState.Loaded;
                    };
                }
            });
        }
Exemple #2
0
        private void LoadDependencyBundlesAsync(Action onAllLoaded)
        {
            var dependencyBundleNames = ResData.Instance.GetDirectDependencies(Name);

            var loadedCount = 0;

            if (dependencyBundleNames.Length == 0)
            {
                onAllLoaded();
            }

            foreach (var dependencyBundleName in dependencyBundleNames)
            {
                mResLoader.LoadAsync <AssetBundle>(dependencyBundleName,
                                                   dependBundle =>
                {
                    loadedCount++;

                    if (loadedCount == dependencyBundleNames.Length)
                    {
                        onAllLoaded();
                    }
                });
            }
        }
Exemple #3
0
        public void LoadABSceneAsync(string sceneName, Action <string, bool> loadCallback = null, LoadSceneMode mode = LoadSceneMode.Single)
        {
            ResLoader nextLoader = ResLoader.Allocate();

            //可以起到缓存已经加载的资源的作用,防止释放后又加载的重复动作
            if (!AddSceneAB2Loader(sceneName, nextLoader))
            {
                if (loadCallback != null)
                {
                    loadCallback(sceneName, false);
                }
                return;
            }

            if (m_CurrentLoader != null)
            {
                m_CurrentLoader.ReleaseAllRes();
                m_CurrentLoader.Recycle2Cache();
                m_CurrentLoader = null;
            }

            m_CurrentLoader = nextLoader;

            m_CurrentLoader.LoadAsync(() =>
            {
                StartCoroutine(LoadSceneAsync(sceneName, loadCallback, mode, true));
            });
        }
        public void LoadTexture(string path)
        {
            if (m_RawImage == null)
            {
                return;
            }

            m_RawImage.texture = null;
            if (m_AutoHide)
            {
                m_RawImage.enabled = false;
            }
            if (m_ResLoader != null)
            {
                m_ResLoader.ReleaseAllRes();
            }

            m_TexturePath = path;

            if (string.IsNullOrEmpty(m_TexturePath))
            {
                return;
            }

            if (m_ResLoader == null)
            {
                m_ResLoader = new ResLoader();
            }

            m_ResLoader.Add2Load(m_TexturePath, OnResLoadFinish);
            m_ResLoader.LoadAsync();
        }
Exemple #5
0
        private IEnumerator Start()
        {
            yield return(new WaitForSeconds(2.0f));

            mResLoader.LoadAsync <AudioClip>("resources://coin", coinClip =>
            {
                Debug.Log(coinClip.name);

                Debug.Log(Time.time);
            });

            Debug.Log(Time.time);

            yield return(new WaitForSeconds(2.0f));

            mResLoader.LoadSync <AudioClip>("resources://home");

            yield return(new WaitForSeconds(2.0f));

            mResLoader.LoadSync <GameObject>("resources://HomePanel");

            mResLoader.LoadSync <AudioClip>("resources://Audio/coin");

            yield return(new WaitForSeconds(5.0f));

            mResLoader.ReleaseAll();
        }
        /// <summary>
        /// 添加常驻音频资源,建议尽早添加,不要在用的时候再添加
        /// </summary>
        void AddRetainAudio(string audioName)
        {
            if (mRetainResLoader == null)
            {
                mRetainResLoader = ResLoader.Allocate();
            }
            if (mRetainAudioNames == null)
            {
                mRetainAudioNames = new List <string>();
            }

            if (!mRetainAudioNames.Contains(audioName))
            {
                mRetainAudioNames.Add(audioName);
                mRetainResLoader.Add2Load(audioName);
                mRetainResLoader.LoadAsync();
            }
        }
        public void SetAudio(GameObject root, string name, bool loop)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (mName == name)
            {
                return;
            }

            if (mAudioSource == null)
            {
                mAudioSource = root.AddComponent <AudioSource>();
            }

            //防止卸载后立马加载的情况
            var preLoader = mLoader;

            mLoader = null;

            CleanResources();

            mLoader = ResLoader.Allocate();

            mIsLoop = loop;
            mName   = name;

            mLoader.Add2Load(name, OnResLoadFinish);

            if (preLoader != null)
            {
                preLoader.Recycle2Cache();
                preLoader = null;
            }

            if (mLoader != null)
            {
                mLoader.LoadAsync();
            }
        }