/// <summary>
    /// 从文件读取技能结构数据
    /// </summary>
    /// <param name="must">是否必须读取</param>
    public void ReadSkillStructData(bool must = false)
    {
        if (skillBaseStructs == null || must)
        {
            TextAsset skillPathTextAsset = Resources.Load <TextAsset>("Data/Skill/Skills");
            if (skillPathTextAsset == null)
            {
                skillBaseStructs = new SkillBaseStruct[0];
            }
            else
            {
                //获取其他类型的宏定义
                Type        edfineType  = typeof(SkillStructConstString);
                FieldInfo[] edfineInfos = edfineType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                Dictionary <string, string> edfineNameToValueDic = edfineInfos.ToDictionary(
                    temp => temp.Name,
                    temp => (string)temp.GetValue(null));
                string[] otherSplit = new string[] { "***" };//截取其他数据时所用的分隔符

                string[] splits     = new string[] { "^^^" };
                string[] skillPaths = skillPathTextAsset.text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
                                      .Select(temp => temp.Split(splits, StringSplitOptions.RemoveEmptyEntries))
                                      .Where(temp => temp != null && temp.Length == 3)
                                      .Select(temp => temp[2]).ToArray();
                string[] skillValues = skillPaths
                                       .Select(temp => Resources.Load <TextAsset>("Data/Skill/" + temp))
                                       .Where(temp => temp != null)
                                       .Select(temp => temp.text)
                                       .ToArray();
                skillAnalysisData.AnalysisData(skillValues);
                string[] ids = skillAnalysisData.GetIDArray();
                skillBaseStructs = new SkillBaseStruct[ids.Length];
                for (int i = 0; i < ids.Length; i++)
                {
                    string          id              = ids[i];
                    EnumSkillType   enumSkillType   = skillAnalysisData.GetEnum <EnumSkillType>(id, "skillType");
                    SkillBaseStruct skillBaseStruct = null;
                    Type            newType         = null;
                    //尝试使用该类型构造一个新的类
                    try
                    {
                        newType         = Type.GetType("SkillStruct_" + enumSkillType.ToString());
                        skillBaseStruct = Activator.CreateInstance(newType) as SkillBaseStruct;
                    }
                    catch { }
                    if (skillBaseStruct == null)
                    {
                        skillBaseStruct = new SkillBaseStruct();
                    }
                    //加载其他属性
                    if (newType != null)
                    {
                        FieldInfo[] otherFieldInfos = newType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                        foreach (FieldInfo otherFieldInfo in otherFieldInfos)
                        {
                            string otherFieldName = otherFieldInfo.Name;
                            if (edfineNameToValueDic.ContainsKey(otherFieldName))
                            {
                                string otherFieldKey    = edfineNameToValueDic[otherFieldName];
                                int[]  otherFieldValues = skillAnalysisData.GetValues <int>(id, otherFieldKey);
                                if (otherFieldValues != null && otherFieldValues.Length > 0)
                                {
                                    otherFieldInfo.SetValue(skillBaseStruct, otherFieldValues[0]);
                                }
                            }
                        }
                    }
                    //加载常规属性
                    skillBaseStructs[i]        = skillBaseStruct;
                    skillBaseStruct.id         = id;
                    skillBaseStruct.name       = skillAnalysisData.GetValue <string>(id, "skillName");
                    skillBaseStruct.skillType  = enumSkillType;
                    skillBaseStruct.skillMode  = skillAnalysisData.GetEnum <EnumReleaseMode>(id, "releaseMode");
                    skillBaseStruct.skillZones = skillAnalysisData.GetEnums <EnumSkillZone>(id, "correlationZone").Where(temp => temp != EnumSkillZone.None).ToArray();
                    //加载技能图标
                    skillBaseStruct.skillSprite         = SkillSpriteData.GetSprite(skillBaseStruct.skillType);
                    skillBaseStruct.skillSprite_Combine = SkillSpriteData.GetSpriteCombine(skillBaseStruct.skillType);
                    //计算技能名(现在暂定使用元名字)
                    skillBaseStruct.skillName = skillBaseStruct.name;
                    //完成加载特殊效果
                    skillBaseStruct.skillBelief = skillAnalysisData.GetEnum <EnumSkillBelief>(id, "skillBelief");
                    string[] skillStatusEffectStrs = skillAnalysisData.GetValues <string>(id, "skillStatusEffect").Where(temp => !string.IsNullOrEmpty(temp)).ToArray();
                    skillBaseStruct.skillStatusEffect = new EnumStatusEffect[skillStatusEffectStrs.Length];
                    for (int j = 0; j < skillStatusEffectStrs.Length; j++)
                    {
                        skillBaseStruct.skillStatusEffect[j] = (EnumStatusEffect)Enum.Parse(typeof(EnumStatusEffect), skillStatusEffectStrs[j]);
                    }
                    //技能前置
                    skillBaseStruct.skillPrecondition = new SkillPrecondition();
                    skillBaseStruct.skillPrecondition.mustSkillZonePointDic = new Dictionary <EnumSkillZone, int>();
                    skillBaseStruct.skillPrecondition.mustSkillPointDic     = new Dictionary <EnumSkillType, int>();
                    EnumSkillZone[] preconditionSkillZones     = skillAnalysisData.GetEnums <EnumSkillZone>(id, "correlationBeforeZone"); //前置技能组数组
                    int[]           preconditionSkillZoneNums  = skillAnalysisData.GetValues <int>(id, "correlationBeforeZoneCount");     //前置技能组加点
                    int             preconditionSkillZoneCount = preconditionSkillZones.Length < preconditionSkillZoneNums.Length ? preconditionSkillZones.Length : preconditionSkillZoneNums.Length;
                    for (int j = 0; j < preconditionSkillZoneCount; j++)
                    {
                        if (preconditionSkillZones[j] != EnumSkillZone.None)
                        {
                            skillBaseStruct.skillPrecondition.mustSkillZonePointDic.Add(preconditionSkillZones[j], preconditionSkillZoneNums[j]);
                        }
                    }
                    EnumSkillType[] preconditionSkills     = skillAnalysisData.GetEnums <EnumSkillType>(id, "correlationBeforeSkill"); //前置技能数组
                    int[]           preconditionSkillNums  = skillAnalysisData.GetValues <int>(id, "correlationBeforeSkillCount");     //前置技能加点
                    int             preconditionSkillCount = preconditionSkillZones.Length < preconditionSkillNums.Length ? preconditionSkillZones.Length : preconditionSkillNums.Length;
                    for (int j = 0; j < preconditionSkillCount; j++)
                    {
                        if (preconditionSkills[j] != EnumSkillType.None)
                        {
                            skillBaseStruct.skillPrecondition.mustSkillPointDic.Add(preconditionSkills[j], preconditionSkillNums[j]);
                        }
                    }
                    //技能的技能等级以及属性
                    skillBaseStruct.maxLevel = skillAnalysisData.GetValue <int>(id, "skillLevel");
                    skillBaseStruct.skillAttributeStructs = new SkillAttributeStruct[skillBaseStruct.maxLevel];
                    Dictionary <string, Array> skillAttributeStructDic = new Dictionary <string, Array>();
                    Type        skillAttributeStructType       = typeof(SkillAttributeStruct);
                    FieldInfo[] skillAttributeStructFieldInfos = skillAttributeStructType.GetFields();
                    foreach (FieldInfo fieldInfo in skillAttributeStructFieldInfos)
                    {
                        FieldExplanAttribute fieldExplan = fieldInfo.GetCustomAttributes(typeof(FieldExplanAttribute), false).OfType <FieldExplanAttribute>().FirstOrDefault();
                        if (fieldExplan == null)
                        {
                            continue;
                        }
                        object[] skillAttributeStructValue = skillAnalysisData.GetValues(fieldInfo.FieldType, id, fieldExplan.GetExplan(1));//explan的第一个下标表示说明
                        if (skillAttributeStructValue.Length == skillBaseStruct.maxLevel)
                        {
                            skillAttributeStructDic.Add(fieldInfo.Name, skillAttributeStructValue);
                        }
                    }
                    for (int j = 0; j < skillBaseStruct.maxLevel; j++)
                    {
                        SkillAttributeStruct skillAttributeStruct = new SkillAttributeStruct();
                        foreach (FieldInfo fieldInfo in skillAttributeStructFieldInfos)
                        {
                            if (skillAttributeStructDic.ContainsKey(fieldInfo.Name))
                            {
                                if (skillAttributeStructDic[fieldInfo.Name].GetValue(j) == null)
                                {
                                    if (j > 0)
                                    {
                                        skillAttributeStructDic[fieldInfo.Name].SetValue(skillAttributeStructDic[fieldInfo.Name].GetValue(j - 1), j);
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                fieldInfo.SetValue(skillAttributeStruct, skillAttributeStructDic[fieldInfo.Name].GetValue(j));
                            }
                        }
                        skillBaseStruct.skillAttributeStructs[j] = skillAttributeStruct;
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置当前选中树节点应该显示的数据
        /// </summary>
        private void SetSelectNodeShowData()
        {
            if (selectNode == null || string.IsNullOrEmpty(projectFilePath))
            {
                return;
            }
            string id = selectNode.Name;

            FlowLayoutPanel_Other.Controls.Clear();

            IEnumerable <TabPage> allTabPage = TabControl_Setting.TabPages.OfType <TabPage>();

            EnumTypeComboBox[] enumTypeComboBoxs = allTabPage.Select(temp => temp.Controls.OfType <EnumTypeComboBox>()).Combine().ToArray();
            foreach (EnumTypeComboBox enumTypeComboBox in enumTypeComboBoxs)
            {
                enumTypeComboBox.InitListenControl();
                string fieldName = (string)enumTypeComboBox.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    enumTypeComboBox.TextValue = skillAnalysisData.GetValue <string>(id, fieldName);
                }
            }
            TextBox[] textBoxs = allTabPage.Select(temp => temp.Controls.OfType <TextBox>()).Combine().ToArray();
            foreach (TextBox textBox in textBoxs)
            {
                string fieldName = (string)textBox.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    textBox.Text = skillAnalysisData.GetValue <string>(id, fieldName);
                }
            }
            AutoArrayControl[] autoArrayControls = allTabPage.Select(temp => temp.Controls.OfType <AutoArrayControl>()).Combine().ToArray();
            foreach (AutoArrayControl autoArrayControl in autoArrayControls)
            {
                string fieldName = (string)autoArrayControl.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    string[] getValues = skillAnalysisData.GetValues <string>(id, fieldName);
                    string[] nowValues = autoArrayControl.TextValues;
                    int      index     = 0;
                    while (index < getValues.Length && index < nowValues.Length)
                    {
                        nowValues[index] = getValues[index];
                        index++;
                    }
                    autoArrayControl.TextValues = nowValues;
                }
            }
            TypeTextBox[] typeTextBoxs = allTabPage.Select(temp => temp.Controls.OfType <TypeTextBox>()).Combine().ToArray();
            foreach (TypeTextBox typeTextBox in typeTextBoxs)
            {
                string fieldName = (string)typeTextBox.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    typeTextBox.TextValue = skillAnalysisData.GetValue <string>(id, fieldName);
                }
            }
            AutoItemControl[] autoItemControls = allTabPage.Select(temp => temp.Controls.OfType <AutoItemControl>()).Combine().ToArray();
            foreach (AutoItemControl autoItemControl in autoItemControls)
            {
                autoItemControl.UpdateItems();
            }
            //处理技能属性(根据等级附加属性)
            AutoItemControl[] attributeSkillLevelControls = FlowLayoutPanel_Attribute.Controls.OfType <AutoItemControl>().ToArray();
            foreach (AutoItemControl attributeSkillLevelControl in attributeSkillLevelControls)
            {
                attributeSkillLevelControl.SkillAnalysisData = skillAnalysisData;
                attributeSkillLevelControl.Tag = id;
                attributeSkillLevelControl.UpdateItems(true);
            }
            //处理其他属性
            string[] oldOtherSettings = skillAnalysisData.GetValues <string>(id, "OtherFieldSet");
            string[] otherSplit       = new string[] { "***" };
            ComboBox_Other_Item.Items.Clear();
            Func <string, string> JCFZFunc = (target) => //解除封装
            {
                if (target.Length < 2)
                {
                    return("");
                }
                target = target.Remove(0, 1);
                target = target.Remove(target.Length - 1, 1);
                return(target);
            };

            foreach (string oldOtherSetting in oldOtherSettings)
            {
                string[] otherFieldSets = oldOtherSetting.Split(otherSplit, StringSplitOptions.RemoveEmptyEntries);
                if (otherFieldSets.Length == 7)
                {
                    AutoItemControl autoItemContorl = new AutoItemControl();
                    autoItemContorl.SkillAnalysisData = skillAnalysisData;
                    autoItemContorl.Tag = id;
                    AutoItemControl.ItemStruct itemStruct = autoItemContorl.CreateItem();
                    itemStruct.Label = JCFZFunc(otherFieldSets[0]);
                    itemStruct.Tag   = JCFZFunc(otherFieldSets[1]);
                    Type controlType = null;
                    try { controlType = Type.GetType(JCFZFunc(otherFieldSets[2])); } catch { }
                    itemStruct.ControlType = controlType;
                    itemStruct.TypeTag     = JCFZFunc(otherFieldSets[3]);
                    bool isArray = false;
                    try { isArray = bool.Parse(JCFZFunc(otherFieldSets[4])); } catch { }
                    itemStruct.IsArray = isArray;
                    int childCount = 0;
                    try { childCount = int.Parse(JCFZFunc(otherFieldSets[5])); } catch { }
                    itemStruct.ChildCount       = childCount;
                    itemStruct.ChildControlType = JCFZFunc(otherFieldSets[6]);

                    autoItemContorl.Size = new Size(Panel_Other.Size.Width / 2 - 7, Panel_Other.Size.Height / 3);
                    FlowLayoutPanel_Other.Controls.Add(autoItemContorl);
                    autoItemContorl.UpdateItems(true);
                    autoItemContorl.IsChangedValue = false;

                    ComboBox_Other_Item.Items.Add(itemStruct.Tag);
                }
            }
        }