Пример #1
0
 /// <summary>
 /// 刷新UI栈
 /// </summary>
 public void OnUIDestroy(LuaBehaviour behaviour)
 {
     if (uiStack.Contains(behaviour))
     {
         uiStack.Remove(behaviour);
     }
     RefreshStack();
 }
Пример #2
0
 /// <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();
 }
Пример #3
0
 /// <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);
         }
     }
 }
Пример #4
0
 /// <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;
         }
     }
 }
Пример #5
0
 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));
     }
 }
Пример #6
0
 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));
     }
 }
Пример #7
0
 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));
     }
 }
Пример #8
0
 /// <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);
 }
Пример #9
0
 /// <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);
 }
Пример #10
0
    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"));
        }
    }
Пример #11
0
    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"));
        }
    }
Пример #12
0
    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"));
        }
    }
Пример #13
0
    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"));
        }
    }
Пример #14
0
    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"));
        }
    }
Пример #15
0
    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"));
        }
    }
Пример #16
0
    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"));
        }
    }
Пример #17
0
    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"));
        }
    }
Пример #18
0
 /// <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);
     }
 }
Пример #19
0
 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;
     }
 }