/// <summary> /// 刷新UI栈 /// </summary> public void OnUIDestroy(LuaBehaviour behaviour) { if (uiStack.Contains(behaviour)) { uiStack.Remove(behaviour); } RefreshStack(); }
/// <summary> /// 清空删除栈内所有UI /// </summary> public void ClearAllUI() { for (int i = 0; i < uiStack.Count; i++) { LuaBehaviour behaviour = uiStack[i]; if (behaviour) { Destroy(behaviour.gameObject); } } uiStack.Clear(); }
/// <summary> /// 创建UI(destroyAssetBundle:当所有引用完全销毁后是否同时销毁AssetBundle) /// </summary> public void SpawnPrefab(string prefabPath, Transform parent, Action <GameObject, bool> callback, bool destroyABAfterSpawn = false, bool destroyABAfterAllSpawnDestroy = false) { if (string.IsNullOrEmpty(prefabPath)) { Debug.LogError("prefabPath为空"); return; } if (Config.UseAssetBundle) { string assetBundleName = "res/" + prefabPath.ToLower(); string prefabName = prefabPath; if (prefabPath.Contains("/")) { assetBundleName = prefabPath.Substring(0, prefabPath.LastIndexOf("/")); assetBundleName = "res/" + assetBundleName.Replace("/", "_").ToLower(); prefabName = prefabPath.Substring(prefabPath.LastIndexOf("/") + 1); } StartCoroutine(LoadAssetFromAssetBundle(assetBundleName, prefabName, (GameObject prefab) => { GameObject go = Instantiate(prefab); if (parent) { go.transform.SetParent(parent, false); } LuaBehaviour luaBehaviour = go.AddComponent <LuaBehaviour>(); luaBehaviour.assetBundleName = assetBundleName; luaBehaviour.prefabPath = prefabPath; luaBehaviour.destroyABAfterAllSpawnDestroy = destroyABAfterAllSpawnDestroy; if (callback != null) { callback(luaBehaviour.gameObject, false); } }, destroyABAfterSpawn)); } else { GameObject prefab = Resources.Load <GameObject>(prefabPath); GameObject go = Instantiate(prefab); if (parent) { go.transform.SetParent(parent, false); } LuaBehaviour luaBehaviour = go.AddComponent <LuaBehaviour>(); luaBehaviour.assetBundleName = ""; luaBehaviour.prefabPath = prefabPath; luaBehaviour.destroyABAfterAllSpawnDestroy = destroyABAfterAllSpawnDestroy; if (callback != null) { callback(luaBehaviour.gameObject, false); } } }
/// <summary> /// 不在栈顶的UI重新到栈顶显示 /// </summary> public void ResumeUI(GameObject go) { for (int i = 0; i < uiStack.Count; i++) { LuaBehaviour behaviour = uiStack[i]; if (behaviour.gameObject == go) { uiStack.RemoveAt(i); uiStack.Add(behaviour); RefreshStack(); break; } } }
static int SetUIID(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)ToLua.CheckObject <ToLuaUIFramework.LuaBehaviour>(L, 1); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); obj.SetUIID(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int SetLuaClazz(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)ToLua.CheckObject <ToLuaUIFramework.LuaBehaviour>(L, 1); LuaTable arg0 = ToLua.CheckLuaTable(L, 2); obj.SetLuaClazz(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int OnUIDestroy(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); ToLuaUIFramework.UIManager obj = (ToLuaUIFramework.UIManager)ToLua.CheckObject <ToLuaUIFramework.UIManager>(L, 1); ToLuaUIFramework.LuaBehaviour arg0 = (ToLuaUIFramework.LuaBehaviour)ToLua.CheckObject <ToLuaUIFramework.LuaBehaviour>(L, 2); obj.OnUIDestroy(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 当前层上面的层全是浮动层 /// </summary> /// <returns></returns> bool AllOverLayerIsFloat(int currIndex) { for (int i = 0; i < uiStack.Count; i++) { LuaBehaviour behaviour = uiStack[i]; if (i > currIndex) { if (!behaviour.isFloat) { return(false); } } } return(true); }
/// <summary> /// 创建UI /// </summary> public void SpawnUI(string prefabPath, Transform parent, Action <GameObject, bool> callback, bool keepActive = false, bool isFloat = false, bool destroyABAfterSpawn = false, bool destroyABAfterAllSpawnDestroy = false) { if (string.IsNullOrEmpty(prefabPath)) { Debug.LogError("prefabPath为空"); return; } //UI当单例使用,先从站内查找,有则直接显示,从栈顶往下找,更快找到 for (int i = uiStack.Count - 1; i >= 0; i--) { LuaBehaviour luaBehaviour = uiStack[i]; if (luaBehaviour.prefabPath.Equals(prefabPath)) { if (luaBehaviour.transform.parent != parent) { luaBehaviour.transform.SetParent(parent, false); } if (i < uiStack.Count - 1) { uiStack.RemoveAt(i); uiStack.Add(luaBehaviour); } RefreshStack(); luaBehaviour.keepActive = keepActive; luaBehaviour.isFloat = isFloat; luaBehaviour.destroyABAfterAllSpawnDestroy = destroyABAfterAllSpawnDestroy; if (callback != null) { callback(luaBehaviour.gameObject, true); } return; } } //开始创建 ResManager.instance.SpawnPrefab(prefabPath, parent, (GameObject go, bool isSingletonActiveCallback) => { LuaBehaviour luaBehaviour = go.GetComponent <LuaBehaviour>(); luaBehaviour.keepActive = keepActive; luaBehaviour.isFloat = isFloat; //处理入栈 uiStack.Add(luaBehaviour); RefreshStack(); if (callback != null) { callback(go, isSingletonActiveCallback); } }, destroyABAfterSpawn, destroyABAfterAllSpawnDestroy); }
static int get_prefabPath(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; string ret = obj.prefabPath; LuaDLL.lua_pushstring(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index prefabPath on a nil value")); } }
static int set_sortObjects(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; System.Collections.Generic.List <ToLuaUIFramework.LuaBehaviour.SortObject> arg0 = (System.Collections.Generic.List <ToLuaUIFramework.LuaBehaviour.SortObject>)ToLua.CheckObject(L, 2, typeof(System.Collections.Generic.List <ToLuaUIFramework.LuaBehaviour.SortObject>)); obj.sortObjects = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index sortObjects on a nil value")); } }
static int set_destroyABAfterAllSpawnDestroy(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; bool arg0 = LuaDLL.luaL_checkboolean(L, 2); obj.destroyABAfterAllSpawnDestroy = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index destroyABAfterAllSpawnDestroy on a nil value")); } }
static int set_isFloat(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; bool arg0 = LuaDLL.luaL_checkboolean(L, 2); obj.isFloat = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index isFloat on a nil value")); } }
static int get_sortObjects(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; System.Collections.Generic.List <ToLuaUIFramework.LuaBehaviour.SortObject> ret = obj.sortObjects; ToLua.PushSealed(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index sortObjects on a nil value")); } }
static int get_destroyABAfterAllSpawnDestroy(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; bool ret = obj.destroyABAfterAllSpawnDestroy; LuaDLL.lua_pushboolean(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index destroyABAfterAllSpawnDestroy on a nil value")); } }
static int get_isFloat(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; bool ret = obj.isFloat; LuaDLL.lua_pushboolean(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index isFloat on a nil value")); } }
static int set_prefabPath(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ToLuaUIFramework.LuaBehaviour obj = (ToLuaUIFramework.LuaBehaviour)o; string arg0 = ToLua.CheckString(L, 2); obj.prefabPath = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index prefabPath on a nil value")); } }
/// <summary> /// 也可以由Lua调用刷新,用于Lua动态给Canvas指定Camera后重新刷新调用 /// </summary> public void RefreshStack() { currVisibleUIList.Clear(); for (int i = 0; i < uiStack.Count; i++) { LuaBehaviour behaviour = uiStack[i]; if (i == uiStack.Count - 1) { if (!behaviour.gameObject.activeInHierarchy) { behaviour.gameObject.SetActive(true); } } else { if (AllOverLayerIsFloat(i)) { if (!behaviour.gameObject.activeInHierarchy) { behaviour.gameObject.SetActive(true); } } else { if (behaviour.gameObject.activeInHierarchy) { behaviour.gameObject.SetActive(behaviour.keepActive); } } } if (behaviour.gameObject.activeInHierarchy) { currVisibleUIList.Add(behaviour); } } for (int i = 0; i < currVisibleUIList.Count; i++) { LuaBehaviour luaBehaviour = currVisibleUIList[i]; if (i > 0 && currVisibleUIList[i - 1].IsSetedOrder) { luaBehaviour.AddCanvas(); } luaBehaviour.SetOrders(i); } }
public SortObject(LuaBehaviour luaBehaviour, Canvas canvas, Renderer particleRenderer) { this.luaBehaviour = luaBehaviour; this.canvas = canvas; this.particle = particleRenderer; if (this.canvas) { originSort = this.canvas.sortingOrder; if (!this.canvas.overrideSorting && this.canvas.renderMode == RenderMode.ScreenSpaceCamera && this.canvas.worldCamera) { this.originDepth = this.canvas.worldCamera.depth; } } else if (this.particle) { originSort = this.particle.sortingOrder; } }