void Awake() { scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv); Action luaAwake = scriptEnv.Get<Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
void Awake() { scriptEnv = LuaEnv.NewTable(); LuaTable meta = LuaEnv.NewTable(); meta.Set("__index", LuaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } TextAsset text = Application.Make<IResources>().Load<TextAsset>(luaPath); LuaEnv.DoString(text.text, "LuaBehaviour", scriptEnv); Action luaAwake = scriptEnv.Get<Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
public void RemovePointerEvent(EventTriggerType triggerType, LuaTable value) { if (_eventDic.ContainsKey(triggerType)) { int key = value.Get <int>("_instanceId"); if (_eventDic[triggerType].luaTables.ContainsKey(key)) { _eventDic[triggerType].luaTables.Remove(key); } } }
/// <summary> /// 绑定lua方法 /// </summary> void BindingLuaScript() { LoadLuaScript(); Action luaAwake = scriptEnv.Get <Action>("Awake"); scriptEnv.Get("Start", out luaStart); scriptEnv.Get("Update", out luaUpdate); scriptEnv.Get("OnDestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } if (isStarted) { CallLuaStart(); } }
public static StructData GenerateVMData(LuaTable luaData) { LuaTable strct = luaData.Get <LuaTable>("__vm_value"); StructData strctData = new StructData(); strct.ForEach <string, LuaTable>(delegate(string key, LuaTable el) { strctData.AddField(key, XLuaData.GenerateDataWithLuaTable(el)); }); return(strctData); }
private Product LoadProduct(LuaTable table) { var haveExtraData = LoadItemData(out var goods, out var amount, table, true); float min = amount, max = amount; if (haveExtraData && amount == 0) { table.Get("amount_min", out min); table.Get("amount_max", out max); } var product = new Product(goods, min, max, table.Get("probability", 1f)); var catalyst = table.Get("catalyst_amount", 0f); if (catalyst > 0f) { product.SetCatalyst(catalyst); } return(product); }
void Awake() { LuaEnv luaEnv = LuaMgr.luaenv; scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); scriptEnv.Set("transform", transform); scriptEnv.Set("gameObject", gameObject); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } string name = gameObject.name; LuaMgr.loadLua(name, text => { if (text == null || text.Length == 0) { return; } luaEnv.DoString(text, name, scriptEnv); Action luaAwake = scriptEnv.Get <Action> ("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }); }
private const float GcInterval = 1; //1 second protected virtual void Awake() { var meta = LuaEnv.NewTable(); meta.Set("__index", LuaEnv.Global); ScriptEnv.SetMetaTable(meta); meta.Dispose(); ScriptEnv.Set("self", this); foreach (var injection in Injections) { ScriptEnv.Set(injection.Name, injection.Value); } var content = LuaEnv.DoString(string.Format(@" local content = require '{0}' return content", _luaFilePath), "LuaMonoBehaviour", ScriptEnv); if (content != null) { LuaTable luaTable = (LuaTable)content[0]; var contentMeta = LuaEnv.NewTable(); contentMeta.Set("__index", ScriptEnv); luaTable.SetMetaTable(contentMeta); contentMeta.Dispose(); var luaAwake = luaTable.Get <Action>("awake"); _luaStart = luaTable.Get <Action>("start"); _luaUpdate = luaTable.Get <Action>("update"); _luaOnDestroy = luaTable.Get <Action>("destroy"); if (luaAwake != null) { luaAwake(); } } }
/// <summary> /// ���ӹ��ﵽԤ���������� /// </summary> /// <param name="monsterID"></param> /// <param name="maxNum"></param> protected virtual void AddMonster(int monsterID, int maxNum) { LuaTable cfg = ConfigManager.Instance.Actor.GetMonsterConfig(monsterID); //monsterConfig monsterCfg = CSVConfigManager.GetmonsterConfig(monsterID); if (null == cfg) { return; } AddModel(cfg.Get <int>("modelId"), maxNum); }
public T GetLuaInterface <T>(LuaTable luaTable = null, string tableName = null) where T : ILuaInterface { if (luaTable == null) { luaTable = this._luaEnv.Global; } if (string.IsNullOrEmpty(tableName)) { tableName = typeof(T).Name; } return(luaTable.Get <T>(tableName)); }
//////////////////////////////////////////////////// public LuaTable GetSkillActon(int nSkillID) { LuaTable skillDesc = ConfigManager.Instance.Skill.GetSkillConfig(nSkillID); if (skillDesc != null) { int nSkillActionID = Convert.ToInt32(skillDesc.Get <string>("skill_action")); return(ConfigManager.Instance.Skill.GetSkillActionConfig(nSkillActionID)); } return(null); }
public string GetMagickeyName(int magickeyid) { string name = ""; LuaTable tbl = null; if (m_CacheMagicKeyConfig.TryGetValue(magickeyid, out tbl)) { name = tbl.Get <string>("nameIcon"); } return(name); }
public int GetMagickeySkillID(int magickeyid) { int kSkillID = 0; LuaTable tbl = null; if (m_CacheMagicKeyConfig.TryGetValue(magickeyid, out tbl)) { kSkillID = tbl.Get <int>("baseSkillID"); } return(kSkillID); }
private Product LoadProduct(LuaTable table) { var haveExtraData = LoadItemData(out var goods, out var amount, table); if (haveExtraData && amount == 0) { table.Get("amount_min", out float min); table.Get("amount_max", out float max); amount = (min + max) / 2; } var product = new Product(goods, amount) { probability = table.Get("probability", 1f) }; if (haveExtraData && goods is Fluid f) { product.temperature = table.Get("temperature", f.minTemperature); } return(product); }
/// <summary> /// 初始化配置。 /// </summary> public void InitConfig() { LuaTable G = LuaMgr.Instance.GetLuaEnv().Global; m_CacheEquipConfig = G.Get <Dictionary <int, LuaTable> >("t_equip"); m_CacheBagCostConfig = G.Get <Dictionary <int, LuaTable> >("t_packetcost"); m_CacheDepotCostConfig = G.Get <Dictionary <int, LuaTable> >("t_storagecost"); m_CacheWingConfig = G.Get <Dictionary <int, LuaTable> >("t_newwing"); m_CacheWingSkinConfig = G.Get <Dictionary <int, LuaTable> >("t_newwingskin"); m_CacheEquipGroupConfig = G.Get <Dictionary <int, LuaTable> >("t_equipgroup"); m_CacheItemConfig = G.Get <Dictionary <int, LuaTable> >("t_item"); m_CacheFashionConfig = G.Get <Dictionary <int, LuaTable> >("t_fashions"); m_CacheFashionGroupConfig = G.Get <Dictionary <int, LuaTable> >("t_fashiongroup"); m_CacheShenBingConfig = G.Get <Dictionary <int, LuaTable> >("t_shenbing"); m_CacheShieldConfig = G.Get <Dictionary <int, LuaTable> >("t_pifeng"); LuaTable itemconfig = G.Get <LuaTable>("ConfigData").Get <LuaTable>("ItemConfig"); m_BagInitSize = itemconfig.Get <int>("BagInitSize"); m_DepotInitSize = itemconfig.Get <int>("StorageInitSize"); }
public void LoadLua(string fileName, string className = "") { //Debug.Log("LoadLua: " + className); TextAsset luaScript = Resources.Load <TextAsset>(fileName); scriptEnv.Set("self", this); luaEnv.DoString(luaScript.text, className, scriptEnv); Action luaAwake = scriptEnv.Get <Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("oncollisionenter", out luaOnCollisionEnter); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
public int GetShareSkillCDTime(LuaTable skillDesc) { int value = 0; ShareCDData data; if (!m_SkillShareCDMap.TryGetValue(skillDesc.Get <int>("group_cd_id"), out data)) { return(value); } value = data.cdTime; return(value); }
private IPerformNode ParseNode(LuaTable table) { IPerformNode node = CreateNode((PerformNodeType)table.Get <int>("nodeType")); node.InjectData(table); var delay = table.Get <float>("delay"); node.Delay = delay; var followers = table.Get <List <LuaTable> >("followers"); var companions = table.Get <List <LuaTable> >("companions"); for (int i = 0; i < followers.Count; ++i) { node.AddFollower(ParseNode(followers[i])); } for (int i = 0; i < companions.Count; ++i) { node.AddCompanion(ParseNode(companions[i])); } return(node); }
public int GetMagickeyModel(int magickeyid) { int modelid = 0; LuaTable tbl = null; if (m_CacheMagicKeyConfig.TryGetValue(magickeyid, out tbl)) { modelid = tbl.Get <int>("model"); } return(modelid); }
/// <summary> /// 发送购买请求。 /// </summary> /// <param name="id">商品id</param> /// <param name="num">购买数量</param> public static void SendShoppingRequest(int id, int num) { //转调Lua层 LuaTable G = LuaMgr.Instance.GetLuaEnv().Global; LuaTable model = G.GetInPath <LuaTable>("ModelManager.ShopModel"); ShoppingCall fun = model.Get <ShoppingCall>("SendShoppingRequest"); if (fun != null) { fun(model, id, num); } }
internal bool _call(string methodName, Gesture go) { if (_luaModule != null && go != null) { var func = _luaModule.Get <EventCallLua>(methodName); if (func != null) { return(func(_luaModule, go)); } } return(false); }
private LuaTable GetLuaTable() { LuaTable luaModule = ezLua.luaRequire(moduleName); LuaAwake awake = luaModule.Get <LuaAwake>("LuaAwake"); LuaTable table = awake == null ? luaModule : awake.Invoke(this); luaStart = table.Get <LuaAction <LuaTable> >("LuaStart"); luaOnEnable = table.Get <LuaAction <LuaTable> >("LuaOnEnable"); luaOnDisable = table.Get <LuaAction <LuaTable> >("LuaOnDisable"); luaOnDestroy = table.Get <LuaAction <LuaTable> >("LuaOnDestroy"); return(table); }
public LuaTable CreateLuaIns <T>(LuaTable lua_class, LuaTable param, T ins) { LuaFunction luaNew = lua_class.Get <LuaFunction>("new"); object[] ret2 = luaNew.Call(transform); scriptEnv = ret2[0] as LuaTable; luaNew.Dispose(); lua_class.Dispose(); Init <T>(param, ins); return(scriptEnv); }
/// <summary> /// Try to load script and init. /// Script will be cached, /// But in development, script cache can be clear, which will be load and init in the next time /// /// 开发阶段经常要使用Lua热重载,热重载过后,要确保OnInit重新执行 /// </summary> bool CheckInitScript(bool showWarn = false) { if (!LuaModule.CacheMode) { ClearLuaTableCache(); } var relPath = UILuaPath; object scriptResult; if (!LuaModule.Instance.TryImport(relPath, out scriptResult)) { if (showWarn) { Log.LogWarning("Import UI Lua Script failed: {0}", relPath); } return(false); } Debuger.Assert(scriptResult is LuaTable, "{0} Script Must Return Lua Table with functions!", UITemplateName); _luaTable = scriptResult as LuaTable; var newFuncObj = _luaTable.Get <LuaFunction>("new"); // if a New function exist, new a table! if (newFuncObj != null) { #if SLUA var newTableObj = (newFuncObj as LuaFunction).call(this); _luaTable = newTableObj as LuaTable; #else var newTableObj = (newFuncObj as LuaFunction).Call(this); _luaTable = newTableObj[0] as LuaTable; #endif } #if SLUA SetOutlet_Slua(_luaTable); #else SetOutlet(_luaTable); #endif var luaInitObj = _luaTable.Get <LuaFunction>("OnInit"); Debuger.Assert(luaInitObj is LuaFunction, "Must have OnInit function - {0}", UIName); // set table variable `Controller` to this #if SLUA _luaTable["Controller"] = this; (luaInitObj as LuaFunction).call(_luaTable, this); #else _luaTable.SetInPath("Controller", this); (luaInitObj as LuaFunction).Call(_luaTable, this); #endif return(true); }
private static Dictionary <object, Type> create_type_map(LuaTable tb) { Dictionary <object, Type> __type_map__ = null; tb.Get <string, Dictionary <object, Type> >("__type_map__", out __type_map__); if (__type_map__ == null) { __type_map__ = new Dictionary <object, Type>(); tb.Set <string, Dictionary <object, Type> >("__type_map__", __type_map__); } return(__type_map__); }
public void SetSkillActionSpeed(string strAction, float speed, LuaTable skillDesc) { float scale = 1f; if (m_AnimationActor != null && skillDesc != null && skillDesc.Get <int>("showtype") == 2 && m_AnimationActor.mActorType == ActorType.AT_BOSS) { scale = m_AnimationActor.NormalAttackSpeedScale; } SetActionSpeed(strAction, speed * scale); }
void Awake() { scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv); Action luaAwake = scriptEnv.Get <Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } luaEnv.AddLoader((ref string filename) => { var result = ABMgr.GetLuaContent(filename + ".lua"); if (result) { return(result.bytes); } return(null); }); }
protected void Awake() { if (!string.IsNullOrEmpty(luaScrpitPath)) { LuaEnv luaEnv = LuaBoot.luaEnv; //_scriptEnv = luaEnv.NewTable(); //LuaTable meta = luaEnv.NewTable(); //meta.Set("__index",luaEnv.Global); //_scriptEnv.SetMetaTable(meta); //meta.Dispose(); //_scriptEnv.Set("self", this); string luaStr = SimpleLoader.LoadLua(luaScrpitPath); // string luaStr = string.Format("require('{0}')",luaScrpitPath); // Debug.Log("lua str is " + luaStr); _scriptEnv = null; object [] ret = luaEnv.DoString(luaStr, "LuaBehaviour"); if (ret != null) { _scriptEnv = ret[0] as LuaTable; _scriptEnv.Set("monobehaviour", this); Action <LuaTable> luaAwake = _scriptEnv.Get <Action <LuaTable> >("Awake"); _scriptEnv.Get("Start", out _luaStart); _scriptEnv.Get("Update", out _luaUpdate); _scriptEnv.Get("OnDestroy", out _luaOnDestroy); _scriptEnv.Get("OnEnable", out _luaOnEnable); _scriptEnv.Get("OnDisable", out _luaOnDisable); if (luaAwake != null) { luaAwake(_scriptEnv); } } } }
void Awake() { //获取LuaTable,要用luaEnv.NewTable(),这里会做一些排序,共用虚拟机等操作 scriptEnv = luaEnv.NewTable(); //key,value的方式,虚拟机环境对应的key值一定要是这个“__index”, //在xlua的底层,获取LuaTable所属虚拟机的环境是get的时候,用的key是这个名字,所以不能改 // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突 LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); //将有虚拟机和全局环境的table绑定成他自己的metatable scriptEnv.SetMetaTable(meta); //值已经传递过去了,就释放他 meta.Dispose(); //这里的"self"和上面的"__index"是一个道理。将c#脚本绑定到LuaTable scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } //执行lua语句,三个参数的意思分别是lua代码,lua代码在c#里的代号,lua代码在lua虚拟机里的代号 luaEnv.DoString(luaScript.text, "LuaTestScript", scriptEnv); //xlua搞了这么久,也就是为了最后这几个锤子,c#调用lua里的方法。 //总结起来一句话,通过luatable这个类来完成c#调用Lua //怎样完成这一步呢?就是获取luatable对象,配置lua虚拟机,配置虚拟机环境,绑定c#代码,最后执行lua语句 Action luaAwake = scriptEnv.Get <Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
protected virtual void Awake() { scriptEnv = luaEnv.NewTable(); // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突 LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); Debug.Log(this.name + "Set Self!!"); if (injections != null) { foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } } if (!string.IsNullOrEmpty(luaScriptPath)) { luaScript = Resources.Load <TextAsset>(luaScriptPath); } componentDic.Add(transform.name, luaEnv.DoString(luaScript.text, luaScript.name, scriptEnv)); Debug.Log(transform.name); luaEnv.Global.Set("ComponentTable", componentDic); Action luaAwake = scriptEnv.Get <Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
void Start() { GameObject.DontDestroyOnLoad(this.gameObject); //CS init TimerMgr.Initilize(); //计时器 AtlasMgr.Instance.initialize(); //图集管理器初始化 ResMgr.Instance.initialize(); //资源接口管理类初始化 ManifestMgr.Instance.initialize(); //依赖文件初始化 PoolMgr.Instance.initialize(); //对象池初始化 LoaderMgr.Instance.initialize(); //加载管理器初始化 UIMgr.Instance.initialize(); //画布初始化 不需要初始化 //Lua init luaAgent = new LuaEnv(); //全局lua代理 luaAgent.DoString("require 'LuaInit'"); //Lua初始化 在Lua那边 scriptEnv = luaAgent.NewTable(); LuaTable meta = luaAgent.NewTable(); meta.Set("__index", luaAgent.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } luaAgent.DoString("require 'LuaBehavior'", "LuaBehaviour", scriptEnv); // Action luaAwake = scriptEnv.Get<Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("onTick", out luaTick); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaStart != null) { luaStart(); } // initClock(); }
private void Awake() { // XLuaEnvironment.AddLoader(load); XLuaEnvironment.OnDispose += LuaDispose; scriptEnv = XLuaEnvironment.NewTable(); // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突 LuaTable meta = XLuaEnvironment.NewTable(); meta.Set("__index", XLuaEnvironment.GlobalTable); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("this", this); foreach (var injection in injections) { scriptEnv.Set(injection.Key, injection.value); } XLuaEnvironment.DoString(luaScript.text, "LuaTestScript", scriptEnv); luaAwake = scriptEnv.Get <Action>("Awake"); luaOnEnable = scriptEnv.Get <Action>("OnEnable"); luaStart = scriptEnv.Get <Action>("Start"); luaUpdate = scriptEnv.Get <Action>("Update"); luaOnDisable = scriptEnv.Get <Action>("OnDisable"); luaOnDestroy = scriptEnv.Get <Action>("OnDestroy"); if (luaAwake != null) { luaAwake(); luaAwake = null; } }