static int _m_Init(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); LuaMonoBehaviour __cl_gen_to_be_invoked = (LuaMonoBehaviour)translator.FastGetCSObj(L, 1); try { { string luaScript = LuaAPI.lua_tostring(L, 2); __cl_gen_to_be_invoked.Init(luaScript); return(0); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }
/// <summary> /// 加载timeline prefab协程 /// </summary> /// <param name="id"></param> /// <param name="prefabPath"></param> /// <param name="finishCallback"></param> /// <param name="pos"></param> /// <param name="needCameraFollowInterpolationWhenFinished"></param> /// <param name="showLocalPlayer"></param> /// <returns></returns> IEnumerator LoadPrefabCoroutine(TimelineConfig config, System.Action finishCallback, AvatarProperty avatarProperty) { uint id = config.Id; string prefabPath = config.PrefabPath; Vector3 pos = config.Pos; Vector3 rotation = config.Rotation; bool needCameraFollowInterpolationWhenFinished = config.NeedCameraFollowInterpolationWhenFinished; bool showLocalPlayer = config.ShowLocalPlayer; bool noStopLocalPlayer = config.NoStopLocalPlayer; bool showUI = config.ShowUI; bool pauseMusic = config.PauseMusic; bool needGC = config.NeedGC; SGameEngine.PrefabResource pr = new SGameEngine.PrefabResource(); yield return(SGameEngine.ResourceLoader.Instance.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_prefab(string.Format("Assets/Res{0}.prefab", prefabPath), pr))); // 延迟资源的加载,测试用 //yield return new WaitForSeconds(5f); // 恢复玩家操作 GameInput.Instance.EnableInput(true, true); GameObject obj = pr.obj_; if (obj == null) { if (finishCallback != null) { finishCallback(); } if (mLoadingTimelineIdList.Contains(id) == true) { mLoadingTimelineIdList.Remove(id); } GameDebug.LogError("Play timeline " + prefabPath + " error, can not load prefab!"); yield break; } PlayableDirector playableDirector = obj.GetComponent <PlayableDirector>(); if (playableDirector == null) { GameObject.DestroyImmediate(obj); if (finishCallback != null) { finishCallback(); } if (mLoadingTimelineIdList.Contains(id) == true) { mLoadingTimelineIdList.Remove(id); } GameDebug.LogError("Play timeline " + prefabPath + " error, can not find PlayableDirector component!"); yield break; } string relatedPrefabPath = config.RelatedPrefabPath; SGameEngine.PrefabResource relatedPrefabPr = null; if (string.IsNullOrEmpty(relatedPrefabPath) == false) { relatedPrefabPr = new SGameEngine.PrefabResource(); yield return(SGameEngine.ResourceLoader.Instance.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_prefab(string.Format("Assets/Res{0}.prefab", relatedPrefabPath), relatedPrefabPr))); } obj.SetActive(false); obj.transform.position = pos; obj.transform.localScale = Vector3.one; obj.transform.localEulerAngles = rotation; TimelineInfo timelineInfo = new TimelineInfo(); playableDirector.time = 0; timelineInfo.Id = id; timelineInfo.PlayableDirector = playableDirector; timelineInfo.FinishCallback = finishCallback; timelineInfo.AvatarProperty = avatarProperty; timelineInfo.NeedCameraFollowInterpolationWhenFinished = needCameraFollowInterpolationWhenFinished; timelineInfo.ShowLocalPlayer = showLocalPlayer; timelineInfo.NoStopLocalPlayer = noStopLocalPlayer; timelineInfo.ShowUI = showUI; timelineInfo.PauseMusic = pauseMusic; timelineInfo.NeedGC = needGC; // 关联GameObject timelineInfo.RelatedGameObject = null; if (relatedPrefabPr != null) { if (relatedPrefabPr.obj_ != null) { timelineInfo.RelatedGameObject = relatedPrefabPr.obj_; timelineInfo.RelatedGameObject.SetActive(false); timelineInfo.RelatedGameObject.transform.position = config.RelatedPrefabPos; timelineInfo.RelatedGameObject.transform.localScale = Vector3.one; timelineInfo.RelatedGameObject.transform.localEulerAngles = Vector3.zero; } else { GameDebug.LogError("Play timeline " + id + " error, can not load related prefab " + relatedPrefabPath); } } // lua脚本 if (string.IsNullOrEmpty(config.BehaviorScript) == false) { if (LuaScriptMgr.Instance != null && LuaScriptMgr.Instance.IsLuaScriptExist(config.BehaviorScript)) { LuaMonoBehaviour com = obj.AddComponent <LuaMonoBehaviour>(); com.Init(config.BehaviorScript); } else { System.Type t = System.Type.GetType(config.BehaviorScript); if (t != null) { obj.AddComponent(t); } } } // 延迟资源的加载,测试用 //yield return new WaitForSeconds(10f); if (mPlayingTimeline != null) { mCacheTimelineList.Enqueue(timelineInfo); } else { PlayImpl(timelineInfo); } if (mLoadingTimelineIdList.Contains(id) == true) { mLoadingTimelineIdList.Remove(id); } //GameDebug.LogError("TimelineManager.LoadPrefabCoroutine: " + id); }