Ejemplo n.º 1
0
    /// <summary>
    /// 向下遍历数据
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    public EntryDataInfo[] GetNexts(EntryDataInfo parent)
    {
        MapElement <EntryDataInfo> root = dataMap.GetElement(parent.ID);

        if (root == null)
        {
            return(null);
        }
        return(root.Next(EnumMapTraversalModel.More).Select(temp => temp.Value).ToArray());
    }
    /// <summary>
    /// 显示当前选择节点的说明
    /// </summary>
    private void ShowNowSelectTreeNodeExplan()
    {
        //删除之前的
        Transform[] childTranses = Enumerable.Range(0, showPanel.childCount).Select(temp => showPanel.GetChild(temp)).ToArray();
        foreach (var childTrans in childTranses)
        {
            GameObject.Destroy(childTrans.gameObject);
        }
        //显示现在的
        UITreeNode selectNode = uiTree.SelectNode;

        if (selectNode == null)
        {
            return;
        }
        EntryDataInfo entryDataInfo = selectNode.value as EntryDataInfo;

        if (entryDataInfo == null)
        {
            return;
        }
        if (!playerState.EntryEnableList.Contains(entryDataInfo.ID))
        {
            return;
        }
        foreach (EntryDataInfo.EntryValue entryValue in entryDataInfo.Datas)
        {
            switch (entryValue.EntryValueType)
            {
            case EntryDataInfo.EnumEntryValueType.Title:
                AddTitle(entryValue.Data);
                break;

            case EntryDataInfo.EnumEntryValueType.Text:
                Text          textValue     = AddText(entryValue.Data);
                LinkImageText linkImageText = textValue as LinkImageText;
                if (linkImageText)
                {
                    linkImageText.onHrefClick.AddListener(ClickLink);
                }
                break;

            case EntryDataInfo.EnumEntryValueType.Image:
                AddSprite(entryValue.Data);
                break;
            }
        }
    }
    /// <summary>
    /// 通过数据创建节点
    /// </summary>
    /// <param name="target">数据</param>
    /// <param name="parent">父节点</param>
    private void CreateNodeByEntryDataInfo(EntryDataInfo target, UITreeNode parent = null)
    {
        UITreeNode uiTreeNode = uiTree.CreateTreeNode();

        if (parent == null)
        {
            uiTree.AddTreeNode(uiTreeNode);
        }
        else
        {
            parent.Add(uiTreeNode);
        }
        uiTreeNode.value = target;
        if (playerState.EntryEnableList.Contains(target.ID))
        {
            uiTreeNode.ExplanText = target.Name;
        }
        else
        {
            uiTreeNode.ExplanText = "????????????????";
        }
        uiTreeNode.IsDisplay = true;
        uiTreeNode.IsExpand  = false;
        if (!entryIDToNodeDic.ContainsKey(target.ID))//添加到字典中
        {
            entryIDToNodeDic.Add(target.ID, uiTreeNode);
        }
        EntryDataInfo[] entryDataInfos = entryData.GetNexts(target);
        if (entryDataInfos != null)
        {
            foreach (EntryDataInfo entryDataInfo in entryDataInfos)
            {
                CreateNodeByEntryDataInfo(entryDataInfo, uiTreeNode);
            }
        }
    }