Пример #1
0
    /// <summary>
    /// 初始化显示
    /// </summary>
    private void InitShow()
    {
        synthesisItemTree.Clear();
        SynthesisDataStruct[] synthesisDataStructs = synthesisStructData.SearchSynthesisData(temp => temp.synthesisType == iSynthesisState.SynthesisType);
        EnumSynthesisItem[]   enumSynthesisItems   = synthesisDataStructs.Select(temp => temp.synthesisItem).Distinct().ToArray();
        //这里需要将枚举转换成对应的文字,但是这里直接使用枚举了(这里添加的是根节点)
        Dictionary <EnumSynthesisItem, UITreeNode> rootNodeDic = enumSynthesisItems.ToDictionary(temp => temp,
                                                                                                 temp =>
        {
            UITreeNode rootNode = synthesisItemTree.CreateTreeNode();
            rootNode.ExplanText = temp.ToString();
            rootNode.IsDisplay  = true;
            rootNode.IsExpand   = true;
            rootNode.value      = null;
            synthesisItemTree.AddTreeNode(rootNode);
            return(rootNode);
        });

        //这里添加的是各自类型的子节点
        foreach (KeyValuePair <EnumSynthesisItem, UITreeNode> rootNode in rootNodeDic)
        {
            SynthesisDataStruct[] tempSynthesisDataStructs = synthesisDataStructs.Where(temp => temp.synthesisItem == rootNode.Key).ToArray();
            foreach (SynthesisDataStruct tempSynthesisDataStruct in tempSynthesisDataStructs)
            {
                UITreeNode createNode = synthesisItemTree.CreateTreeNode();
                createNode.ExplanText = tempSynthesisDataStruct.name;
                createNode.IsDisplay  = true;
                createNode.IsExpand   = true;
                createNode.value      = tempSynthesisDataStruct;
                rootNode.Value.Add(createNode);
            }
        }
        //选择设置第一个选项为当前选项
        if (synthesisItemTree.Count > 0)
        {
            synthesisItemTree[0].IsSelect = true;
        }
    }
    /// <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);
            }
        }
    }