static int set_Instance(IntPtr L) { try { CFramework.DebugManager arg0 = (CFramework.DebugManager)ToLua.CheckObject <CFramework.DebugManager>(L, 2); CFramework.BaseManager <CFramework.DebugManager> .Instance = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Init(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); CFramework.DebugManager obj = (CFramework.DebugManager)ToLua.CheckObject <CFramework.DebugManager>(L, 1); obj.Init(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// /// </summary> void OnDestroy() { if (this._table != null) { DebugManager.Log(_baseView.Id + " Destroy"); LuaFunction fun = this._table.GetLuaFunction("Destroy"); if (fun != null) { fun.Call(this._table); } this._table.Dispose(); this._table = null; } if (this._baseView != null) { this._baseView.Dispose(); this._baseView = null; } }
public void TestLua() { //this._lua.DoFile("test.lua"); this._lua.DoString(@" local cla = {1,2,3,4,5} function F1() print(333333333333333333333) end "); //LuaFunction lf = this._lua.GetFunction("Main1"); //lf.Call(); DebugManager.Log("//////cla////////" + (this._lua.GetTable("cla") == null).ToString()); //Debug.Log("//////////////" + (this._lua.GetTable("s1") == null).ToString()); //return this._lua.GetTable("LoginScene"); }
/// <summary> /// 添加打入Lua代码的AssetBundle /// </summary> /// <param name="bundle"></param> public void AddBundle(string path, string bundleName) { AssetBundle bundle = null; if (Application.platform == RuntimePlatform.Android) { if (path.StartsWith("file://")) { path = path.Replace("file://", string.Empty); } bundle = AssetBundle.LoadFromFile(path); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { if (path.StartsWith("file://")) { path = path.Replace("file://", string.Empty); } bundle = AssetBundle.LoadFromFile(path); } else { if (File.Exists(path) == true) { bundle = AssetBundle.LoadFromMemory(File.ReadAllBytes(path)); } } if (bundle != null) { base.AddSearchBundle(bundleName.ToLower(), bundle); } else { DebugManager.LogError("AddSearchBundle Error:" + path + "," + bundleName); } }
/// <summary> /// 检查游戏更新 /// </summary> IEnumerator StartUpdate() { _Txt_msg.text = "解压安装包资源完成, 开始检查游戏更新"; DebugManager.Log(_Txt_msg.text); string cdnUrl = "file://F:/LocalSvn/TestCdnServer/"; WWW www = new WWW(cdnUrl + "version.t"); yield return(www); DebugManager.Log("server version:" + www.text); string serverVersion = www.text; www.Dispose(); www = new WWW(FileUtil.Instance.GetWritePath("version.t")); yield return(www); if (serverVersion.Equals(www.text)) { //版本一致,进入下一步 _Txt_msg.text = "更新版本完成"; DebugManager.Log(_Txt_msg.text); InitApp(); } else { _Txt_msg.text = "检测到新版本,准备更新"; DebugManager.Log(_Txt_msg.text); CopyFiles(cdnUrl, new string[] { "file.t" }, delegate() { StartCoroutine(CheckAndUpdateFile()); }); } www.Dispose(); }
/// <summary> /// /// </summary> public void New(LuaTable table, BaseView baseView) { this._table = table; this._baseView = baseView; if (this._baseView != null) { this._baseView.LuaBehaviour = this; } if (this._table != null) { DebugManager.Log(_baseView.Id + " Awake"); LuaFunction fun = this._table.GetLuaFunction("OnAwake"); if (fun != null) { fun.Call(this._table, baseView); } } this.UpdateControlBind(); }
/// <summary> /// /// </summary> /// <param name="viewId"></param> /// <param name="parent"></param> /// <param name="abName"></param> /// <param name="assetName"></param> /// <param name="callback"></param> public void NewSpineAni(string viewId, GameObject parent, string abName, string assetName, LuaFunction callback, string actionName = "", bool isLoop = true) { ResourceManager.Instance.LoadPrefabAsync(viewId, abName, delegate(AssetBundle assetBundle) { if (assetBundle == null) { DebugManager.LogError("NewSpineAni Error:下载资源失败!" + abName + "," + assetName); return; } //foreach (UnityEngine.Object obj in assetBundle.LoadAllAssets()) { // DebugManager.Log(obj.name); //} SkeletonAnimation animation = createSpineAni(parent, assetBundle, assetName, actionName, isLoop); if (callback != null) { callback.Call(animation); callback.Dispose(); } }); }
/// <summary> /// 移除控件事件 /// </summary> /// <param name="viewId"></param> /// <param name="eventId"></param> /// <param name="target"></param> public void RemoveEvent(string viewId, int eventId, Transform target, string fullEventId = null) { if (target == null) { DebugManager.LogError("RemoveEvent Error:target is null!"); return; } Dictionary <string, EventData> viewEventList = null; this._eventList.TryGetValue(viewId, out viewEventList); if (fullEventId == null) { fullEventId = viewId + "_" + target.name + "_" + eventId.ToString(); } if (viewEventList != null && viewEventList.ContainsKey(fullEventId) == true) { switch (eventId) { case 1: //click事件 target.GetComponent <Button>().onClick.RemoveAllListeners(); break; case 2: //Scroll OnValueChanged target.GetComponent <ScrollRect>().onValueChanged.RemoveAllListeners(); break; case 3: target.GetComponent <Toggle>().onValueChanged.RemoveAllListeners(); break; case 4: target.GetComponent <Slider>().onValueChanged.RemoveAllListeners(); break; case 5: break; case 6: break; case 7: target.GetComponent <InputField>().onEndEdit.RemoveAllListeners(); break; case 8: target.GetComponent <InputField>().onValueChanged.RemoveAllListeners(); break; case 9: target.GetComponent <Dropdown>().onValueChanged.RemoveAllListeners(); break; } EventData eventData = viewEventList[fullEventId]; eventData.obj = null; if (eventData.luaFunc != null) { //eventData.luaFunc.Dispose(); eventData.luaFunc = null; } viewEventList.Remove(fullEventId); } }
/// <summary> /// 添加控件事件 /// </summary> /// <param name="viewId"></param> /// <param name="eventId"></param> /// <param name="target"></param> /// <param name="callback"></param> public void AddEvent(string viewId, int eventId, Transform target, LuaFunction callback, string fullEventId = null) { if (target == null || callback == null) { DebugManager.LogError("AddEvent Error:target or callback is null!" + viewId + "," + eventId); return; } Dictionary <string, EventData> viewEventList = null; this._eventList.TryGetValue(viewId, out viewEventList); if (viewEventList == null) { viewEventList = new Dictionary <string, EventData>(); this._eventList.Add(viewId, viewEventList); } if (fullEventId == null) { fullEventId = viewId + "_" + target.name + "_" + eventId.ToString(); } EventData eventData = new EventData(); eventData.obj = target.gameObject; eventData.luaFunc = callback; if (viewEventList.ContainsKey(fullEventId) == true) { DebugManager.LogError("AddEvent Error:重复的事件ID注册!" + fullEventId); return; } viewEventList.Add(fullEventId, eventData); switch (eventId) { case 1: //click事件 Button btn = target.GetComponent <Button>(); if (btn == null) { DebugManager.LogError("AddEvent Error:对象没有添加Button组件!" + target.name); return; } btn.onClick.AddListener( delegate() { callback.Call(target); }); break; case 2: //Scroll OnValueChanged ScrollRect scrollRect = target.GetComponent <ScrollRect>(); if (scrollRect == null) { DebugManager.LogError("AddEvent Error:对象没有添加ScrollRect组件!" + target.name); return; } scrollRect.onValueChanged.AddListener( delegate(Vector2 v) { callback.Call(target, v); }); break; case 3: Toggle toggle = target.GetComponent <Toggle>(); if (toggle == null) { DebugManager.LogError("AddEvent Error:对象没有添加Toggle组件!" + target.name); return; } toggle.onValueChanged.AddListener( delegate(bool check) { callback.Call(target, check); } ); break; case 4: Slider slider = target.GetComponent <Slider>(); if (slider == null) { DebugManager.LogError("AddEvent Error:对象没有添加Slider组件!" + target.name); return; } slider.onValueChanged.AddListener( delegate(float v) { callback.Call(target, v); } ); break; case 5: //SkeletonGraphic skeleton = target.GetComponent<SkeletonGraphic>(); //if (skeleton == null) //{ // DebugManager.Instance.LogError("AddEvent Error:对象没有添加SkeletonGraphic组件!"+ target.name); // return; //} //skeleton.AnimationState.Event += delegate (Spine.TrackEntry trackEntry, Spine.Event e) //{ // callback.Call(target, e.Data.Name); //}; //skeleton.AnimationState.Complete += delegate (Spine.TrackEntry trackEntry) //{ // callback.Call(target, "End"); //}; break; case 6: break; case 7: InputField field = target.GetComponent <InputField>(); if (field == null) { DebugManager.LogError("AddEvent Error:对象没有添加InputField组件!" + target.name); return; } field.onEndEdit.AddListener(delegate(string txt) { callback.Call(target, txt); }); break; case 8: InputField field1 = target.GetComponent <InputField>(); if (field1 == null) { DebugManager.LogError("AddEvent Error:对象没有添加InputField组件!" + target.name); return; } field1.onValueChanged.AddListener(delegate(string txt) { callback.Call(target, txt); }); break; case 9: Dropdown dropdown = target.GetComponent <Dropdown>(); if (dropdown == null) { DebugManager.LogError("AddEvent Error:对象没有添加Dropdown组件!" + target.name); return; } dropdown.onValueChanged.AddListener(delegate(int v) { callback.Call(target, v); }); break; } }
/// <summary> /// 加载场景 /// </summary> /// <param name="loadingWindowClass"></param> /// <returns></returns> private IEnumerator LoadingScene(LuaTable loadingWindowClass) { int showProgress = 80; while (showProgress < 100) { if (showProgress < 30) { showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } else if (showProgress < 90) { yield return(new WaitUntil(delegate() { return _preloadIsEnd; })); showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } else { yield return(new WaitUntil(delegate() { return _prog.progress >= 0.9f; })); showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } } //-----------------------------预加载资源加载完成,进入场景------------------------------ _prog.allowSceneActivation = true; //如果加载完成,可以进入场景 Scene scene = SceneManager.GetSceneByName(_id); yield return(new WaitUntil(delegate() { return scene.isLoaded; })); DebugManager.Log("enter scene:" + scene.name); GameObject[] objs = scene.GetRootGameObjects(); foreach (GameObject go in objs) { DebugManager.Log("go.name:" + go.name); if (go.name.Equals("Canvas")) { _loadBaseScene = new BaseScene(_id, _preloadList, _completeCallback, _progressCallback, _isCache, go.transform); LuaComponent luaComponent = go.AddComponent <LuaComponent>(); luaComponent.New(_luaSceneClass, _loadBaseScene); _completeCallback(_loadBaseScene); this.CurrScene = _loadBaseScene; _loadBaseScene = null; _id = null; break; } } }
/// <summary> /// /// </summary> private void InitLuaBundle() { if (this._loader.beZip == false) { return; } string[] files = null; if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(FileUtil.Instance.GetResPath("file.t")); while (!www.isDone) { } files = www.text.Split(new string[] { "\r\n" }, StringSplitOptions.None); www.Dispose(); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { WWW www = new WWW(FileUtil.Instance.GetResPath("file.t")); while (!www.isDone) { } DebugManager.Log("file.t content:" + www.text); files = www.text.Split(new string[] { "\r\n" }, StringSplitOptions.None); DebugManager.Log("files content:" + www.text); www.Dispose(); } else { files = File.ReadAllLines(FileUtil.Instance.GetResPath("file.t")); } DebugManager.Log("file.t Length:" + files.Length); for (int i = 0; i < files.Length; i++) { string[] keyValue = files[i].Split('|'); string fileName = keyValue[0]; DebugManager.Log("for file======>:" + fileName); if (Path.GetExtension(fileName) == ".bytes") { string bundleName = ""; if (fileName.StartsWith("src/tolua/") == true) { bundleName = fileName.Replace("src/tolua/", string.Empty); } else if (fileName.StartsWith("src/gameapp/lua/") == true) { bundleName = fileName.Replace("src/gameapp/lua/", string.Empty); } else if (fileName.StartsWith("src/") == true) { bundleName = fileName.Replace("src/", string.Empty); } //DebugManager.Log("InitLuaBundle:"+ bundleName); string abPath = FileUtil.Instance.GetWritePath(fileName); this._loader.AddBundle(abPath, bundleName); } } }
static void Build(BuildTarget buildTarget) { string U3D_CODE_ROOT = Environment.GetEnvironmentVariable("U3D_CODE_ROOT"); string outputPath = Replace((U3D_CODE_ROOT + "/StreamingAssets/src")); string tempPath = Replace((U3D_CODE_ROOT + "/luaroot")); FileTool.CopyLuaFolderTo(Replace(U3D_CODE_ROOT + "/GameApp/Lua"), tempPath); FileTool.CopyLuaFolderTo(Replace(U3D_CODE_ROOT + "/Extends/Plugins/ToLua/Lua"), tempPath + "/tolua"); AssetDatabase.Refresh(); try { //检查是否存在目的目录 if (Directory.Exists(outputPath)) { FileTool.DeleteAll(outputPath); AssetDatabase.Refresh(); } Directory.CreateDirectory(outputPath); } catch (Exception e) { DebugManager.Log(e.Message); } //FileTool.CopyFolderTo(U3D_CODE_ROOT + "/GameApp/Lua", U3D_CODE_ROOT + "/StreamingAssets/src/lua"); //FileTool.CopyFolderTo(U3D_CODE_ROOT + "/GameApp/Lua", U3D_CODE_ROOT + "/StreamingAssets/src/lua"); FileTool.CopyFolderTo(U3D_CODE_ROOT + "/GameApp/Protobuf", U3D_CODE_ROOT + "/StreamingAssets/src/protobuf"); PackLuaDir(tempPath); //根据BuildSetting里面所激活的平台进行打包 BuildPipeline.BuildAssetBundles(outputPath, 0, buildTarget); AssetDatabase.Refresh(); //FileTool.DeleteAll(tempPath); //生成file文件 string filePaht = U3D_CODE_ROOT + "/StreamingAssets/file.t"; if (File.Exists(filePaht)) { File.Delete(filePaht); } StreamWriter streamWriter = File.CreateText(filePaht); writeFile(U3D_CODE_ROOT + "\\StreamingAssets", streamWriter, Replace(U3D_CODE_ROOT + "/StreamingAssets/")); streamWriter.Close(); //复制json文件 FileTool.CopyLuaFolderTo(tempPath + "/config/battleSkill", outputPath + "/gameapp/lua/battleskill"); //复制pb文件 Debug.Log("生成lua完成"); }
IEnumerator DoRegisterPB(LuaFunction processCallback, LuaFunction completeCallback) { string configFilePath = ""; string pbDir = ""; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { pbDir = FileUtil.Instance.GetWritePath("protobuf/"); } else { pbDir = FileUtil.Instance.GetAssetsPath("GameApp/Protobuf/").Replace("file://", ""); } configFilePath = pbDir + "proto.config"; Debugger.Log(configFilePath); string configFileStr = ""; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { WWW www = new WWW(configFilePath); yield return(www); if (www.isDone) { configFileStr = www.text; yield return(0); } else { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + configFilePath); } www.Dispose(); } else { if (File.Exists(configFilePath) == true) { try { configFileStr = File.ReadAllText(configFilePath); } catch (Exception e) { DebugManager.LogError("DoRegisterPB Error:读取配置文件错误!" + e.Message); yield break; } } else { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + configFilePath); } } DebugManager.Log("configFileStr:" + configFileStr); string[] pClassCommandList = configFileStr.Split(','); string fpath = pbDir + "message.pb"; DebugManager.Log("读取注册PB文件:" + fpath); if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { WWW www = new WWW(fpath); yield return(www); if (www.isDone) { ByteBuffer data = new ByteBuffer(www.bytes); processCallback.Call(data); data.Close(); yield return(0); } else { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + fpath); } www.Dispose(); } else { try { ByteBuffer data = new ByteBuffer(File.ReadAllBytes(fpath)); processCallback.Call(data); data.Close(); } catch (Exception e) { DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + fpath + "\n error:\n" + e.Message); } } completeCallback.Call(pClassCommandList); completeCallback.Dispose(); processCallback.Dispose(); }
//设置一个回掉方法 private void BeCallFunc(string content) { DebugManager.Log("sdk回回调:" + content); callback.Call(content); }