public void LoadScript(string luaScriptName, object userData = null) { if (string.IsNullOrEmpty(luaScriptName)) { Log.Warning("Lua script name is invalid."); return; } string luaScriptAssetName = AssetUtility.GetLuaScriptAsset(luaScriptName); if (GameEntry.Base.EditorResourceMode) { if (!System.IO.File.Exists(luaScriptAssetName)) { string appendErrorMessage = string.Format("Can not find lua script '{0}'.", luaScriptAssetName); Debug.LogError(appendErrorMessage); //GameEntry.Event.Fire(this, ReferencePool.Acquire<LoadLuaScriptFailureEventArgs>().Fill(luaScriptName, luaScriptAssetName, appendErrorMessage, userData)); return; } InternalLoadLuaScript(luaScriptName, luaScriptAssetName, System.IO.File.ReadAllBytes(luaScriptAssetName), 0f, userData); } else { GameEntry.Resource.LoadAsset(luaScriptAssetName, m_LoadAssetCallbacks, new LuaScriptInfo(luaScriptName, userData)); } }
/// <summary> /// 重新加载指定的Lua脚本,只在编辑器状态下可用 /// </summary> public void LoadScriptInEditor(string luaScriptName, object userData = null) { if (GameEntry.Base.EditorResourceMode) { string luaScriptAssetName = AssetUtility.GetLuaScriptAsset(luaScriptName); if (!File.Exists(luaScriptAssetName)) { Log.Error("Can not find lua script '{0}'.", luaScriptAssetName); return; } InternalLoadLuaScript(luaScriptName, luaScriptAssetName, File.ReadAllBytes(luaScriptAssetName), 0f, userData); m_LuaEnv.DoString(string.Format("package.loaded[\"{0}\"] = nil", luaScriptName), luaScriptName); Debug.Log(luaScriptName); } }