public override bool Update() { if (m_Request != null) { return(false); } LoadedAssetBundle bundle = AssetLoadManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError); if (bundle != null) { if (m_IsAdditive) { m_Request = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(m_LevelName, LoadSceneMode.Additive); } else { m_Request = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(m_LevelName); } return(false); } else { return(true); } }
IEnumerator LoadUnitAssets() { yield return(AssetLoadManager.LoadFromResource <Object>(mSquadPath, (Object tObject) => { mSquadAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(mUnitPath, (Object tObject) => { mUnitAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(mArcherPath, (Object tObject) => { mArcherAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(mUnitAimPath, (Object tObject) => { mUnitAimAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(mArrowPath, (Object tObject) => { mArrowAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(mSkillPath, (Object tObject) => { mSkillAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(mPosPath, (Object tObject) => { mPosAsset = tObject; })); //yield return AssetLoadManager.LoadFromResource<Object>(mtestPath, (Object tObject) => //{ // mTestAsset = tObject; //}); }
private IEnumerator OnSetupAvatar() { string modelName = chessCfg.Model; if (string.IsNullOrEmpty(modelName)) { yield break; } string resPath = string.Format("model/{0}.bundle", modelName); var request = AssetLoadManager.LoadAssetAsync(resPath, modelName, typeof(GameObject)); AutoUnloadAsset(request); yield return(request); GameObject prefab = request.GetAsset <GameObject>(); UnityEngine.Profiling.Profiler.BeginSample("EntityInstantiate"); GameObject model = Instantiate(prefab) as GameObject; UnityEngine.Profiling.Profiler.EndSample(); SetAvatar(model); }
int mAutoFight = 1;//the value 1 is AutoFight void Awake() { GameObject tbattleRoot = GameObjectCreater.CreateGo("BattleRoot"); mEmb = transform.GetComponent <Embattling>(); GameObjectPool.GetInstance().root = tbattleRoot; mSquadDataList = new List <SquadData>(); mSquadGameObjDict = new Dictionary <int, GameObject>(); mBattleSceneConfig = TableManager.GetSceneClassByID(1)[0]; StartCoroutine(AssetLoadManager.LoadFromResource(mPosPath, GeneratePos)); //EventManager.GetInstance().AddEventListener(EventId.LoadSquad, LoadSquad); EventManager.GetInstance().AddEventListener(EventId.StartBattle, StartBattle); //EventManager.GetInstance().AddEventListener(EventId.StartFight, StartFight); //EventManager.GetInstance().AddEventListener(EventId.ReceiveFight, ReceiveFight); //EventManager.GetInstance().AddEventListener(EventId.SendMarch, SendMerch); EventManager.GetInstance().AddEventListener(EventId.UseSkill, UseSkill); EventManager.GetInstance().AddEventListener(EventId.AutoFight, AutoFight); EventManager.GetInstance().AddEventListener(EventId.ReceiveBattleInfor, ReceiveBattleInfor); EventManager.GetInstance().AddEventListener(EventId.ReceiveSquadPosInfor, ReceivePosList); EventManager.GetInstance().AddEventListener(EventId.ReceiveCommandPursue, ReceiveCommandPursue); EventManager.GetInstance().AddEventListener(EventId.ReceivePrepareForAttack, ReceivePrepareForAttack); EventManager.GetInstance().AddEventListener(EventId.ReceiveObjGetHurt, ReceiveObjGetHurt); EventManager.GetInstance().AddEventListener(EventId.ReceiveSkill, ReceiveSkill); EventManager.GetInstance().AddEventListener(EventId.ReceiveBattleEnd, ReceiveBattleEnd); //EventManager.GetInstance().AddEventListener(EventId.ReceiveUpdateMarchMsg, ReceiveSendMarch); LoadSquad(null); //GetBattlerInfor(); }
private void UnLoadLastSceneAsset() { if (LastSceneCfg != null) { string sceneBundleName = string.Format("scene/scene_{0}.bundle", LastSceneCfg.AssetPath.ToLower()); AssetLoadManager.UnLoadAssetBundle(sceneBundleName); } }
void UpdateLoad() { if (!seqState.IsInit()) { for (int i = 0; i < EFFECT_PATH_TABLE.Length; i++) { var path = EFFECT_PATH_TABLE[i]; var handle = AssetLoadManager.Load <GameObject>(ref path); effectLoadDatas[i] = new EffectLoadData() { assetLoadHandle = handle, effectId = (EFFECT_ID)i, }; } seqState.SetInit(true); } bool end = true; for (int i = 0; i < effectLoadDatas.Length; i++) { var data = effectLoadDatas[i]; if (data.assetLoadHandle.Result == ASSET_LOAD_RESULT_TYPE.SUCCESS) { data.gameObject = data.assetLoadHandle.LoadObject as GameObject; data.isLoaded = true; int id = (int)data.effectId; int count = EFFECT_COUNT_TABLE[id]; ParticleSystem[] particles = new ParticleSystem[count]; for (int k = 0; k < particles.Length; k++) { GameObject instance = GameObject.Instantiate(data.gameObject, rootTrans); instance.name = data.gameObject.name; instance.SetActive(false); particles[k] = instance.GetComponent <ParticleSystem>(); } effectTable.Add(id, particles); } else if (data.assetLoadHandle.Result == ASSET_LOAD_RESULT_TYPE.FAILURE) { int id = (int)data.effectId; effectTable.Add(id, null); } else { end = false; } } if (end) { seqState.ChangeState(SEQ_STATE.UPDATE); } }
static private IEnumerator LoadAllPolicys() { yield return(AssetLoadManager.LoadAssetAsync <LoadPolicys>("load_first$loadfirst.assetbundle", "LoadPolicys", (asset) => { Configs.loadPolicys = asset; })); SubBundleRef("load_first$loadfirst.assetbundle"); }
public void Update() { if (!ConfigManager.isDone) { return; } AssetLoadManager.CreateInstance(); GameStateManager.ChangeState(StateEnum.LOGIN); }
IEnumerator LoadUnitAssets(CBattleInfor tBattleInfor) { yield return(AssetLoadManager.LoadFromResource <Object>("SquadPrefab/Cylinder", (Object tObject) => { mSquadAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>("AimPrefab/AimObj", (Object tObject) => { mAimAsset = tObject; })); for (int i = 0; i < tBattleInfor.objList.Count; i++) { SquadData tSquadData = new SquadData(); tSquadData.SetSquadInfor(tBattleInfor.objList[i]); Tab_UnitTemplate tUnitTpData = TableManager.GetUnitTemplateByID(tSquadData.GetUnitTemplateID())[0]; Tab_SkillTemplate tSkillTemplate = TableManager.GetSkillTemplateByID(tSquadData.SkillTemplateID)[0]; yield return(AssetLoadManager.LoadFromResource <Object>(tUnitTpData.UnitPath, (Object tObject) => { tSquadData.UnitAsset = tObject; })); yield return(AssetLoadManager.LoadFromResource <Object>(tSkillTemplate.UnitPath, (Object tObjcet) => { tSquadData.SkillAsset = tObjcet; })); yield return(AssetLoadManager.LoadFromResource <Object>(tUnitTpData.UnitSkillPath, (Object tObjcet) => { tSquadData.UnitSkillAsset = tObjcet; })); yield return(AssetLoadManager.LoadFromResource <Object>(tUnitTpData.UnitArrowPath, (Object tObjcet) => { tSquadData.UnitArrowAsset = tObjcet; })); mSquadDataList.Add(tSquadData); } PrepareForBattle(mSquadGameObjDict, mSquadDataList); switch (mBattleState) { case BattleState.prepare: AddEmbateBornList(); StartCoroutine(BattleStart()); break; case BattleState.Start: break; } SetSquadEnemy(); }
//卸载指定 “加载策略文件” 中的所有bundle static public void UnloadBundlesByPolicy(string str, bool unloadAllLoadedObject) { LoadPolicy policy = GetPolicy(str); if (policy.list != null && policy.list.Count > 0) { for (int i = 0; i < policy.list.Count; i++) { AssetLoadManager.Unload(policy.list[i], unloadAllLoadedObject); } } }
//下载并缓存指定 “加载策略文件” 中的所有bundle static public IEnumerator LoadBundlesByPolicy(string str) { LoadPolicy policy = GetPolicy(str); if (policy.list != null && policy.list.Count > 0) { for (int i = 0; i < policy.list.Count; i++) { yield return(AssetLoadManager.LoadAssetBundle(policy.list[i])); } } }
public EffectObject(EffectCfg config, Transform root) { this.config = config; this.EffectID = config.ID; this.gameObject = new GameObject(config.ID.ToString()); this.transform = gameObject.transform; this.transform.SetParent(root); this.assetBundleName = string.Format(effectBundlePath, config.AssetName.ToLower()); this.activelayer = LayerManager.DefaultLayer; assetLoadOperation = AssetLoadManager.LoadAssetAsync(assetBundleName, config.AssetName, typeof(GameObject)); }
private IEnumerator ChangeToEmptyScene(int sceneId, bool isServerScene = false) { AssetLoadManager.OnDispose(); GameEventManager.RaiseEvent(GameEventTypes.ExitScene); UnityEngine.SceneManagement.SceneManager.LoadScene("empty"); UnLoadLastSceneAsset(); SceneCamera = null; yield return(ChangeSceneInternal(sceneId)); }
private static T CreateView <T>(string packageName, string uiName) where T : GUIBase { GUIBase view = System.Activator.CreateInstance(typeof(T)) as GUIBase; if (view == null) { return(null); } string packageBundleName = string.Format("ui/{0}.bundle", packageName.ToLower()); LoadedAssetBundle loadedassetBundle = AssetLoadManager.LoadAssetBundle(packageBundleName); if (loadedassetBundle == null && AssetLoadManager.SimulateAssetBundleInEditor == false) { return(null); } PackageInfo package; if (!packageDic.TryGetValue(packageName, out package)) { package = new PackageInfo(packageName); packageDic.Add(packageName, package); } else { package.referencedCount++; } UIPackage.AddPackage(packageName, (string name, string extension, System.Type type) => { if (loadedassetBundle != null) { return(loadedassetBundle.assetBundle.LoadAsset(name, type)); } else if (AssetLoadManager.SimulateAssetBundleInEditor) { return(AssetLoadManager.LoadAsset(packageBundleName, name, type)); } return(null); }); view.uiName = uiName; view.packageName = packageName; view.Start(); uiViewDic.Add(uiName, view); return(view as T); }
private IEnumerator ChangeSceneInternal(int sceneId) { var config = sceneCfgLoader.GetConfig(sceneId); LastSceneCfg = config; string sceneName = ""; sceneName = config.AssetPath; string sceneBundleName = string.Format("scene/scene_{0}.bundle", sceneName.ToLower()); var m_operation = AssetLoadManager.LoadLevelAsync(sceneBundleName, sceneName, false); Progress = 0f; while (!m_operation.IsDone()) { Progress += Time.deltaTime * 0.2f; Progress = Mathf.Min(Progress, 1f); yield return(null); } Progress = 1; SceneCamera = Camera.main; SceneCameraTrans = SceneCamera.transform; GameEventManager.EnableEventFiring = true; CloseMainCameraUILayer(); if (config.BGM > 0) { PlayBGM(config.BGM); } if (config.SceneType == 1) { GameStateManager.ChangeState(StateEnum.WORLD); } else { GameStateManager.ChangeState(StateEnum.WORLDFight); } GameEventManager.RaiseEvent(GameEventTypes.EnterScene, sceneId); }
/// <summary> /// メモリ使用量が一定以上になったら解放 /// </summary> static void UnusedUnload() { long memory = 0; if (Profiler.supported) { memory = Profiler.GetTotalAllocatedMemoryLong(); if (memory < 100 * 1024 * 1024) { // メモリ使用量が100MBいないなら解放しない return; } } AssetLoadManager.UnusedUnload(); }
static public IEnumerator LoadAllConfigs() { yield return(AssetLoadManager.LoadAssetAsync <CustomConfig> ("load_preload$g_config$config.assetbundle", "CustomConfig", (config) => { _customConfig = config; })); yield return(AssetLoadManager.LoadAssetAsync <UICategoryConfigFile> ("load_preload$g_config$config.assetbundle", UICategoryConfig.BundleConfigName, (config) => { UICategoryConfigFile = config; })); yield return(AssetLoadManager.LoadAssetAsync <UIItemConfigFile> ("load_preload$g_config$config.assetbundle", UIItemConfig.BundleConfigName, (config) => { UIItemConfigFile = config; })); // AssetLoadManager.Unload ("",true); yield break; }
//加载 并转存所有表格 static private IEnumerator LoadAndSaveTables() { LoadPolicy policy = GetPolicy("load_table"); if (policy.list != null && policy.list.Count > 0) { string filePath = Application.persistentDataPath + "/Tables"; if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } //正式版 和Develop模式表的分别处理 if (Configs.clientConfig.isReleaseBundle) { for (int i = 0; i < policy.list.Count; i++) { //表是没有依赖的 所以只取第一个 yield return(AssetLoadManager.LoadAssetBundle(policy.list[i], (bundle) => { TextAsset[] assets = bundle.LoadAllAssets <TextAsset>(); string fileName = assets[0].name + ".txt"; File.WriteAllText(filePath + "/" + fileName, assets[0].text); })); } yield return(null); } else { List <AssetInfo> list = new List <AssetInfo>(); for (int i = 0; i < policy.list.Count; i++) { GetAllAssetByBundleName(policy.list[i], list); } for (int i = 0; i < list.Count; i++) { TextAsset ta = Resources.Load <TextAsset>(list[i].path); string fileName = ta.name + ".txt"; File.WriteAllText(filePath + "/" + fileName, ta.text); } yield return(null); } } }
public static void Destroy(GUIBase ui) { PackageInfo package = packageDic[ui.packageName]; package.referencedCount--; ui.Destory(); uiViewDic.Remove(ui.uiName); string packageBundleName = string.Format("ui/{0}.bundle", package.packageName.ToLower()); AssetLoadManager.UnLoadAssetBundle(packageBundleName); if (package.referencedCount == 0) { UIPackage.RemovePackage(package.packageName); packageDic.Remove(package.packageName); } }
//下载指定 “加载策略文件” 中的所有bundle static public IEnumerator DownloadBundlesByPolicy(LoadPolicy policy) { if (policy.list != null && policy.list.Count > 0) { List <string> needLoads = new List <string>(); for (int i = 0; i < policy.list.Count; i++) { AssetLoadManager.GetBundleNeedLoads(policy.list[i], needLoads); } for (int i = 0; i < needLoads.Count; i++) { yield return(AssetLoadManager.LoadAssetBundle(needLoads[i], (bundle) => { AssetLoadManager.Unload(bundle.name, true); })); } } }
//反向查找资源并缓存加载 static public IEnumerator LoadAssetAsyncByFileName <T>(string fileName, Action <T> callback) where T : UnityEngine.Object { List <AssetInfo> infos = new List <AssetInfo>(); StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < GameUtility.assetsInfo.assetList.Count; i++) { strBuilder.Remove(0, strBuilder.Length); strBuilder.Append(GameUtility.assetsInfo.assetList[i].name); strBuilder.Append("."); strBuilder.Append(GameUtility.assetsInfo.assetList[i].suffix); if (strBuilder.ToString() == fileName) { //冗余资源的反向查找未支持,找到一个Bundle就直接Break infos.Add(GameUtility.assetsInfo.assetList[i]); fileName = GameUtility.assetsInfo.assetList[i].name; if (!GameUtility.assetsInfo.assetList[i].multiple) { break; } } } if (infos.Count == 0) { #if UNITY_EDITOR Debug.LogError("Not find file from AssetsInfo :" + fileName); #endif } else if (infos.Count == 1) { yield return(AssetLoadManager.LoadAssetAsync <T>(infos[0].bundleName, fileName, callback)); } else if (infos.Count > 1) { #if UNITY_EDITOR Debug.LogError("冗余资源的反向查找未支持!"); #endif } yield break; }
//获取指定加载策略文件中所有需要从远端下载更新的文件大小 static public long GetNeedDownByPolicy(string str) { long totalSize = 0; LoadPolicy policy = GetPolicy(str); List <string> bundleNames = new List <string>(); for (int i = 0; i < policy.list.Count; i++) { AssetLoadManager.GetBundleNeedLoads(policy.list[i], bundleNames); } if (bundleNames.Count > 0) { for (int i = 0; i < bundleNames.Count; i++) { totalSize += AssetLoadManager.GetBundleSize(bundleNames[i]); } } return(totalSize); }
public AudioObject(AudioCfg audioCfg, Transform root) { this.audioCfg = audioCfg; AudioID = audioCfg.ID; gameObject = new GameObject(audioCfg.ID.ToString()); Disable(); transform = gameObject.transform; transform.SetParent(root); audioTarget = new AudioTarget(); audioSource = gameObject.AddComponent <AudioSource>(); audioSource.outputAudioMixerGroup = AudioManager.GetMixerGroup((AudioGroupTypes)audioCfg.Priority); audioSource.volume = audioCfg.Volume; audioSource.loop = audioCfg.Loop; audioSource.dopplerLevel = 0; assetBundleName = string.Format(audioBundlePath, audioCfg.AssetName.ToLower()); assetLoadOperation = AssetLoadManager.LoadAssetAsync(assetBundleName, audioCfg.AssetName, typeof(AudioClip)); }
// Returns true if more Update calls are required. public override bool Update() { if (m_Request != null) { return(false); } LoadedAssetBundle bundle = AssetLoadManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError); if (bundle != null) { ///@TODO: When asset bundle download fails this throws an exception... m_Request = bundle.assetBundle.LoadAssetAsync(m_AssetName, m_Type); return(false); } else { return(true); } }
// static private IEnumerator LoadAndSaveLuaScripts() { string filePath = string.Format("{0}/{1}/", Application.persistentDataPath, "Lua"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string bundleName = "load_preload$g_lua$lua.assetbundle"; //正式版 和Develop的分别处理 if (Configs.clientConfig.isReleaseBundle) { yield return(AssetLoadManager.LoadAssetBundle(bundleName, (bundle) => { TextAsset[] textAssets = bundle.LoadAllAssets <TextAsset>(); for (int i = 0; i < textAssets.Length; i++) { string fileName = textAssets[i].name + ".txt"; File.WriteAllText(filePath + "/" + fileName, textAssets[i].text); } })); yield return(null); } else { List <AssetInfo> list = new List <AssetInfo>(); GetAllAssetByBundleName(bundleName, list); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { TextAsset ta = Resources.Load <TextAsset>(list[i].path); string fileName = ta.name + ".txt"; File.WriteAllText(filePath + "/" + fileName, ta.text); } } yield return(null); } }
public static void DestroyAll() { foreach (var pair in uiViewDic) { PackageInfo package = packageDic[pair.Value.packageName]; package.referencedCount--; pair.Value.Destory(); string packageBundleName = string.Format("ui/{0}.bundle", package.packageName.ToLower()); AssetLoadManager.UnLoadAssetBundle(packageBundleName); if (package.referencedCount == 0) { UIPackage.RemovePackage(package.packageName); packageDic.Remove(package.packageName); } } uiViewDic.Clear(); packageDic.Clear(); }
public static XmlDocument GetDocument(string path, string bundleName) { TextAsset data = AssetLoadManager.LoadAsset <TextAsset>(bundleName, System.IO.Path.GetFileNameWithoutExtension(path)); if (data == null) { return(null); } XmlDocument doc = new XmlDocument(); try { doc.LoadXml(data.text); } catch (System.Exception ex) { return(null); } return(doc); }
/// <summary> /// 単体ファイルを読み込みます /// AssetBundleに使用する場合、1AssetBundle1ファイルのものにのみ使えます /// </summary> /// <param name="path">アセットバンドルのパス</param> /// <param name="name">アセット名</param> /// <returns></returns> public static AssetLoader LoadAssetFile(string path, string name) { AssetLoader loader = null; var resources = AssetLoadManager.IsResources(path); if (resources) { loader = LoadAssetFileResources(path, name); } #if UNITY_EDITOR else if (!UseAssetBundle) { loader = LoadAssetFileEditor(path, name); } #endif else { loader = LoadAssetFileAssetBundle(path, name); } loader.IsResources = resources; return(loader); }
private IEnumerator OnSetupController() { string controllerName = chessCfg.Controller; if (string.IsNullOrEmpty(controllerName)) { Debug.LogErrorFormat("chess config {0} does not have a controller name", chessObj.id); yield break; } string resPath = string.Format("controller/controller_{0}.bundle", controllerName); var request = AssetLoadManager.LoadAssetAsync(resPath, controllerName, typeof(RuntimeAnimatorController)); AutoUnloadAsset(request); yield return(request); var controller = request.GetAsset <RuntimeAnimatorController>(); SetAnimatorController(controller); }
static public IEnumerator Init() { //初始化 资源加载器 yield return(AssetLoadManager.Init()); //加载资源信息文件 yield return(GameUtility.LoadAssetsInfo()); //加载Bundle信息文件 if (Configs.clientConfig.isReleaseBundle) { yield return(GameUtility.LoadBundlesInfo()); } //加载所有配置文件 yield return(Configs.LoadAllConfigs()); //加载 热更策略文件 yield return(LoadAllPolicys()); //加载 所有后续需要处理的资源 yield return(DownloadAllAssets()); }