/// <summary> 资源单元加载器 /// resId:资源的根目录 /// abRoot:unity中 对应打包Packager 打包的资源根目录位置 /// LuaFunction: 加载中的结束及进度回调 /// </summary> internal ResLoader(string resId, string abRoot, LuaInterface.LuaFunction finish, LuaInterface.LuaFunction progress, string extName = AppConst.ExtName) { this.resId = resId; this.abName = abRoot + resId + extName; this.finishLuaCallback = finish; this.progressLuaCallback = progress; }
public void LoadScene(string sceneId, LuaInterface.LuaFunction finishCallback, LuaInterface.LuaFunction progressCallback, bool useLocal = false) { ResLoader loader = null; string abName = sceneRoot + sceneId + AppConst.ExtName; if (finishCallback == null) { loader = new ResLoader(sceneId, sceneRoot, finishCallback, progressCallback); if (!PreLoadScene(loader)) { return; } } else { if (preLoaderMap.ContainsKey(abName)) { loader = preLoaderMap[abName]; preLoaderMap.Remove(abName); loader.finishLuaCallback = finishCallback; loader.progressLuaCallback = progressCallback; } else { loader = new ResLoader(sceneId, sceneRoot, finishCallback, progressCallback); } } LoadSceneResHandler(loader, useLocal); //LoadSceneResHandler(new ResLoader(sceneId, sceneRoot, finishCallback, progressCallback), useLocal); }
private static IEnumerator HttpGet(string url, bool strResult, LuaInterface.LuaFunction func) { WWW www = new WWW(url); yield return(www); if (www.error != null) { Debugger.LogError("n http get send error->" + www.error); } else { if (www.bytes != null) { if (strResult) { string data = System.Text.Encoding.UTF8.GetString(www.bytes); Debug.LogError("http get re->" + data); LuaManager.CallFunc_V(func, data); } else { LuaManager.CallFunc_V(func, www.bytes); } } } www.Dispose(); }
private static TweenValue GenTween(float duration, LuaInterface.LuaFunction func, int param) { int index = -1; if (idles.Count > 0) { index = idles.Dequeue(); } if (index < 0) { index = pool.Count; Info info = new Info(index); pool.Add(info); } Info cur = pool[index]; cur.func = func; cur.funcParam = param; cur.SetActive(true); TweenValue tween = TweenValue.Begin <TweenValue>(cur.go, duration); tween.SetDelegateFunc(cur.TweenCallFunc); return(tween); }
public static void ShowUI(string name, int index, LuaInterface.LuaFunction showUICall, int scriptCallParam) { UIFrame ui = GetUI(name, index); ui.SetScriptShowCall(showUICall, scriptCallParam); ProcessUIShow(ui, true); }
public static void Ping(string ip, LuaInterface.LuaFunction func, int funcID) { if (func == null) { return; } NetPing ping = GenPing(); if (ping == null) { Debug.LogError("ping num is to much"); return; } if (Config.Detail_Debug_Log()) { Debug.Log("----------net ping 0->" + ip); } CoroutineHelper.CreateCoroutineHelper(ping.PingConnect(ip, (state, delay) => { ping.index = -1; LuaManager.CallFunc_V(func, state, delay, funcID); })); }
private void OnDisable() { if (uiData == null) { return; } UIManager.ResetUIAlpha(this); scriptShowUICall = null; UISpriteData data = null; for (int i = 0, count = uiData.sprites.Count; i < count; i++) { data = uiData.sprites[i]; SetAtlas(data, false); } #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnDisable", this); #elif LUASCRIPT if (lua_OnDisable == null) { lua_OnDisable = LuaManager.GetFunction(name + ".OnDisable"); } if (lua_OnDisable != null) { LuaManager.CallFunc_V(lua_OnDisable, this); } #endif }
internal void SetScriptShowCall(LuaInterface.LuaFunction showCall, int scriptCallParam) { #if LUASCRIPT scriptShowUICall = showCall; this.scriptCallParam = scriptCallParam; #endif }
/// <summary> /// 添加lua单机事件 /// </summary> public static void AddClick(GameObject go, System.Object luafuc) { //UIEventListener.Get(go).onClick += delegate(GameObject o) { LuaInterface.LuaFunction func = (LuaInterface.LuaFunction)luafuc; func.Call(); }; }
void CallLuaFunc(LuaInterface.LuaFunction luaFun) { if (luaFun != null) { luaFun.Call(); luaFun.Dispose(); luaFun = null; } }
private void InitEditorActor() { _setActor = LuaClient.GetMainState().GetFunction("SetActor"); ResetActorGo(); for (int i = 0; i < _actorTypes.Count; i++) { SetActor(_actorTypes[i], _actorNames[i], _actorGos[i]); } }
public static Timer LuaCreateTimer(float interval, int count, int param) { if (interval <= 0) { return(null); } if (callLuaFunc == null) { callLuaFunc = LuaManager.GetFunction("TimerMgr.Back"); } if (callLuaFunc == null) { return(null); } TD td; if (disposeQueue.Count > 0) { disposeQueue.Dequeue(out td); if (td != null) { td.gameObject.SetActive(true); } } else { GameObject go = new GameObject(); Object.DontDestroyOnLoad(go); td = go.AddComponent <TD>(); td.id = ++idx; } if (td == null) { return(null); } td.interval = interval; td.count = (short)count; td.doSomething = null; td.luaDoSth = callLuaFunc; td.param = param; Timer t = new Timer(); t.td = td; td.timer = t; td.StartTimer(); return(t); }
private void ShowUICallback() { #if LUASCRIPT if (scriptShowUICall != null) { LuaInterface.LuaFunction func = scriptShowUICall; scriptShowUICall = null; LuaManager.CallFunc_VX(func, scriptCallParam); scriptCallParam = -1; } #endif }
public void SetLuaHandler(LuaInterface.LuaTable lua_obj, LuaInterface.LuaFunction on_finish, LuaInterface.LuaFunction on_event) { LuaObj = lua_obj; OnFinish = on_finish; OnEvent = on_event; for (int i = 0; i < UiAinm.Length; i++) { UnregisterEventHandler(i, InternalOnEvent); RegisterEventHandler(i, InternalOnEvent); } }
public void TweenCallFunc(float factor, bool isFinished) { if (func != null) { LuaManager.CallFunc_VX(func, funcParam, factor, isFinished); } if (isFinished) { func = null; funcParam = -1; Dispose(this); } }
private void OnAdditiveSceneLoaded(string name) { #if LUASCRIPT if (luaAdditiveLoadOverFunc == null) { luaAdditiveLoadOverFunc = LuaManager.GetFunction("SceneManager.ListenAdditiveLoadOver"); } if (luaAdditiveLoadOverFunc != null) { LuaManager.CallFunc_VX(luaAdditiveLoadOverFunc, name); } #endif }
public override void Enter(string preStateName) { base.Enter(preStateName); loginSuccess = false; UFrameLuaClient.GetMainState().DoFile("UFrame/Game/GameState/StateLogin.lua"); luaMsgTable = UFrameLuaClient.GetMainState().GetTable("MessageCode"); luaFunEnter = UFrameLuaClient.GetMainState().GetFunction("StateLogin.Enter"); luaFunLeave = UFrameLuaClient.GetMainState().GetFunction("StateLogin.Leave"); CallLuaFunc(luaFunEnter); RegistLuaMessage(); }
public static GameObject LoadPrefab(string path, EnumAssetType assetType, LuaInterface.LuaFunction callBack) { GameObject obj = LoadAsset(path, typeof(GameObject), ".prefab", assetType, callBack) as GameObject; if (obj == null) { Debug.LogError("load prefab is null --path: " + path); } else { GameObject go = GameObject.Instantiate(obj); go.name = path; return(go); } return(obj); }
// for lua public static void SetOnClick(GameObject go, LuaInterface.LuaFunction luafunc) { if (go == null || luafunc == null) { Debug.LogError("UIEventListener SetOnClick: " + (go == null ? "param GameObject is null." : "param LuaFunction is null.")); return; } UnityEngine.UI.Button btn = go.GetComponent <UnityEngine.UI.Button>(); if (btn != null) { btn.onClick.AddListener(delegate(){ luafunc.Call(go); }); } else { Get(go).onClick = delegate(GameObject obj){ luafunc.Call(obj); }; } }
private void OnSceneWasLoaded() { if (!alive) { return; } if (loadStatus == LoadSceneStatus.END) { { loadStatus = LoadSceneStatus.NONE; sceneLoading = false; LuaContext.RefreshDelegateMap(); #if LUASCRIPT if (luaLoadOverFunc == null) { luaLoadOverFunc = LuaManager.GetFunction("SceneManager.ListenLoadOver"); } if (luaLoadOverFunc != null) { LuaManager.CallFunc_VX(luaLoadOverFunc, next); } #endif } } else if (loadStatus == LoadSceneStatus.BEGIN) { if (!sceneLoading) { sceneLoading = true; if (next != null) { Load(); } } } ClearSceneAsset(); Resources.UnloadUnusedAssets(); System.GC.Collect(); }
private void OnScroll(GameObject gameObject, float delta, int id) { if (listenOnSroll && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnScroll", gameObject, delta, id); #elif LUASCRIPT if (lua_OnScroll == null) { lua_OnScroll = LuaManager.GetFunction(name + ".OnScroll"); } if (lua_OnScroll != null) { LuaManager.CallFunc_V(lua_OnScroll, gameObject, delta, id); } #endif } }
private void OnDrag(GameObject gameObject, Vector2 delta, int id) { if (listenOnDrag && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnDrag", gameObject, delta, id); #elif LUASCRIPT if (lua_OnDrag == null) { lua_OnDrag = LuaManager.GetFunction(name + ".OnDrag"); } if (lua_OnDrag != null) { LuaManager.CallFunc_V(lua_OnDrag, gameObject, delta, id); } #endif } }
private void OnKey(GameObject gameObject, KeyCode key, int id) { if (listenOnKey && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnKey", gameObject, key, id); #elif LUASCRIPT if (lua_OnKey == null) { lua_OnKey = LuaManager.GetFunction(name + ".OnKey"); } if (lua_OnKey != null) { LuaManager.CallFunc_V(lua_OnKey, gameObject, key, id); } #endif } }
private void OnTooltip(GameObject gameObject, bool show, int id) { if (listenOnTooltip && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnTooltip", gameObject, show, id); #elif LUASCRIPT if (lua_OnTooltip == null) { lua_OnTooltip = LuaManager.GetFunction(name + ".OnTooltip"); } if (lua_OnTooltip != null) { LuaManager.CallFunc_V(lua_OnTooltip, gameObject, show, id); } #endif } }
private void OnDoubleClick(GameObject gameObject, int id) { if (listenOnDoubleClick && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnDoubleClick", gameObject, id); #elif LUASCRIPT if (lua_OnDoubleClick == null) { lua_OnDoubleClick = LuaManager.GetFunction(name + ".OnDoubleClick"); } if (lua_OnDoubleClick != null) { LuaManager.CallFunc_V(lua_OnDoubleClick, gameObject, id); } #endif } }
private void OnSelect(GameObject gameObject, bool selected, int id) { if (listenOnSelect && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnSelect", gameObject, selected, id); #elif LUASCRIPT if (lua_OnSelect == null) { lua_OnSelect = LuaManager.GetFunction(name + ".OnSelect"); } if (lua_OnSelect != null) { LuaManager.CallFunc_V(lua_OnSelect, gameObject, selected, id); } #endif } }
private void OnHover(GameObject gameObject, bool isOver, int id) { if (listenOnHover && !UIManager.IsFocusEventLocked(uiID, id)) { #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnHover", gameObject, isOver, id); #elif LUASCRIPT if (lua_OnHover == null) { lua_OnHover = LuaManager.GetFunction(name + ".OnHover"); } if (lua_OnHover != null) { LuaManager.CallFunc_V(lua_OnHover, gameObject, id); } #endif } }
private void OnEnable() { if (uiData == null) { return; } if (lowLayerAlpha < 1) { UIManager.SetLessLayerUIAlpha(layer, lowLayerAlpha); } UIManager.ProcessUIAlpha(this); UISpriteData data = null; for (int i = 0, count = uiData.sprites.Count; i < count; i++) { data = uiData.sprites[i]; SetAtlas(data, true); } UITextureData utd = null; for (int i = 0, count = uiData.textures.Count; i < count; i++) { utd = uiData.textures[i]; SetTexture(utd, true); } #if JSSCRIPT jsRepresentClass.CallFunctionByFunName("OnEnable", this); #elif LUASCRIPT if (lua_OnEnable == null) { lua_OnEnable = LuaManager.GetFunction(name + ".OnEnable"); } if (lua_OnEnable != null) { LuaManager.CallFunc_V(lua_OnEnable, this); } #endif }
private static double ExecuteLuaIntfCompiled(string sScript, int iLoops) { using (LuaInterface.Lua lua = new LuaInterface.Lua()) { lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest")); lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho")); LuaInterface.LuaFunction f = lua.LoadString(sScript, "test"); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < iLoops; i++) { DebugOut("LuaIntf-C", i, f.Call()); } return(sw.ElapsedMilliseconds / (double)iLoops); } }
private void LoadAssetOver() { if (uiData == null) { Create(); } else { ProcessShow(true); Prepare(); if (lua_OnShowOver == null) { lua_OnShowOver = LuaManager.GetFunction(name + ".OnShowOver"); } if (lua_OnShowOver != null) { LuaManager.CallFunc_V(lua_OnShowOver, this); } } }