//-------∽-★-∽------∽-★-∽--------∽-★-∽列表项相关∽-★-∽--------∽-★-∽------∽-★-∽--------// //创建列表项 protected GameObject CreateItem(int index_) { if (m_index2item.ContainsKey(index_)) { return(m_index2item[index_]); } GameObject item; if (m_itemPool.Count > 0) { item = ListUtil.Pop(m_itemPool); //先从池里拿 } else { item = GameObjUtil.Instantiate(m_itemTemp); GameObjUtil.ChangeParent(item, m_contentGo); } m_index2item[index_] = item; item.SetActive(true); item.name = "item(" + index_ + ")"; LayItem(index_, item); return(item); }
void OnKeyPress(object evt_) { KeyCode key = (KeyCode)evt_; switch (key) { case KeyCode.Keypad1: m_listView.JumpToIndex(11, KListViewScroll.JumpPosType.BOTTOM); break; case KeyCode.Keypad2: m_listView.JumpToIndex(5, KListViewScroll.JumpPosType.CENTER); break; case KeyCode.Keypad3: m_listView.JumpToIndex(14, KListViewScroll.JumpPosType.TOP); break; case KeyCode.Keypad4: GameObjUtil.RemoveFromParent(m_btnOk.gameObject); break; case KeyCode.Keypad5: GameObjUtil.ChangeParent(m_btnOk.gameObject, m_panel); break; default: break; } }
//-------∽-★-∽------∽-★-∽--------∽-★-∽Layout∽-★-∽--------∽-★-∽------∽-★-∽--------// void ShowLayout() { LayoutParam param = new LayoutParam { }; param.padding = new Padding(20, 20, 20, 20); param.itemGap = new Vector2(50, 50); param.divNum = 2; GameObject itemGo = GameObjUtil.FindChild(m_scrollViewItemList.gameObject, "Image_mask/Container_content/Container_Item"); GameObject container = GameObjUtil.GetParent(itemGo); itemGo.SetActive(false); for (var i = 0; i < 10; ++i) { GameObject item = GameObjUtil.Instantiate(itemGo); item.SetActive(true); GameObjUtil.ChangeParent(item, container); LayoutUtil.LayItem(param, i, item); m_idx2item[i] = item; } }
protected override void __ShowGameObject() { base.__ShowGameObject(); GameObjUtil.ChangeParent(m_gameObject, KUIApp.UILayer); m_gameObject.SetActive(true); m_canvas = m_gameObject.GetComponent <Canvas>(); m_canvas.worldCamera = KUIApp.UICamera; m_canvas.sortingLayerName = m_sortingLayer.ToString(); m_canvas.sortingOrder = m_sortingOrder; m_canvas.planeDistance = m_planeDistance; }
//-------∽-★-∽------∽-★-∽--------∽-★-∽Prefab∽-★-∽--------∽-★-∽------∽-★-∽--------// //生成预制 static void GenPrefabs(GameObject root, bool isBuildAssetBundle) { Dictionary <GameObject, GameObject> go2parent = null; //记录父节点,方便还原 //List<GameObject> toGenerate = GetPrefabList(root, jsonName); List <GameObject> toGenerate = GetPrefabList(root, root.name); for (int i = toGenerate.Count - 1; i >= 0; --i) { GameObject go = toGenerate[i]; if (go.transform.parent) { //需要export GameObject parent = go.transform.parent.gameObject; if (go2parent == null) { go2parent = new Dictionary <GameObject, GameObject>(); } go2parent[go] = parent; var pos = go.GetComponent <RectTransform>().anchoredPosition3D; go.transform.parent = null; //放到根目录 go.GetComponent <RectTransform>().anchoredPosition3D = pos; } //保存预制文件 CreatePrefabFile(go, isBuildAssetBundle); } if (go2parent != null) { List <KeyValuePair <GameObject, GameObject> > list = new List <KeyValuePair <GameObject, GameObject> >(go2parent); list.Reverse(); foreach (var kvp in list) { //移回原来的地方,这样比较方便写界面逻辑 GameObjUtil.ChangeParent(kvp.Key, kvp.Value); } } }
//-------∽-★-∽------∽-★-∽--------∽-★-∽数据操作∽-★-∽--------∽-★-∽------∽-★-∽--------// private void Test_LoadBundle() { string[] dependPaths = new string[] { "StreamingAssets/depend.j", }; string[] bundlePaths = new string[] { "StreamingAssets/canvas_bag.j", "StreamingAssets/canvas_test3.j", }; List <AssetBundle> bundleList = new List <AssetBundle>(); foreach (string path in dependPaths) { AssetBundle b = AssetBundle.LoadFromFile(Application.dataPath + "/" + path); bundleList.Add(b); } AssetBundle bundle1 = AssetBundle.LoadFromFile(Application.dataPath + "/" + bundlePaths[1]); bundleList.Add(bundle1); GameObject prefab = bundle1.LoadAsset("canvas_test3") as GameObject; GameObject go = GameObjUtil.Instantiate(prefab); GameObjUtil.ChangeParent(go, KUIApp.UILayer); //需要全部卸载掉才能重新加载, 不然会报错 foreach (var b in bundleList) { b.Unload(false); } Resources.UnloadUnusedAssets(); }