| | |
| | | using UnityEngine; |
| | | using TableConfig; |
| | | |
| | | public class AssetPreLoad : SingletonMonobehaviour<AssetPreLoad> |
| | | public class AssetPreLoad : SingletonMonobehaviour<AssetPreLoad>
|
| | | { |
| | | public void PreLoadNPC(int _mapId) |
| | | { |
| | | NpcPreloadConfig _config = ConfigManager.Instance.GetTemplate<NpcPreloadConfig>(_mapId); |
| | | |
| | | if (_config == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | for (int i = 0; i < _config.NpcIDs.Length; ++i) |
| | | { |
| | | if (_config.NpcIDs[i] == 0) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | var gameObject = InstanceResourcesLoader.LoadNpcPrefab(_config.NpcIDs[i]); |
| | | if (gameObject) |
| | | { |
| | | GAMgr.Instance.AddNeedDestroyPrefab(gameObject); |
| | | GameObjectPoolManager.Instance.CacheNpc(_config.NpcIDs[i], _config.NpcCount[i], true); |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<EffectConfig> m_Effects = null; |
| | | List<EffectConfig> effects |
| | | { |
| | | get { return m_Effects ?? (m_Effects = ConfigManager.Instance.GetAllValues<EffectConfig>()); } |
| | | } |
| | | |
| | | public void PreLoadNPC(int _mapId)
|
| | | {
|
| | | NpcPreloadConfig _config = Config.Instance.Get<NpcPreloadConfig>(_mapId);
|
| | |
|
| | | if (_config == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | for (int i = 0; i < _config.NpcIDs.Length; ++i)
|
| | | {
|
| | | if (_config.NpcIDs[i] == 0)
|
| | | {
|
| | | continue;
|
| | | }
|
| | |
|
| | | var gameObject = InstanceResourcesLoader.LoadNpcPrefab(_config.NpcIDs[i]);
|
| | | if (gameObject)
|
| | | {
|
| | | GAMgr.Instance.AddNeedDestroyPrefab(gameObject);
|
| | | GameObjectPoolManager.Instance.CacheNpc(_config.NpcIDs[i], _config.NpcCount[i], true);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | List<EffectConfig> m_Effects = null;
|
| | | List<EffectConfig> effects
|
| | | {
|
| | | get { return m_Effects ?? (m_Effects = Config.Instance.GetAllValues<EffectConfig>()); }
|
| | | }
|
| | |
|
| | | List<int> loadedJobs = new List<int>(); |
| | | |
| | | public void PreLoadJobEffect(int _job) |
| | | { |
| | | if (loadedJobs.Contains(_job)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | loadedJobs.Add(_job); |
| | | |
| | | var preLoadEffects = new List<int>(); |
| | | foreach (var config in effects) |
| | | { |
| | | if (config.job == _job |
| | | || config.job == 4)// 4 为约定的职业通用特效 |
| | | { |
| | | preLoadEffects.Add(config.id); |
| | | } |
| | | } |
| | | |
| | | if (preLoadEffects.Count > 0) |
| | | { |
| | | StartCoroutine(Co_AsyncLoadEffects(preLoadEffects)); |
| | | } |
| | | public void PreLoadJobEffect(int _job)
|
| | | {
|
| | | if (loadedJobs.Contains(_job))
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | loadedJobs.Add(_job);
|
| | |
|
| | | var preLoadEffects = new List<int>();
|
| | | foreach (var config in effects)
|
| | | {
|
| | | if (config.job == _job
|
| | | || config.job == 4)// 4 为约定的职业通用特效
|
| | | {
|
| | | preLoadEffects.Add(config.id);
|
| | | }
|
| | | }
|
| | |
|
| | | if (preLoadEffects.Count > 0)
|
| | | {
|
| | | StartCoroutine(Co_AsyncLoadEffects(preLoadEffects));
|
| | | }
|
| | | } |
| | | |
| | | IEnumerator Co_AsyncLoadEffects(List<int> _effectIds) |
| | | { |
| | | for (int i = 0; i < _effectIds.Count; i++) |
| | | { |
| | | var effectId = _effectIds[i]; |
| | | InstanceResourcesLoader.LoadEffectAsync(effectId, OnAsyncLoadEffect); |
| | | |
| | | yield return null; |
| | | } |
| | | IEnumerator Co_AsyncLoadEffects(List<int> _effectIds)
|
| | | {
|
| | | for (int i = 0; i < _effectIds.Count; i++)
|
| | | {
|
| | | var effectId = _effectIds[i];
|
| | | InstanceResourcesLoader.LoadEffectAsync(effectId, OnAsyncLoadEffect);
|
| | |
|
| | | yield return null;
|
| | | }
|
| | | } |
| | | |
| | | private void OnAsyncLoadEffect(bool _ok, Object _object) |
| | | { |
| | | if (_ok) |
| | | { |
| | | GameObjectPoolManager.Instance.CacheGameObject(_object as GameObject, 1, false); |
| | | } |
| | | private void OnAsyncLoadEffect(bool _ok, Object _object)
|
| | | {
|
| | | if (_ok)
|
| | | {
|
| | | GameObjectPoolManager.Instance.CacheGameObject(_object as GameObject, 1, false);
|
| | | }
|
| | | } |
| | | |
| | | } |