private void CreateItem(TreeItemData value) { var item = Instantiate(template); item.SetParent(itemParent, false); value.SetTarget(item.transform); if (customsSize.ContainsKey(value.parent.id)) { value.target.sizeDelta = customsSize[value.parent.id]; } else { value.target.sizeDelta = itemSize; } value.button.onClick.AddListener(() => { value.isClick = !value.isClick; OnItemValueChanged(value, value.isClick); if (onClick != null) { onClick(value, value.isClick); } }); if (onCreateItem != null) { onCreateItem(value); } items.Add(item.gameObject); }
private void GetOneTreeItemData(TreeItem treeItem, List <TreeItemData> buffer) { if (treeItem.BeFolder) { TreeFolder _treeFolder = treeItem as TreeFolder; //buffer.PutBool (_treeFolder.BeFolder);//是否是folder //buffer.PutString (_treeFolder.Name);//节点名称 List <TreeItem> _ItemList = _treeFolder.ItemList; //buffer.PutInt (_ItemList.Count);//直接子节点数 for (int i = 0; i < _ItemList.Count; i++) { TreeItem item = _ItemList [i]; GetOneTreeItemData(item, buffer); } } else { TreeItemData tempData = new TreeItemData(); tempData.TreeItemID = treeItem.TreeItemID; tempData.TreeItemName = treeItem.Name; buffer.Add(tempData); //buffer.PutBool (treeItem.BeFolder);//是否是folder //buffer.PutString (treeItem.Name);//节点名称 //buffer.PutString(treeItem.TreeItemID);//数据索引ID } }
private void UpdatePos(TreeItemData data, int index = -1) { if (data != root) { if (data.target.gameObject.activeSelf) { if (!(index == 0 && data.parent.id == 0)) { if (index != 0) { currentHeight += GetSpace(data); } else { currentHeight += space; } } data.target.localPosition = itemParent.localPosition - new Vector3(-data.indentLevel * indent - padding.x, currentHeight + padding.y); currentHeight += GetHeight(data); } } int count = data.childs.Count; for (int i = 0; i < count; i++) { UpdatePos(data.childs[i], i); } }
private void GetTreeFromRelayPacket(DHCPv6RelayPacket relayPacket, ICollection <TreeItemData> collection) { collection.Add(new TreeItemData { Name = "Hop Count", Value = relayPacket.HopCount.ToString() }); collection.Add(new TreeItemData { Name = "Link Address", Value = relayPacket.LinkAddress.ToString() }); collection.Add(new TreeItemData { Name = "Peer Address", Value = relayPacket.PeerAddress.ToString() }); collection.Add(new TreeItemData { Name = "Packet Type", Value = relayPacket.PacketType.ToString() }); var innerPacket = relayPacket.InnerPacket; var children = new HashSet <TreeItemData>(); var item = new TreeItemData { Name = "Inner Packet", Children = children }; collection.Add(item); if (innerPacket is DHCPv6RelayPacket innerRelayedPacket) { GetTreeFromRelayPacket(innerRelayedPacket, children); } else if (innerPacket is DHCPv6Packet innersPacket) { GetTreeFromPacket(innersPacket, children); } }
/// <summary> /// 清空树 /// </summary> public void Clear() { ClearItem(); root = new TreeItemData(); datas.Clear(); conent.sizeDelta = Vector2.zero; }
public GridItemData GetItemChildDataByIndex(int itemIndex, int childIndex) { TreeItemData data = GetItemDataByIndex(itemIndex); if (data == null) { return(null); } return(data.GetChild(childIndex)); }
/// <summary> /// 打开或关闭节点 /// </summary> /// <param name="node"></param> /// <param name="value"></param> public void OpenNode(TreeItemData node, bool value) { int count = node.childs.Count; for (int i = 0; i < count; i++) { node.childs[i].target.gameObject.SetActive(value); node.childs[i].isShow = value; } UpdatePos(); UpdateSize(); }
private int GetMaxIdent(TreeItemData value, int max = 0) { int count = value.childs.Count; for (int i = 0; i < count; i++) { if (value.childs[i].isShow) { max = Mathf.Max(GetMaxIdent(value.childs[i], Mathf.Max(max, value.childs[i].indentLevel)), max); } } return(max); }
private void OnItemValueChanged(TreeItemData value, bool isOn) { if (isOn) { OpenNode(value, true); } else { SetItemActive(value, false); } UpdatePos(); UpdateSize(); }
private void DeleteItem(TreeItemData value) { int count = value.childs.Count; for (int i = 0; i < count; i++) { DeleteItem(value.childs[i]); } value.parent.childs.Remove(value); datas.Remove(value); items.Remove(value.target.gameObject); GameObject.Destroy(value.target.gameObject); UpdatePos(); UpdateSize(); }
private void SetItemActive(TreeItemData value, bool active) { int count = value.childs.Count; if (onHideItem != null && !active) { value.isClick = false; onHideItem(value); } for (int i = 0; i < count; i++) { value.childs[i].target.gameObject.SetActive(active); value.childs[i].isShow = active; SetItemActive(value.childs[i], active); } }
public TreeItemData GetNode(int id) { if (id == this.id) { return(this); } TreeItemData node = null; for (int i = 0; i < childs.Count; i++) { node = childs[i].GetNode(id); if (node != null) { break; } } return(node); }
void DoRefreshDataSource() { mItemDataList.Clear(); for (int i = 0; i < mTreeViewItemCount; ++i) { TreeItemData tData = new TreeItemData(); tData.mName = "Item" + i; mItemDataList.Add(tData); //int childCount = mTreeViewChildItemCount; int childCount = mTreeViewChildItemCountList[i]; for (int j = 1; j <= childCount; ++j) { GridItemData childItemData = new GridItemData(); //childItemData.mName = "Item" + i + ":Child" + j; //childItemData.mDesc = "Item Desc For " + childItemData.mName; //childItemData.mStarCount = Random.Range(0, 6); //childItemData.mFileSize = Random.Range(20, 999); tData.AddChild(childItemData); } } }
private float GetSpace(TreeItemData value) { return(customsSpace.ContainsKey(value.parent.id) ? customsSpace[value.parent.id] : space); }
public void Add(TreeItemData value) { childs.Add(value); value.parent = this; }
private static void AddDHCPv6PacketIdentityAssociationAddressrefixSuboption(DHCPv6PacketIdentityAssociationPrefixDelegationSuboption addressSubOption, TreeItemData item) { item.Children.Add(new TreeItemData { Name = "Address", Value = addressSubOption.Address.ToString() }); item.Children.Add(new TreeItemData { Name = "Prefix Length", Value = addressSubOption.PrefixLength.ToString() }); item.Children.Add(new TreeItemData { Name = "Preferred Lifetime", Value = addressSubOption.PreferredLifetime.ToString() }); item.Children.Add(new TreeItemData { Name = "Valid Lifetime", Value = addressSubOption.ValidLifetime.ToString() }); var statusCodeItems = new HashSet <TreeItemData>(); foreach (var addre in addressSubOption.Suboptions.OfType <DHCPv6PacketStatusCodeSuboption>()) { statusCodeItems.Add(new TreeItemData { Name = "Code", Value = addre.Code.ToString() }); statusCodeItems.Add(new TreeItemData { Name = "Message", Value = addre.Message.ToString() }); } if (statusCodeItems.Count > 0) { item.Children.Add(new TreeItemData { Name = "Status Code", Children = statusCodeItems }); } }
private void GetTreeFromPacket(DHCPv6Packet packet, ICollection <TreeItemData> collection) { collection.Add(new TreeItemData { Name = "Transaction Id", Value = packet.TransactionId.ToString() }); collection.Add(new TreeItemData { Name = "Packet Type", Value = packet.PacketType.ToString() }); var options = new HashSet <TreeItemData>(); var optionItem = new TreeItemData { Name = "Options", Children = options }; collection.Add(optionItem); foreach (var item in packet.Options) { String name = $"{_codeToNameConverter.GetName(item.Code)} ({item.Code})"; switch (item) { case DHCPv6PacketIdentifierOption castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.DUID.ToFriendlyString() }); break; case DHCPv6PacketReconfigureOption castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.MessageType.ToString() }); break; case DHCPv6PacketByteArrayOption castedOption: options.Add(new TreeItemData { Name = name, Value = ByteHelper.ToString(castedOption.Data) }); break; case DHCPv6PacketVendorSpecificInformationOption castedOption: { var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Enterprise", Value = castedOption.EnterpriseNumber.ToString() }, new TreeItemData { Name = "Options", Children = castedOption.Options.Select(x => new TreeItemData { Name = x.Code.ToString(), Value = ByteHelper.ToString(x.Data) }).ToHashSet() } }; options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketVendorClassOption castedOption: { Int32 index = 1; var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Enterprise", Value = castedOption.EnterpriseNumber.ToString() }, new TreeItemData { Name = "Options", Children = castedOption.VendorClassData.Select(x => new TreeItemData { Name = (index++).ToString(), Value = ByteHelper.ToString(x) }).ToHashSet() } }; options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketUserClassOption castedOption: { Int32 index = 1; var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Options", Children = castedOption.UserClassData.Select(x => new TreeItemData { Name = (index++).ToString(), Value = ByteHelper.ToString(x) }).ToHashSet() } }; options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketUInt32Option castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.Value.ToString() }); break; case DHCPv6PacketUInt16Option castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.Value.ToString() }); break; case DHCPv6PacketByteOption castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.Value.ToString() }); break; case DHCPv6PacketTimeOption castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.Value.Humanize() }); break; case DHCPv6PacketTrueOption castedOption: options.Add(new TreeItemData { Name = name }); break; case DHCPv6PacketBooleanOption castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.Value.ToString() }); break; case DHCPv6PacketIPAddressOption castedOption: options.Add(new TreeItemData { Name = name, Value = castedOption.Address.ToString() }); break; case DHCPv6PacketIPAddressListOption castedOption: { Int32 index = 1; var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Addesses", Children = castedOption.Addresses.Select(x => new TreeItemData { Name = (index++).ToString(), Value = x.ToString() }).ToHashSet() } }; options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketRemoteIdentifierOption castedOption: options.Add(new TreeItemData { Name = name, Value = ByteHelper.ToString(castedOption.Value) }); break; case DHCPv6PacketOptionRequestOption castedOption: { var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Options", Children = castedOption.RequestedOptions.Select(x => new TreeItemData { Name = x.ToString(), Value = _codeToNameConverter.GetName(x) }).ToHashSet() } }; options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption castedOption: { var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Id", Value = castedOption.Id.ToString() }, new TreeItemData { Name = "T1", Value = castedOption.T1.Humanize() }, new TreeItemData { Name = "T2", Value = castedOption.T2.Humanize() } }; var secondLevelSuboptions = new HashSet <TreeItemData>(); Int32 index = 0; foreach (var addressSubOption in castedOption.Suboptions.OfType <DHCPv6PacketIdentityAssociationAddressSuboption>()) { var subOptionTreeItem = new TreeItemData { Name = (index++).ToString(), Children = new() }; secondLevelSuboptions.Add(subOptionTreeItem); AddDHCPv6PacketIdentityAssociationAddressSuboption(addressSubOption, subOptionTreeItem); } if (secondLevelSuboptions.Count > 0) { subOptions.Add(new TreeItemData { Name = "Address sub options", Children = secondLevelSuboptions }); } options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketIdentityAssociationTemporaryAddressesOption castedOption: { var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Id", Value = castedOption.Id.ToString() } }; var secondLevelSuboptions = new HashSet <TreeItemData>(); Int32 index = 0; foreach (var addressSubOption in castedOption.Suboptions.OfType <DHCPv6PacketIdentityAssociationAddressSuboption>()) { var subOptionTreeItem = new TreeItemData { Name = (index++).ToString(), Children = new() }; secondLevelSuboptions.Add(subOptionTreeItem); AddDHCPv6PacketIdentityAssociationAddressSuboption(addressSubOption, subOptionTreeItem); } if (secondLevelSuboptions.Count > 0) { subOptions.Add(new TreeItemData { Name = "Address sub options", Children = secondLevelSuboptions }); } options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; case DHCPv6PacketIdentityAssociationPrefixDelegationOption castedOption: { var subOptions = new HashSet <TreeItemData> { new TreeItemData { Name = "Id", Value = castedOption.Id.ToString() }, new TreeItemData { Name = "T1", Value = castedOption.T1.Humanize() }, new TreeItemData { Name = "T2", Value = castedOption.T2.Humanize() } }; var secondLevelSuboptions = new HashSet <TreeItemData>(); Int32 index = 0; foreach (var addressSubOption in castedOption.Suboptions.OfType <DHCPv6PacketIdentityAssociationPrefixDelegationSuboption>()) { var subOptionTreeItem = new TreeItemData { Name = (index++).ToString(), Children = new() }; secondLevelSuboptions.Add(subOptionTreeItem); AddDHCPv6PacketIdentityAssociationAddressrefixSuboption(addressSubOption, subOptionTreeItem); } if (secondLevelSuboptions.Count > 0) { subOptions.Add(new TreeItemData { Name = "Address sub options", Children = secondLevelSuboptions }); } options.Add(new TreeItemData { Name = name, Children = subOptions }); } break; default: break; } } }
private float GetHeight(TreeItemData data) { return(customsSize.ContainsKey(data.parent.id) ? customsSize[data.parent.id].y : itemSize.y); }
private LoopListViewItem2 OnGetItemByIndex1(LoopListView2 listView, int index) { if (index < 0) { return(null); } /*to check the index'th item is a TreeItem or a TreeChildItem.for example, * * 0 TreeItem0 * 1 TreeChildItem0_0 * 2 TreeChildItem0_1 * 3 TreeChildItem0_2 * 4 TreeChildItem0_3 * 5 TreeItem1 * 6 TreeChildItem1_0 * 7 TreeChildItem1_1 * 8 TreeChildItem1_2 * 9 TreeItem2 * 10 TreeChildItem2_0 * 11 TreeChildItem2_1 * 12 TreeChildItem2_2 * * the first column value is the param 'index', for example, if index is 1, * then we should return TreeChildItem0_0 to SuperScrollView, and if index is 5, * then we should return TreeItem1 to SuperScrollView */ TreeViewItemCountData countData = TreeItemCountMgr.QueryTreeItemByTotalIndex(index); if (countData == null) { return(null); } int treeItemIndex = countData.mTreeItemIndex; TreeItemData treeViewItemData = TreeData.GetItemDataByIndex(treeItemIndex); if (countData.IsChild(index) == false)// if is a TreeItem { //get a new TreeItem LoopListViewItem2 item = listView.NewListViewItem(ItemNameList[0]); TreeItem1 itemScript = item.GetComponent <TreeItem1>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); itemScript.SetClickCallBack(this.OnExpandClicked); } //update the TreeItem's content itemScript.mText.text = treeViewItemData.mName; itemScript.SetItemData(treeItemIndex, countData.mIsExpand); return(item); } else { int childIndex = countData.GetChildIndex(index); GridItemData itemData = treeViewItemData.GetChild(childIndex); if (itemData == null) { return(null); } LoopListViewItem2 item = listView.NewListViewItem(ItemNameList[1]); TreeItem2 itemScript = item.GetComponent <TreeItem2>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } return(item); } }
public override LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (index < 0) { return null; } /*to check the index'th item is a TreeItem or a TreeChildItem.for example, 0 TreeItem0 1 TreeChildItem0_0 2 TreeChildItem0_1 3 TreeChildItem0_2 4 TreeChildItem0_3 5 TreeItem1 6 TreeChildItem1_0 7 TreeChildItem1_1 8 TreeChildItem1_2 9 TreeItem2 10 TreeChildItem2_0 11 TreeChildItem2_1 12 TreeChildItem2_2 the first column value is the param 'index', for example, if index is 1, then we should return TreeChildItem0_0 to SuperScrollView, and if index is 5, then we should return TreeItem1 to SuperScrollView */ TreeViewItemCountData countData = TreeItemCountMgr.QueryTreeItemByTotalIndex(index); if (countData == null) { return null; } int treeItemIndex = countData.mTreeItemIndex; TreeItemData treeViewItemData = TreeData.GetItemDataByIndex(treeItemIndex); if (countData.IsChild(index) == false)// if is a TreeItem { //get a new TreeItem LoopListViewItem2 item = listView.NewListViewItem(ItemNameList[0]); TreeItem1 itemScript = item.GetComponent<TreeItem1>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); itemScript.SetClickCallBack(this.OnExpandClicked); } itemScript.mText.text = treeViewItemData.mName; //Debug.Log(index); itemScript.mText.text = m_Achievement1List[treeItemIndex]; itemScript.SetItemData(treeItemIndex, countData.mIsExpand); return item; } else { int childIndex = countData.GetChildIndex(index); GridItemData itemData = treeViewItemData.GetChild(childIndex); if (itemData == null) { return null; } LoopListViewItem2 item = listView.NewListViewItem(ItemNameList[1]); TreeItem2 itemScript = item.GetComponent<TreeItem2>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } itemScript.BtnGet.onClick.AddListener(delegate { Debug.Log("领取 "+itemScript.mNameText.text); }); Vector3 v3 = itemScript.transform.localPosition; itemScript.transform.localPosition = new Vector3(v3.x + 50, v3.y, v3.z); itemScript.SetData(m_Achievement2List[treeItemIndex][childIndex]); return item; } }