/// <summary> /// 资源载入的资源 /// </summary> /// <param name="loader"></param> private void instanceCutscene(ALoadOperation loader) { GameObject gObj = loader.GetAsset <GameObject>(); if (gObj == null) { Debug.LogError(string.Format("找不到加载的剧情片段资源!路径:{0}", loader.assetPath)); return; } gObj = GameObject.Instantiate(gObj); gObj.name = gObj.name.Replace("(Clone)", ""); GameObject.DontDestroyOnLoad(gObj); caches.Add(gObj); PlotCamera[] plotCameraArr = gObj.GetComponentsInChildren <PlotCamera>(); for (int i = 0; i < plotCameraArr.Length; i++) { plotCameraArr[i].gameObject.SetActive(false); } Cutscene cutscene = gObj.GetComponent <Cutscene>(); cutscene.Optimize(); cutscene.CutscenePaused += pauseCutsceneEvent; cutscene.CutsceneFinished += finishCutsceneEvent; int cutsceneId = Convert.ToInt32(gObj.name.Substring(8)); this.catchCutscenes[cutsceneId] = cutscene; gObj.SetActive(false); }
/// <summary> /// 异步加载剧情片段 /// </summary> /// <param name="cutsceneId"></param> /// <returns></returns> private IEnumerator loadCutsceneAsync(int cutsceneId) { string cutscenePath = string.Concat("Prefab/Cutscene/Cutscene", cutsceneId); ALoadOperation operation = ResourceManager.LoadBundleAsync(cutscenePath); yield return(this.StartCoroutine(operation)); GameObject gObj = operation.GetAsset <GameObject>(); if (gObj == null) { Debug.LogError(string.Format("找不到加载的剧情片段资源!路径:{0}", cutscenePath)); yield break; } gObj = GameObject.Instantiate(gObj); gObj.name = gObj.name.Replace("(Clone)", ""); GameObject.DontDestroyOnLoad(gObj); PlotCamera[] plotCameraArr = gObj.GetComponentsInChildren <PlotCamera>(); for (int i = 0; i < plotCameraArr.Length; i++) { plotCameraArr[i].gameObject.SetActive(false); } yield return(null); curCutscene = gObj.GetComponent <Cutscene>(); curCutscene.Optimize(); yield return(null); curCutscene.CutscenePaused += pauseCutsceneEvent; curCutscene.CutsceneFinished += finishCutsceneEvent; }
/// <summary> /// 预加载场景中的资源 /// </summary> /// <param name="triggerGroup"></param> public void PreLoadCutscene(GameObject triggerGroup, LoadStageAsync stageLoader) { if (triggerGroup == null) { return; } GameObject.DontDestroyOnLoad(triggerGroup); caches.Add(triggerGroup); Transform triggerGroupTrans = triggerGroup.transform; List <string> cutsenes = new List <string>(); for (int i = 0, count = triggerGroupTrans.childCount; i < count; i++) { Transform childTrans = triggerGroupTrans.GetChild(i); if (!childTrans.gameObject.activeSelf) { continue; } string cutsceneId = childTrans.name.Substring(7); //name = Trigger + id if (!triggered.Contains(Convert.ToInt32(cutsceneId))) { cutsenes.Add(cutsceneId); } } cutsenes.Sort(); for (int i = 0; i < cutsenes.Count; i++) { string resPath = string.Concat("Prefab/Cutscene/Cutscene", cutsenes[i]); ALoadOperation loadAssetAsync = ResourceManager.LoadBundleAsync(resPath); loadAssetAsync.OnFinish = instanceCutscene; stageLoader.AddLoader(loadAssetAsync, 5); } }