static int AddChildToTarget(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes <UnityEngine.Transform, UnityEngine.Transform>(L, 1)) { UnityEngine.Transform arg0 = (UnityEngine.Transform)ToLua.ToObject(L, 1); UnityEngine.Transform arg1 = (UnityEngine.Transform)ToLua.ToObject(L, 2); MonoExtendUtil.AddChildToTarget(arg0, arg1); return(0); } else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Transform, UnityEngine.Transform, UnityEngine.Vector3>(L, 1)) { UnityEngine.Transform arg0 = (UnityEngine.Transform)ToLua.ToObject(L, 1); UnityEngine.Transform arg1 = (UnityEngine.Transform)ToLua.ToObject(L, 2); UnityEngine.Vector3 arg2 = ToLua.ToVector3(L, 3); MonoExtendUtil.AddChildToTarget(arg0, arg1, arg2); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: MonoExtendUtil.AddChildToTarget")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 回收item到缓存中 /// </summary> private void RecycleCacheItems() { Transform gridTrans = grid.transform; if (gridTrans.childCount <= 0) { return; } Queue <GameObject> cacheItems = null; if (!cacheItemDic.TryGetValue(itemPrefabPath, out cacheItems)) { return; } for (int i = gridTrans.childCount - 1; i >= 0; i--) { Transform itemTrans = gridTrans.GetChild(i); if (cacheItems.Contains(itemTrans.gameObject)) { continue; } MonoExtendUtil.AddChildToTarget(cacheItemRoot.transform, itemTrans); NGUITools.SetActive(itemTrans.gameObject, false); cacheItems.Enqueue(itemTrans.gameObject); } grid.ClearChildren(); }
/// <summary> /// 创建表单元格 /// </summary> private void CreateGridCells() { if (grid == null) { return; } if (datas.Count == grid.transform.childCount || grid.transform.childCount >= maxGridNum) { RefreshScrollView(true); return; } Queue <GameObject> cacheItems = null; if (!cacheItemDic.TryGetValue(itemPrefabPath, out cacheItems)) { return; } int hasCount = grid.transform.childCount; for (int i = 0; i < datas.Count - hasCount; i++) { if (i >= maxGridNum || cacheItems.Count <= 0) { break; } GameObject cell = cacheItems.Dequeue(); if (cell == null) { continue; } MonoExtendUtil.AddChildToTarget(grid.transform, cell.transform); NGUITools.SetActive(cell, true); UIGridItem gridItem = cell.GetOrAddComponent <UIGridItem>(); gridItem.Data = datas[i]; gridItem.createBoxCollider(); items.Add(gridItem); } RefreshScrollView(false); }
protected override void Awake() { base.Awake(); grid = transform.GetComponentInChildren <UIBetterGrid>(); if (grid == null) { Debugger.LogError("Need UIBetterGrid Component!!"); return; } grid.onUpdateGrid = OnUpdateGrid; // 预创建缓存item根节点 cacheItemRoot = MonoExtendUtil.FindDeepChild(gameObject, CACHE_ITEM_ROOT); if (cacheItemRoot == null) { cacheItemRoot = new GameObject("CacheItemRoot").transform; MonoExtendUtil.AddChildToTarget(transform, cacheItemRoot); } }
protected UIWindowBase ReadyToShowWindow(int id, ShowWindowData?showData = null) { // 检测控制权限 if (!IsRegisterWindow(id)) { Debug.Log("UIManager has no control power of " + id.ToString()); return(null); } UIWindowBase showWindow = null; if (showWindows.TryGetValue(id, out showWindow)) { curShownWindow = showWindow; return(null); } UIWindowBase baseWindow = GetWindow(id); bool newAdded = false; if (baseWindow == null) { newAdded = true; // 判断窗口资源路径是否正确 string prefabPath = MLResourceManager.Instance.GetWindowPrefabPath(id); if (string.IsNullOrEmpty(prefabPath)) { return(null); } GameObject uiObject = MLResourceManager.Instance.LoadInstance(prefabPath, ResourceType.RES_UI) as GameObject; if (uiObject != null) { baseWindow = uiObject.GetComponent <UIWindowBase>(); // 检查窗口id if (baseWindow.WindowID != id) { Debug.LogError(string.Format("<color=cyan>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.WindowID, id)); return(null); } // 查询window类型 Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType); // 挂在到相应的根节点上 MonoExtendUtil.AddChildToTarget(targetRoot, uiObject.transform); allWindows[id] = baseWindow; } } if (baseWindow == null) { Debug.LogError("[window instance is null.]" + id.ToString()); return(null); } // 重置界面(第一次添加,强制Reset) if (newAdded || (showData != null && showData.Value.forceResetWindow)) { baseWindow.ResetWindow(); } if (showData == null || (showData != null && showData.Value.executeNavLogic)) { // 执行窗口层级逻辑 ExecuteNavigationLogic(baseWindow, showData); } // 调整层级depth AdjustBaseWindowDepth(baseWindow); return(baseWindow); }