/// <summary> /// 使用kvData这个dic中的数据 /// 刷新kv区域ui /// </summary> /// <param name="kvData">Kv data.</param> private void RefreshKVListUI(Dictionary <int, KVData> kvData) { ClearKVListUI(); //创建新节点 int i = 0; //创建ui相关 foreach (KeyValuePair <int, KVData> p in kvData) { //Debug.Log("nafio--->k:"+p.Key+" v:"+p.Value); KVListItem keyItem = FreeItemPool.GetFreeItem(); if (!keyItem.gameObject.activeSelf) { keyItem.gameObject.SetActive(true); } keyItem.gameObject.name = p.Value.key; keyItem.IsKey = true; keyItem.Index = i; keyItem.TreeItemID = Convert.ToInt32(CurTreeItemID); //Debug.Log("==========>i:"+i+"====>CurItemID:"+CurTreeItemID); keyItem.SetContent(p.Value.key); keyItem.SetKVMgr(this); RectTransform keyRT = keyItem.gameObject.GetComponent <RectTransform>(); keyRT.SetParent(KeyParentTrm as Transform); keyRT.anchoredPosition = new Vector2(0, i * -1 * UIEnum.KVItemH); keyRT.offsetMax = new Vector2(-1, keyRT.offsetMax.y); keyRT.offsetMin = new Vector2(1, keyRT.offsetMin.y); KVListItem valueItem = FreeItemPool.GetFreeItem(); if (!valueItem.gameObject.activeSelf) { valueItem.gameObject.SetActive(true); } RectTransform valueRT = valueItem.gameObject.GetComponent <RectTransform>(); valueItem.gameObject.name = p.Value.value; valueItem.IsKey = false; valueItem.Index = i; valueItem.TreeItemID = Convert.ToInt32(CurTreeItemID); valueItem.SetContent(p.Value.value); //valueItem.DialogOpenType = p.Value.type; valueItem.SetKVMgr(this); valueRT.SetParent(ValueParentTrm as Transform); valueRT.anchoredPosition = new Vector2(0, i * -1 * UIEnum.KVItemH); valueRT.offsetMax = new Vector2(-1, valueRT.offsetMax.y); valueRT.offsetMin = new Vector2(1, valueRT.offsetMin.y); //keyItem.DialogOpenType = p.Value.type; keyItem.BrotherItem = valueItem; valueItem.BrotherItem = keyItem; i++; } float h = i * UIEnum.KVItemH; RefreshKVContainerArea(h); }
[HideInInspector] public int TreeItemID; //记录下KVListItem属于哪个TreeItemID //[HideInInspector]public string DialogOpenType; //打开(Dialog)方式 public override void Reset() { base.Reset(); BrotherItem = null; IsKey = true; //DialogOpenType = GEditorConfig.DLG_TYPE_stringValue; transform.SetParent(null); gameObject.SetActive(false); }
public static void PushFreeItem2Pool(KVListItem node) { node.Reset(); if (size == 0) { head = node; } else { node.Next = head; head = node; } size++; }
public static KVListItem GetFreeItem() { if (size == 0) { GameObject go = GameObject.Instantiate(Resources.Load <GameObject> ("Prefabs/KVListItem")); KVListItem listItem = go.GetComponent <KVListItem>(); return(listItem); } else if (size == 1) { size = 0; return(head); } else { KVListItem tempNode = head; head = head.Next as KVListItem; tempNode.Next = null; size--; return(tempNode); } }