public LuaTable Inject(LuaMonoBehaviour lb) { LuaTable luaTable = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); luaTable.SetMetaTable(meta); meta.Dispose(); luaTable.Set("mono", lb); if (lb.Injections != null && lb.Injections.Count > 0) { foreach (var injection in lb.Injections.Where(i => i.obj != null)) { luaTable.Set(injection.name, injection.obj); } } if (lb.InjectValues != null && lb.InjectValues.Count > 0) { foreach (var injection in lb.InjectValues.Where(i => i.v != null)) { luaTable.Set(injection.k, injection.v); } } return(luaTable); }
public void Register(string name, LuaMonoBehaviour luaMonoBehaviour) { if (!dicLuaMonoBehaviour.ContainsValue(luaMonoBehaviour)) { dicLuaMonoBehaviour[name] = luaMonoBehaviour; } }
public Lua Init(string name, LuaMonoBehaviour target, ref int tid) { tid = id++; var env = new Lua(); dicLuaMonoBehaviour = new Dictionary <string, LuaMonoBehaviour>(); env.LoadCLRPackage(); var path = Application.streamingAssetsPath + "/lua/?.lua"; env["package.path"] = env["package.path"] + ";" + path; var csHelper = new CsHelper(); env.RegisterFunction("newList", csHelper, typeof(CsHelper).GetMethod("newDFList")); Register(name + tid, target); return(env); }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { LuaMonoBehaviour luaMono = animator.gameObject.GetComponent <LuaMonoBehaviour>(); if (luaMono != null) { luaMono.CallLuaFunction("OnStateEnter", stateInfo.fullPathHash); } }
public override void OnStateMachineExit(Animator animator, int stateMachinePathHash) { LuaMonoBehaviour luaMono = animator.gameObject.GetComponent <LuaMonoBehaviour>(); if (luaMono != null) { luaMono.CallLuaFunction("OnStateMachineExit", stateMachinePathHash); } }
public void OnEnable() { mTarget = (LuaMonoBehaviour)target; if (mTarget.LuaAsset && !Application.isPlaying) { mLuaText = mTarget.LuaAsset.text; refreshAutoGen(); } }
public LuaTable GetLuaTable(byte[] textBytes, LuaMonoBehaviour self = null, string name = "LuaMonoBehaviour") { LuaTable env = null; if (self != null) { env = Inject(self); } return(GetLuaTable(textBytes, env, name)); }
static int _g_get_mLuaScript(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { LuaMonoBehaviour __cl_gen_to_be_invoked = (LuaMonoBehaviour)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushstring(L, __cl_gen_to_be_invoked.mLuaScript); } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } return(1); }
static int _s_set_Injections(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); LuaMonoBehaviour gen_to_be_invoked = (LuaMonoBehaviour)translator.FastGetCSObj(L, 1); gen_to_be_invoked.Injections = (BehaviourInjection[])translator.GetObject(L, 2, typeof(BehaviourInjection[])); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(0); }
static int _g_get_Injections(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); LuaMonoBehaviour gen_to_be_invoked = (LuaMonoBehaviour)translator.FastGetCSObj(L, 1); translator.Push(L, gen_to_be_invoked.Injections); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(1); }
public override void OnInspectorGUI() { LuaMonoBehaviour lb = (LuaMonoBehaviour)target; EditorGUILayout.LabelField("Behaviours:"); EditorGUI.indentLevel++; foreach (var funName in lb.behaviourFun.Keys) { EditorGUILayout.LabelField(funName); } EditorGUI.indentLevel--; }
static int __CreateInstance(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); try { if (LuaAPI.lua_gettop(L) == 1) { LuaMonoBehaviour __cl_gen_ret = new LuaMonoBehaviour(); translator.Push(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to LuaMonoBehaviour constructor!")); }
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); }