GetValue() public method

public GetValue ( int row, int column ) : object
row int
column int
return object
Example #1
0
        void DebugExcel()
        {
            ExcelTable table = GetTable(pathName, 0);

            int rowCount     = table.NumberOfRows;
            int columnsCount = table.NumberOfColumns;

            for (int r = 1; r <= rowCount; r++)
            {
                string stRow = "";
                for (int c = 1; c < columnsCount; c++)
                {
                    stRow += table.GetValue(1, c) + ":" + table.GetValue(r, c) + "  ";
                }
                Debug.Log(stRow);
            }
        }
Example #2
0
        private void Start()
        {
            rayConf = ExcelHelper.LoadExcel(Application.streamingAssetsPath + @"\Conf\" + "vr射线颜色配置.xlsx");
            ExcelTable tb       = rayConf.Tables[0];
            int        rowCount = tb.NumberOfRows;

            for (int i = 2; i <= rowCount; i++)
            {
                Color color;
                tagS.Add(tb.GetValue(i, 1));
                ColorUtility.TryParseHtmlString("#" + tb.GetValue(i, 2), out color);
                colorS.Add(color);
                cursorSizeS.Add(int.Parse(tb.GetValue(i, 3)));

                //Debug.Log(tb.GetValue(i,1)+"    "+ tb.GetValue(i, 2) + "    " + tb.GetValue(i, 3) );
            }
        }
    public static void DrawCell(ExcelTable table, int row, int column)
    {
        ExcelTableCell cell = table.GetCell(row, column);

        if (cell != null)
        {
            switch (cell.Type)
            {
            case ExcelTableCellType.TextField:
            {
                string s = EditorGUILayout.TextField(cell.Value.ToString(), GUILayout.MaxWidth(cell.width));
                cell.Value = s;
                break;
            }

            case ExcelTableCellType.Label:
            {
                EditorGUILayout.LabelField(cell.Value.ToString(), GUILayout.MaxWidth(cell.width));
                break;
            }

            case ExcelTableCellType.Popup:
            {
                int selectIndex = cell.ValueSelected.IndexOf(cell.Value);
                if (selectIndex < 0)
                {
                    selectIndex = 0;
                }
                selectIndex = EditorGUILayout.Popup(selectIndex, cell.ValueSelected.ToArray(), GUILayout.MaxWidth(cell.width));
                cell.Value  = cell.ValueSelected[selectIndex];
                break;
            }

            default:
            {
                break;
            }
            }
        }
        else
        {
            string s = EditorGUILayout.TextField(table.GetValue(row, column).ToString());
            table.SetValue(row, column, s);
        }
    }
    public static void SaveExcel(Excel xls, string path)
    {
        FileInfo     output = new FileInfo(path);
        ExcelPackage ep     = new ExcelPackage();

        for (int i = 0; i < xls.Tables.Count; i++)
        {
            ExcelTable     table = xls.Tables[i];
            ExcelWorksheet sheet = ep.Workbook.Worksheets.Add(table.TableName);
            for (int row = 1; row <= table.NumberOfRows; row++)
            {
                for (int column = 1; column <= table.NumberOfColumns; column++)
                {
                    sheet.Cells[row, column].Value = table.GetValue(row, column);
                }
            }
        }
        ep.SaveAs(output);
    }
Example #5
0
 public static void DrawCell(ExcelTable table, int row, int column)
 {
     ExcelTableCell cell = table.GetCell(row, column);
     if (cell != null)
     {
         switch (cell.Type)
         {
             case ExcelTableCellType.TextField:
                 {
                     string s = EditorGUILayout.TextField(cell.Value.ToString(), GUILayout.MaxWidth(cell.width));
                     cell.Value = s;
                     break;
                 }
             case ExcelTableCellType.Label:
                 {
                     EditorGUILayout.LabelField(cell.Value.ToString(), GUILayout.MaxWidth(cell.width));
                     break;
                 }
             case ExcelTableCellType.Popup:
                 {
                     int selectIndex = cell.ValueSelected.IndexOf(cell.Value);
                     if (selectIndex < 0)
                     {
                         selectIndex = 0;
                     }
                     selectIndex = EditorGUILayout.Popup(selectIndex, cell.ValueSelected.ToArray(), GUILayout.MaxWidth(cell.width));
                     cell.Value = cell.ValueSelected[selectIndex];
                     break;
                 }
             default:
                 {
                     break;
                 }
         }
     }
     else
     {
         string s = EditorGUILayout.TextField(table.GetValue(row, column).ToString());
         table.SetValue(row, column, s);
     }
 }
Example #6
0
    static void MathBattles()
    {
        string     path  = ExcelEditor.DocsPath + "/数值平衡.xlsx";
        Excel      xls   = ExcelHelper.LoadExcel(path);
        ExcelTable table = xls.Tables[0];

        Debug.Log(table.TableName + "计算开始。。。");
        Debug.Log(table.NumberOfColumns + "," + table.NumberOfRows);
        List <string> areaNames = new List <string>()
        {
        };
        List <List <RoleData> > friends = new List <List <RoleData> >();
        List <List <RoleData> > enemys  = new List <List <RoleData> >();
        string   areaName;
        RoleData friend;
        RoleData enemy;

        for (int i = 1; i < table.NumberOfRows; i++)
        {
            areaName = table.GetValue(i, 1).ToString();
            if (!string.IsNullOrEmpty(areaName))
            {
                areaNames.Add(areaName);
                friends.Add(new List <RoleData>());
                enemys.Add(new List <RoleData>());
            }
            else
            {
                if (!string.IsNullOrEmpty(table.GetValue(i, 2).ToString()))
                {
                    friend                      = new RoleData();
                    friend.IsKnight             = true;
                    friend.Id                   = table.GetValue(i, 2).ToString();
                    friend.Name                 = table.GetValue(i, 3).ToString();
                    friend.Lv                   = int.Parse(table.GetValue(i, 4).ToString());
                    friend.DifLv4HP             = int.Parse(table.GetValue(i, 7).ToString());
                    friend.DifLv4PhysicsAttack  = int.Parse(table.GetValue(i, 9).ToString());
                    friend.DifLv4PhysicsDefense = int.Parse(table.GetValue(i, 11).ToString());
                    friend.DifLv4MagicAttack    = int.Parse(table.GetValue(i, 13).ToString());
                    friend.DifLv4MagicDefense   = int.Parse(table.GetValue(i, 15).ToString());
                    friend.DifLv4Dodge          = int.Parse(table.GetValue(i, 17).ToString());
                    //处理兵器秘籍
                    if (!string.IsNullOrEmpty(table.GetValue(i, 18).ToString()))
                    {
                        friend.ResourceWeaponDataId = table.GetValue(i, 18).ToString();
                    }
                    if (!string.IsNullOrEmpty(table.GetValue(i, 19).ToString()))
                    {
                        string[] fen = table.GetValue(i, 19).ToString().Split(new char[] { '|' });
                        foreach (string f in fen)
                        {
                            friend.ResourceBookDataIds.Add(f);
                        }
                    }
                    friend.Desc = table.GetValue(i, 20).ToString(); //记录武功类型 0为外功 1为内功
                    friend.MakeJsonToModel();
                    friend.Init();
                    friends[friends.Count - 1].Add(friend);
//                    Debug.Log(JsonManager.GetInstance().SerializeObject(friend));
                }
                if (!string.IsNullOrEmpty(table.GetValue(i, 21).ToString()))
                {
                    enemy                      = new RoleData();
                    enemy.IsKnight             = false;
                    enemy.Id                   = table.GetValue(i, 21).ToString();
                    enemy.Name                 = table.GetValue(i, 22).ToString();
                    enemy.Lv                   = int.Parse(table.GetValue(i, 23).ToString());
                    enemy.DifLv4HP             = int.Parse(table.GetValue(i, 26).ToString());
                    enemy.DifLv4PhysicsAttack  = int.Parse(table.GetValue(i, 28).ToString());
                    enemy.DifLv4PhysicsDefense = int.Parse(table.GetValue(i, 30).ToString());
                    enemy.DifLv4MagicAttack    = int.Parse(table.GetValue(i, 32).ToString());
                    enemy.DifLv4MagicDefense   = int.Parse(table.GetValue(i, 34).ToString());
                    enemy.DifLv4Dodge          = int.Parse(table.GetValue(i, 36).ToString());
                    enemy.Desc                 = table.GetValue(i, 37).ToString(); //记录武功类型 0为外功 1为内功
                    //处理兵器秘籍
                    if (!string.IsNullOrEmpty(table.GetValue(i, 38).ToString()))
                    {
                        enemy.ResourceWeaponDataId = table.GetValue(i, 38).ToString();
                    }
                    if (!string.IsNullOrEmpty(table.GetValue(i, 39).ToString()))
                    {
                        string[] fen = table.GetValue(i, 39).ToString().Split(new char[] { '|' });
                        foreach (string f in fen)
                        {
                            enemy.ResourceBookDataIds.Add(f);
                        }
                    }
                    enemy.MakeJsonToModel();
                    enemy.Init();
//                Debug.Log(JsonManager.GetInstance().SerializeObject(enemy));
                    enemys[enemys.Count - 1].Add(enemy);
                }
            }
        }

        //生成excel
        Excel      outputXls   = new Excel();
        ExcelTable outputTable = new ExcelTable();

        outputTable.TableName = "理想伤害统计";
        string outputPath = ExcelEditor.DocsPath + "/理想伤害统计表.xlsx";

        outputXls.Tables.Add(outputTable);

        outputXls.Tables[0].SetValue(1, 1, "战斗区域");
        outputXls.Tables[0].SetValue(1, 2, "攻方");
        outputXls.Tables[0].SetValue(1, 3, "守方");
        outputXls.Tables[0].SetValue(1, 4, "战斗次数");
        outputXls.Tables[0].SetValue(1, 5, "攻方胜利数");
        outputXls.Tables[0].SetValue(1, 6, "攻方失败数");
        outputXls.Tables[0].SetValue(1, 7, "攻方胜率");
        outputXls.Tables[0].SetValue(1, 8, "攻方命中率");
        outputXls.Tables[0].SetValue(1, 9, "攻方闪避率");
        outputXls.Tables[0].SetValue(1, 10, "攻方HP平均余量");
        outputXls.Tables[0].SetValue(1, 11, "平均持续招数");
        outputXls.Tables[0].SetValue(1, 12, "攻方兵器");
        outputXls.Tables[0].SetValue(1, 13, "攻方秘籍");
        outputXls.Tables[0].SetValue(1, 14, "守方兵器");
        outputXls.Tables[0].SetValue(1, 15, "守方秘籍");
        outputXls.Tables[0].SetValue(1, 16, "守方HP平均余量");

        int rowIndex = 1;

        //假设在单位战斗次数中没次攻击都100%成功
        int fightTimes = 20;
        int times;
        int winTimes;
        int failTimes; //出招次数
        int attackTimes;
        int hitedTimes;
        int missTimes;
        int freindLeftHP;
        int enemyLeftHP;
        int maxRounds = 300;
        int rounds;

        List <BuffData> teamBuffs  = new List <BuffData>();
        List <BuffData> enemyBuffs = new List <BuffData>();

        for (int i = 0, len0 = friends.Count; i < len0; i++)
        {
            for (int j = 0, len1 = friends[i].Count; j < len1; j++)
            {
                friend = friends[i][j];
                for (int k = 0, len3 = enemys[i].Count; k < len3; k++)
                {
                    enemy        = enemys[i][k];
                    times        = fightTimes;
                    winTimes     = 0;
                    failTimes    = 0;
                    attackTimes  = 0;
                    hitedTimes   = 0;
                    missTimes    = 0;
                    freindLeftHP = 0;
                    enemyLeftHP  = 0;
                    while (times-- > 0)
                    {
                        friend.HP = friend.MaxHP;
                        enemy.HP  = enemy.MaxHP;
                        teamBuffs.Clear();
                        enemyBuffs.Clear();
                        rounds = maxRounds;
                        while (rounds > 0 && friend.HP > 0 && enemy.HP > 0)
                        {
                            if (friend.AttackSpeed >= enemy.AttackSpeed)
                            {
                                if (friend.HP > 0)
                                {
                                    attackTimes++; //记录总的出手次数
                                    if (friend.IsHited(enemy))
                                    {
//                                        enemy.HP -= friend.Desc == "0" ? friend.GetPhysicsDamage(enemy) : friend.GetMagicDamage(enemy);
                                        dealInjury(friend, enemy, teamBuffs, enemyBuffs);
                                        hitedTimes++; //记录命中次数
                                    }
                                }
                                if (enemy.HP > 0)
                                {
                                    if (enemy.IsHited(friend))
                                    {
//                                        friend.HP -= enemy.Desc == "0" ? enemy.GetPhysicsDamage(enemy) : enemy.GetMagicDamage(enemy);
                                        dealInjury(enemy, friend, enemyBuffs, teamBuffs);
                                    }
                                    else
                                    {
                                        missTimes++; //记录闪避次数
                                    }
                                }
                            }
                            else
                            {
                                if (enemy.HP > 0)
                                {
                                    if (enemy.IsHited(friend))
                                    {
//                                        friend.HP -= enemy.Desc == "0" ? enemy.GetPhysicsDamage(enemy) : enemy.GetMagicDamage(enemy);
                                        dealInjury(enemy, friend, enemyBuffs, teamBuffs);
                                    }
                                    else
                                    {
                                        missTimes++; //记录闪避次数
                                    }
                                }
                                if (friend.HP > 0)
                                {
                                    attackTimes++; //记录总的出手次数
                                    if (friend.IsHited(enemy))
                                    {
//                                        enemy.HP -= friend.Desc == "0" ? friend.GetPhysicsDamage(enemy) : friend.GetMagicDamage(enemy);
                                        dealInjury(friend, enemy, teamBuffs, enemyBuffs);
                                        hitedTimes++; //记录命中次数
                                    }
                                }
                            }
                            rounds--; //回合数
                            buffsAction(friend, teamBuffs);
                            buffsAction(enemy, enemyBuffs);
                        }
                        if (enemy.HP <= 0)
                        {
                            winTimes++; //记录获胜次数
                            freindLeftHP += Mathf.Clamp(friend.HP, 0, friend.HP);
                        }
                        else if (friend.HP <= 0)
                        {
                            failTimes++; //记录失败次数
                            enemyLeftHP += Mathf.Clamp(enemy.HP, 0, enemy.HP);
                        }
                    }
//                    Debug.Log(string.Format("{0}与{1}战斗次数:{2},胜利{3}次,失败{4}次, 胜率:{5}%,命中率:{6}%,闪避率:{7}%,平均气血剩余值:{8},平均持续招数:{9}",
//                        friend.Name,
//                        enemy.Name,
//                        fightTimes,
//                        winTimes,
//                        failTimes,
//                        (int)((float)winTimes / (float)fightTimes * 100),
//                        (int)((float)hitedTimes / (float)attackTimes * 100),
//                        (int)((float)missTimes / (float)attackTimes * 100),
//                        winTimes > 0 ?freindLeftHP / winTimes : 0,
//                        (float)attackTimes / (float)fightTimes));
                    rowIndex++;
                    outputXls.Tables[0].SetValue(rowIndex, 1, areaNames[i]);
                    outputXls.Tables[0].SetValue(rowIndex, 2, friend.Name);
                    outputXls.Tables[0].SetValue(rowIndex, 3, enemy.Name);
                    outputXls.Tables[0].SetValue(rowIndex, 4, fightTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 5, winTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 6, failTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 7, ((int)((float)winTimes / (float)fightTimes * 100)).ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 8, ((int)((float)hitedTimes / (float)attackTimes * 100)).ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 9, ((int)((float)missTimes / (float)attackTimes * 100)).ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 10, (winTimes > 0 ? freindLeftHP / winTimes : 0).ToString() + (winTimes > 0 ? string.Format("/{0}({1}%)", friend.MaxHP, (int)((float)(freindLeftHP / winTimes) / (float)friend.MaxHP * 100)) : ""));
                    outputXls.Tables[0].SetValue(rowIndex, 11, ((float)attackTimes / (float)fightTimes).ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 12, friend.Weapon != null ? friend.Weapon.Name : "");
                    string friendBookNames = "";
                    foreach (BookData book in friend.Books)
                    {
                        friendBookNames += book.Name + "|";
                    }
                    if (friendBookNames.Length > 1)
                    {
                        friendBookNames = friendBookNames.Remove(friendBookNames.Length - 1, 1);
                    }
                    outputXls.Tables[0].SetValue(rowIndex, 13, friendBookNames);
                    outputXls.Tables[0].SetValue(rowIndex, 14, enemy.Weapon != null ? enemy.Weapon.Name : "");
                    string enemyBookNames = "";
                    foreach (BookData book in enemy.Books)
                    {
                        enemyBookNames += book.Name + "|";
                    }
                    if (enemyBookNames.Length > 1)
                    {
                        enemyBookNames = enemyBookNames.Remove(enemyBookNames.Length - 1, 1);
                    }
                    outputXls.Tables[0].SetValue(rowIndex, 15, enemyBookNames);
                    outputXls.Tables[0].SetValue(rowIndex, 16, (failTimes > 0 ? enemyLeftHP / failTimes : 0).ToString() + (failTimes > 0 ? string.Format("/{0}({1}%)", enemy.MaxHP, (int)((float)(enemyLeftHP / failTimes) / (float)enemy.MaxHP * 100)) : ""));
                }
            }
            rowIndex++;
        }

        ExcelHelper.SaveExcel(outputXls, outputPath); //生成excel

        Debug.Log(table.TableName + "计算结束,请查看原表。");
    }
Example #7
0
    public bool GenerateCS(ExcelTable table)
    {
        string moudle = File.ReadAllText(ModelPath);

        string properties  = "";
        string parse       = "";
        int    tableColumn = 0;

        try
        {
            for (int j = 1; j <= table.NumberOfColumns; j++)
            {
                tableColumn = j;
                string propName = table.GetValue(FieldNameLine, j).ToString();
                string propType = table.GetValue(FieldTypeLine, j).ToString().ToLower();
                if (!string.IsNullOrEmpty(IgnoreSymbol) && propName.StartsWith(IgnoreSymbol))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(propName) || string.IsNullOrEmpty(propType))
                {
                    continue;
                }
                if (properties.Length == 0)
                {
                    properties += string.Format("\tpublic {0} {1};\n", propType, propName);
                    if (propType.Equals("string"))
                    {
                        properties += "\tpublic override string StringIdentity(){ return " + propName + "; }\n";
                    }
                    else
                    {
                        properties += "\tpublic override int Identity(){ return " + propName + "; }\n";
                    }
                }
                else
                {
                    properties += string.Format("\tpublic {0} {1};\n", propType, propName);
                }

                if (propType == "string")
                {
                    parse += string.Format("\t\t{0} = data[\"{1}\"].ToString();\n", propName, propName);
                }
                else if (propType == "bool")
                {
                    parse += string.Format("\t\t{0} = data[\"{1}\"].ToString() != \"0\";\n", propName, propName);
                }
                else if (propType == "int" || propType == "float" || propType == "double")
                {
                    parse += string.Format("\t\t{0} = {1}.Parse(data[\"{2}\"].ToString());\n", propName, propType, propName);
                }
                else if (propType == "string[]")
                {
                    string subType = propType.Replace("[]", "");
                    parse += string.Format("\t\tstring {0}_str = data[\"{1}\"].ToString();\n", propName, propName);
                    parse += "\t\tif(" + propName + "_str.Length > 0) { \n";
                    parse += string.Format("\t\t {0} = data[\"{1}\"].ToString().Split (';');\n", propName, propName);
                    string elseStr = string.Format("{0} = new {1}[0];", propName, subType);
                    parse += "\t\t} else {" + elseStr + "}\n";
                }
                else if (propType == "int[]" || propType == "float[]" || propType == "double[]")
                {
                    string subType = propType.Replace("[]", "");
                    parse += string.Format("\t\tstring {0}_str = data[\"{1}\"].ToString();\n", propName, propName);
                    parse += "\t\tif(" + propName + "_str.Length > 0) { \n";
                    parse += string.Format("\t\tstring[] {0}_data = data[\"{1}\"].ToString().Split (';');\n", propName, propName);
                    parse += string.Format("\t\t{0} = new {1}[{2}_data.Length];\n", propName, subType, propName);
                    parse += "\t\tfor (int i = 0; i < " + propName + "_data.Length; i++) { " + propName + "[i] = " + subType + ".Parse (" + propName + "_data [i]);}\n";
                    string elseStr = string.Format("{0} = new {1}[0];", propName, subType);
                    parse += "\t\t} else {" + elseStr + "}\n";
                }
                else
                {
                    Debug.LogError("generate .cs failed! " + propType + " not a valid type" + " " + "table:" + table.TableName);
                    return(false);
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
            Debug.LogError("generate .cs failed: " + table.TableName + "!" + " " + "table:" + table.TableName);
            return(false);
        }
        moudle = moudle.Replace("{0}", table.TableName + "Item");
        moudle = moudle.Replace("{1}", properties);
        moudle = moudle.Replace("{2}", table.TableName + "Item");
        moudle = moudle.Replace("{3}", parse);
        string path = Application.dataPath + "/Scripts/Model/" + table.TableName + "Item.cs";
        string str  = string.Empty;

        if (File.Exists(path))
        {
            str = File.ReadAllText(path);
        }
        string directory = Path.GetDirectoryName(path);

        Debug.LogError(directory);
        if (!Directory.Exists(directory))
        {
            Directory.CreateDirectory(directory);
        }
        if (str != moudle)
        {
            Debug.LogError("change " + table.TableName + ".cs");
            File.WriteAllText(path, moudle);
        }
        else
        {
            //			Debug.LogError ("no change " + table.TableName + ".cs");
        }
        AssetDatabase.Refresh();
        return(true);
    }
Example #8
0
    static void MathBattleLogics()
    {
        string     path  = ExcelEditor.DocsPath + "/数值平衡.xlsx";
        Excel      xls   = ExcelHelper.LoadExcel(path);
        ExcelTable table = xls.Tables[0];

        Debug.Log(table.TableName + "计算开始。。。");
        Debug.Log(table.NumberOfColumns + "," + table.NumberOfRows);
        List <string> areaNames = new List <string>()
        {
        };
        List <List <RoleData> > friends = new List <List <RoleData> >();
        List <List <RoleData> > enemys  = new List <List <RoleData> >();
        string   areaName;
        RoleData friend;
        RoleData enemy;

        for (int i = 1; i < table.NumberOfRows; i++)
        {
            areaName = table.GetValue(i, 1).ToString();
            if (areaName.IndexOf("x") >= 0)
            {
                continue;
            }
            if (!string.IsNullOrEmpty(areaName))
            {
                areaNames.Add(areaName);
                friends.Add(new List <RoleData>());
                enemys.Add(new List <RoleData>());
            }
            else
            {
                if (!string.IsNullOrEmpty(table.GetValue(i, 2).ToString()))
                {
                    friend                      = new RoleData();
                    friend.TeamName             = "Team";
                    friend.IsKnight             = true;
                    friend.Id                   = table.GetValue(i, 2).ToString();
                    friend.Name                 = table.GetValue(i, 3).ToString();
                    friend.Lv                   = int.Parse(table.GetValue(i, 4).ToString());
                    friend.DifLv4HP             = int.Parse(table.GetValue(i, 7).ToString());
                    friend.DifLv4PhysicsAttack  = int.Parse(table.GetValue(i, 9).ToString());
                    friend.DifLv4PhysicsDefense = int.Parse(table.GetValue(i, 11).ToString());
                    friend.DifLv4MagicAttack    = int.Parse(table.GetValue(i, 13).ToString());
                    friend.DifLv4MagicDefense   = int.Parse(table.GetValue(i, 15).ToString());
                    friend.DifLv4Dodge          = int.Parse(table.GetValue(i, 17).ToString());
                    //处理兵器秘籍
                    if (!string.IsNullOrEmpty(table.GetValue(i, 18).ToString()))
                    {
                        friend.ResourceWeaponDataId = table.GetValue(i, 18).ToString();
                    }
                    if (!string.IsNullOrEmpty(table.GetValue(i, 19).ToString()))
                    {
                        string[] fen = table.GetValue(i, 19).ToString().Split(new char[] { '|' });
                        foreach (string f in fen)
                        {
                            friend.ResourceBookDataIds.Add(f);
                        }
                    }
                    friend.Desc = table.GetValue(i, 20).ToString(); //记录武功类型 0为外功 1为内功
                    friend.Init();
                    friends[friends.Count - 1].Add(friend);
                    //                    Debug.Log(JsonManager.GetInstance().SerializeObject(friend));
                }
                if (!string.IsNullOrEmpty(table.GetValue(i, 21).ToString()))
                {
                    enemy                      = new RoleData();
                    enemy.TeamName             = "Enemy";
                    enemy.IsKnight             = false;
                    enemy.Id                   = table.GetValue(i, 21).ToString();
                    enemy.Name                 = table.GetValue(i, 22).ToString();
                    enemy.Lv                   = int.Parse(table.GetValue(i, 23).ToString());
                    enemy.DifLv4HP             = int.Parse(table.GetValue(i, 26).ToString());
                    enemy.DifLv4PhysicsAttack  = int.Parse(table.GetValue(i, 28).ToString());
                    enemy.DifLv4PhysicsDefense = int.Parse(table.GetValue(i, 30).ToString());
                    enemy.DifLv4MagicAttack    = int.Parse(table.GetValue(i, 32).ToString());
                    enemy.DifLv4MagicDefense   = int.Parse(table.GetValue(i, 34).ToString());
                    enemy.DifLv4Dodge          = int.Parse(table.GetValue(i, 36).ToString());
                    enemy.Desc                 = table.GetValue(i, 37).ToString(); //记录武功类型 0为外功 1为内功
                    //处理兵器秘籍
                    if (!string.IsNullOrEmpty(table.GetValue(i, 38).ToString()))
                    {
                        enemy.ResourceWeaponDataId = table.GetValue(i, 38).ToString();
                    }
                    if (!string.IsNullOrEmpty(table.GetValue(i, 39).ToString()))
                    {
                        string[] fen = table.GetValue(i, 39).ToString().Split(new char[] { '|' });
                        foreach (string f in fen)
                        {
                            enemy.ResourceBookDataIds.Add(f);
                        }
                    }
                    enemy.Init();
                    //                Debug.Log(JsonManager.GetInstance().SerializeObject(enemy));
                    enemys[enemys.Count - 1].Add(enemy);
                }
            }
        }

        //生成excel
        Excel      outputXls   = new Excel();
        ExcelTable outputTable = new ExcelTable();

        outputTable.TableName = "理想伤害统计";
        string outputPath = ExcelEditor.DocsPath + "/理想伤害统计表(新).xlsx";

        outputXls.Tables.Add(outputTable);

        outputXls.Tables[0].SetValue(1, 1, "战斗区域");
        outputXls.Tables[0].SetValue(1, 2, "攻方");
        outputXls.Tables[0].SetValue(1, 3, "守方");
        outputXls.Tables[0].SetValue(1, 4, "战斗次数");
        outputXls.Tables[0].SetValue(1, 5, "攻方胜利数");
        outputXls.Tables[0].SetValue(1, 6, "守方胜利数");
        outputXls.Tables[0].SetValue(1, 7, "攻方胜率");
        outputXls.Tables[0].SetValue(1, 8, "攻方平均出招数");
        outputXls.Tables[0].SetValue(1, 9, "攻方命中率");
        outputXls.Tables[0].SetValue(1, 10, "攻方闪避率");
        outputXls.Tables[0].SetValue(1, 11, "守方平均出招数");
        outputXls.Tables[0].SetValue(1, 12, "守方命中率");
        outputXls.Tables[0].SetValue(1, 13, "守方闪避率");
        outputXls.Tables[0].SetValue(1, 14, "攻方HP平均余量");
        outputXls.Tables[0].SetValue(1, 15, "守方HP平均余量");
        outputXls.Tables[0].SetValue(1, 16, "攻方兵器");
        outputXls.Tables[0].SetValue(1, 17, "攻方秘籍");
        outputXls.Tables[0].SetValue(1, 18, "守方兵器");
        outputXls.Tables[0].SetValue(1, 19, "守方秘籍");

        int rowIndex = 1;

        int             fightTimes = 10;
        int             times;
        float           teamWinTimes;
        float           enemyWinTimes; //出招次数
        float           teamAttackTimes;
        float           enemyAttackTimes;
        float           teamHitedTimes;
        float           enemyHitedTimes;
        float           teamMissTimes;
        float           enemyMissTimes;
        int             freindLeftHP;
        int             enemyLeftHP;
        List <BuffData> teamBuffs  = new List <BuffData>();
        List <BuffData> enemyBuffs = new List <BuffData>();
        BattleProcess   process;

        for (int i = 0, len0 = friends.Count; i < len0; i++)
        {
            for (int j = 0, len1 = friends[i].Count; j < len1; j++)
            {
                friend = friends[i][j];
                for (int k = 0, len3 = enemys[i].Count; k < len3; k++)
                {
                    enemy            = enemys[i][k];
                    times            = fightTimes;
                    teamWinTimes     = 0;
                    enemyWinTimes    = 0;
                    teamAttackTimes  = 0;
                    enemyAttackTimes = 0;
                    teamHitedTimes   = 0;
                    enemyHitedTimes  = 0;
                    teamMissTimes    = 0;
                    enemyMissTimes   = 0;
                    freindLeftHP     = 0;
                    enemyLeftHP      = 0;
                    while (times-- > 0)
                    {
                        friend.MakeJsonToModel();
                        enemy.MakeJsonToModel();
                        friend.HP = friend.MaxHP;
                        enemy.HP  = enemy.MaxHP;
                        BattleLogic.Instance.Init(new List <RoleData>()
                        {
                            friend
                        }, new List <List <SecretData> >()
                        {
                            DbManager.Instance.GetSecretsBelongBooks(friend.ResourceBookDataIds)
                        }, new List <RoleData>()
                        {
                            enemy
                        });
                        while (!BattleLogic.Instance.IsFail() && !BattleLogic.Instance.IsWin())
                        {
                            BattleLogic.Instance.Action();
                        }
                        if (BattleLogic.Instance.IsWin())
                        {
                            teamWinTimes++;
                        }
                        if (BattleLogic.Instance.IsFail())
                        {
                            enemyWinTimes++;
                        }
                        freindLeftHP += BattleLogic.Instance.CurrentTeamRole.HP;
                        enemyLeftHP  += BattleLogic.Instance.CurrentEnemyRole.HP;
                        while (BattleLogic.Instance.GetProcessCount() > 0)
                        {
                            process = BattleLogic.Instance.PopProcess();
                            switch (process.Type)
                            {
                            case BattleProcessType.Attack:
                                if (process.IsTeam)
                                {
                                    teamAttackTimes++;
                                    if (process.IsMissed)
                                    {
                                        enemyMissTimes++;
                                    }
                                    else
                                    {
                                        teamHitedTimes++;
                                    }
                                }
                                else
                                {
                                    enemyAttackTimes++;
                                    if (process.IsMissed)
                                    {
                                        teamMissTimes++;
                                    }
                                    else
                                    {
                                        enemyHitedTimes++;
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
//                    teamWinTimes = teamWinTimes;
//                    enemyWinTimes = enemyWinTimes;
                    teamAttackTimes  = teamAttackTimes / fightTimes;
                    enemyAttackTimes = enemyAttackTimes / fightTimes;
                    teamHitedTimes   = teamHitedTimes / fightTimes;
                    enemyHitedTimes  = enemyHitedTimes / fightTimes;
                    teamMissTimes    = teamMissTimes / fightTimes;
                    enemyMissTimes   = enemyMissTimes / fightTimes;

                    freindLeftHP = teamWinTimes > 0 ? (int)((float)freindLeftHP / teamWinTimes) : 0;
                    enemyLeftHP  = enemyWinTimes > 0 ? (int)((float)enemyLeftHP / enemyWinTimes) : 0;

                    rowIndex++;
                    outputXls.Tables[0].SetValue(rowIndex, 1, areaNames[i]);
                    outputXls.Tables[0].SetValue(rowIndex, 2, friend.Name);
                    outputXls.Tables[0].SetValue(rowIndex, 3, enemy.Name);
                    outputXls.Tables[0].SetValue(rowIndex, 4, fightTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 5, teamWinTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 6, enemyWinTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 7, ((int)((float)teamWinTimes / (float)fightTimes * 100)).ToString() + "%");
                    outputXls.Tables[0].SetValue(rowIndex, 8, teamAttackTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 9, (teamAttackTimes > 0 ? ((int)((float)teamHitedTimes / (float)teamAttackTimes * 100)) : 0) + "%");
                    outputXls.Tables[0].SetValue(rowIndex, 10, (enemyAttackTimes > 0 ? ((int)((float)teamMissTimes / (float)enemyAttackTimes * 100)) : 0) + "%");
                    outputXls.Tables[0].SetValue(rowIndex, 11, enemyAttackTimes.ToString());
                    outputXls.Tables[0].SetValue(rowIndex, 12, (enemyAttackTimes > 0 ? ((int)((float)enemyHitedTimes / (float)enemyAttackTimes * 100)) : 0) + "%");
                    outputXls.Tables[0].SetValue(rowIndex, 13, (teamAttackTimes > 0 ? ((int)((float)enemyMissTimes / (float)teamAttackTimes * 100)) : 0) + "%");
                    outputXls.Tables[0].SetValue(rowIndex, 14, freindLeftHP + (teamWinTimes > 0 ? string.Format("/{0}({1}%)", friend.MaxHP, (int)((float)freindLeftHP / (float)friend.MaxHP * 100)) : ""));
                    outputXls.Tables[0].SetValue(rowIndex, 15, enemyLeftHP + (enemyWinTimes > 0 ? string.Format("/{0}({1}%)", enemy.MaxHP, (int)((float)enemyLeftHP / (float)enemy.MaxHP * 100)) : ""));
                    outputXls.Tables[0].SetValue(rowIndex, 16, friend.Weapon != null ? friend.Weapon.Name : "");
                    string friendBookNames = "";
                    foreach (BookData book in friend.Books)
                    {
                        friendBookNames += book.Name + "|";
                    }
                    if (friendBookNames.Length > 1)
                    {
                        friendBookNames = friendBookNames.Remove(friendBookNames.Length - 1, 1);
                    }
                    outputXls.Tables[0].SetValue(rowIndex, 17, friendBookNames);
                    outputXls.Tables[0].SetValue(rowIndex, 18, enemy.Weapon != null ? enemy.Weapon.Name : "");
                    string enemyBookNames = "";
                    foreach (BookData book in enemy.Books)
                    {
                        enemyBookNames += book.Name + "|";
                    }
                    if (enemyBookNames.Length > 1)
                    {
                        enemyBookNames = enemyBookNames.Remove(enemyBookNames.Length - 1, 1);
                    }
                    outputXls.Tables[0].SetValue(rowIndex, 19, enemyBookNames);
//                    Debug.Log(friend.Name + " VS " + enemy.Name + ", 战斗:" + fightTimes + ", 攻方胜利:" + teamWinTimes + ", 攻方出手:" + teamAttackTimes + ", 攻方命中:" + teamHitedTimes + ", 攻方闪避" + teamMissTimes + ", 攻方剩余血量:" + freindLeftHP + "(" + (int)((float)freindLeftHP / (float)BattleLogic.Instance.CurrentTeamRole.MaxHP * 100.0f) + "%)" + " - 守方胜利:" + enemyWinTimes + ", 守方出手:" + enemyAttackTimes + ", 守方命中:" + enemyHitedTimes + ", 守方闪避" + enemyMissTimes + ", 守方剩余血量:" + enemyLeftHP + "(" + (int)((float)enemyLeftHP / (float)BattleLogic.Instance.CurrentEnemyRole.MaxHP * 100.0f) + "%)");
                }
            }
            rowIndex++;
        }
        ExcelHelper.SaveExcel(outputXls, outputPath); //生成excel

        Debug.Log(table.TableName + "计算结束,请查看原表。");
    }
Example #9
0
        //绘制窗口时调用
        void OnGUI()
        {
            data = null;

            GUILayout.BeginArea(new Rect(5, 5, 200, 20));
            GUI.Label(new Rect(0, 0, 50, 18), "搜索名称:");
            searchKeyword = GUI.TextField(new Rect(55, 0, 100, 18), searchKeyword);
            if (GUI.Button(new Rect(160, 0, 30, 18), "搜索"))
            {
                selGridInt = 0;
                fetchData(searchKeyword);
            }
            GUILayout.EndArea();

            GUILayout.BeginArea(new Rect(205, 5, 200, 20));
            if (GUI.Button(new Rect(0, 0, 80, 18), "生成对应简表"))
            {
                //生成excel
                Excel      outputXls   = new Excel();
                ExcelTable outputTable = new ExcelTable();
                outputTable.TableName = "战斗角色简表";
                string outputPath = ExcelEditor.DocsPath + "/战斗角色简表.xlsx";
                outputXls.Tables.Add(outputTable);

                outputXls.Tables[0].SetValue(1, 1, "角色id");
                outputXls.Tables[0].SetValue(1, 2, "名称");
                outputXls.Tables[0].SetValue(1, 3, "兵器");
                outputXls.Tables[0].SetValue(1, 4, "秘籍");

                int      rowIndex = 2;
                RoleData role;
                string   booksStr;
                for (int i = 0, len = allRoleDatas.Count; i < len; i++)
                {
                    role = allRoleDatas[i];
                    if (role == null)
                    {
                        continue;
                    }
                    outputXls.Tables[0].SetValue(rowIndex, 1, role.Id);
                    outputXls.Tables[0].SetValue(rowIndex, 2, role.Name);
                    outputXls.Tables[0].SetValue(rowIndex, 3, role.ResourceWeaponDataId);
                    booksStr = "";
                    for (int j = 0, len2 = role.ResourceBookDataIds.Count; j < len2; j++)
                    {
                        if (j > 0)
                        {
                            booksStr += "|";
                        }
                        booksStr += role.ResourceBookDataIds[j];
                    }
                    outputXls.Tables[0].SetValue(rowIndex, 4, booksStr);
                    rowIndex++;
                }
                ExcelHelper.SaveExcel(outputXls, outputPath); //生成excel

                Debug.Log("对应简表创建完毕");
            }

            if (GUI.Button(new Rect(85, 0, 80, 18), "加载角色数据"))
            {
                string        path      = ExcelEditor.DocsPath + "/数值平衡.xlsx";
                Excel         xls       = ExcelHelper.LoadExcel(path);
                ExcelTable    table     = xls.Tables[0];
                List <string> areaNames = new List <string>()
                {
                };
                string   areaName;
                RoleData friend;
                RoleData enemy;
                for (int i = 1; i <= table.NumberOfRows; i++)
                {
                    areaName = table.GetValue(i, 1).ToString();
                    if (!string.IsNullOrEmpty(areaName))
                    {
                        areaNames.Add(areaName);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(table.GetValue(i, 2).ToString()))
                        {
                            if (dataMapping.ContainsKey(table.GetValue(i, 2).ToString()))
                            {
                                friend                      = dataMapping[table.GetValue(i, 2).ToString()];
                                friend.IsKnight             = true;
                                friend.IsBoss               = false;
                                friend.Id                   = table.GetValue(i, 2).ToString();
                                friend.Name                 = table.GetValue(i, 3).ToString();
                                friend.Lv                   = int.Parse(table.GetValue(i, 4).ToString());
                                friend.DifLv4HP             = int.Parse(table.GetValue(i, 7).ToString());
                                friend.DifLv4PhysicsAttack  = int.Parse(table.GetValue(i, 9).ToString());
                                friend.DifLv4PhysicsDefense = int.Parse(table.GetValue(i, 11).ToString());
                                friend.DifLv4MagicAttack    = int.Parse(table.GetValue(i, 13).ToString());
                                friend.DifLv4MagicDefense   = int.Parse(table.GetValue(i, 15).ToString());
                                friend.DifLv4Dodge          = int.Parse(table.GetValue(i, 17).ToString());
                                friend.Desc                 = table.GetValue(i, 20).ToString(); //记录武功类型 0为外功 1为内功
                                //处理兵器秘籍
//                                if (!string.IsNullOrEmpty(table.GetValue(i, 18).ToString())) {
//                                    friend.ResourceWeaponDataId = table.GetValue(i, 18).ToString();
//                                }
//                                if (!string.IsNullOrEmpty(table.GetValue(i, 19).ToString())) {
//                                    string[] fen = table.GetValue(i, 19).ToString().Split(new char[] { '|' });
//                                    friend.ResourceBookDataIds.Clear();
//                                    foreach (string f in fen) {
//                                        friend.ResourceBookDataIds.Add(f);
//                                    }
//                                }
                                friend.InitAttribute();
                                Debug.Log(friend.Id + "," + friend.Name);
                            }
                        }
                        if (!string.IsNullOrEmpty(table.GetValue(i, 21).ToString()))
                        {
                            if (dataMapping.ContainsKey(table.GetValue(i, 21).ToString()))
                            {
                                enemy                      = dataMapping[table.GetValue(i, 21).ToString()];
                                enemy.IsKnight             = false;
                                enemy.IsBoss               = table.GetValue(i, 40).ToString() == "是";
                                enemy.Id                   = table.GetValue(i, 21).ToString();
                                enemy.Name                 = table.GetValue(i, 22).ToString();
                                enemy.Lv                   = int.Parse(table.GetValue(i, 23).ToString());
                                enemy.DifLv4HP             = int.Parse(table.GetValue(i, 26).ToString());
                                enemy.DifLv4PhysicsAttack  = int.Parse(table.GetValue(i, 28).ToString());
                                enemy.DifLv4PhysicsDefense = int.Parse(table.GetValue(i, 30).ToString());
                                enemy.DifLv4MagicAttack    = int.Parse(table.GetValue(i, 32).ToString());
                                enemy.DifLv4MagicDefense   = int.Parse(table.GetValue(i, 34).ToString());
                                enemy.DifLv4Dodge          = int.Parse(table.GetValue(i, 36).ToString());
                                enemy.Desc                 = table.GetValue(i, 37).ToString(); //记录武功类型 0为外功 1为内功
//                                //处理兵器秘籍
//                                if (!string.IsNullOrEmpty(table.GetValue(i, 38).ToString())) {
//                                    enemy.ResourceWeaponDataId = table.GetValue(i, 38).ToString();
//                                }
//                                if (!string.IsNullOrEmpty(table.GetValue(i, 39).ToString())) {
//                                    string[] fen = table.GetValue(i, 39).ToString().Split(new char[] { '|' });
//                                    enemy.ResourceBookDataIds.Clear();
//                                    foreach (string f in fen) {
//                                        enemy.ResourceBookDataIds.Add(f);
//                                    }
//                                }
                                enemy.InitAttribute();
                                Debug.Log(enemy.Id + "," + enemy.Name);
                            }
                        }
                    }
                }

                writeDataToJson();
                oldSelGridInt = -1;
                getData();
                fetchData(searchKeyword);
                this.ShowNotification(new GUIContent("数据加载成功"));
            }

            GUILayout.EndArea();

            float listStartX   = 5;
            float listStartY   = 25;
            float scrollHeight = Screen.currentResolution.height - 110;

            if (listNames != null && listNames.Count > 0)
            {
                float contextHeight = listNames.Count * 21;
                //开始滚动视图
                scrollPosition = GUI.BeginScrollView(new Rect(listStartX, listStartY, 200, scrollHeight), scrollPosition, new Rect(5, 5, 190, contextHeight), false, scrollHeight < contextHeight);

                selGridInt = GUILayout.SelectionGrid(selGridInt, listNames.ToArray(), 1, GUILayout.Width(190));
                selGridInt = selGridInt >= listNames.Count ? listNames.Count - 1 : selGridInt;
                data       = showListData[selGridInt];
                if (selGridInt != oldSelGridInt)
                {
                    oldSelGridInt = selGridInt;
                    showId        = data.Id;
                    roleName      = data.Name;
                    if (iconIdIndexs.ContainsKey(data.IconId))
                    {
                        iconIndex = iconIdIndexs[data.IconId];
                    }
                    else
                    {
                        iconIndex = 0;
                    }
                    if (iconTextureMappings.ContainsKey(data.IconId))
                    {
                        iconTexture = iconTextureMappings[data.IconId];
                    }
                    else
                    {
                        iconTexture = null;
                    }
                    occupationTypeIndex = occupationTypeIndexMapping[data.Occupation];
                    genderTypeIndex     = genderTypeIndexMapping[data.Gender];
                    if (halfBodyIdIndexs.ContainsKey(data.HalfBodyId))
                    {
                        halfBodyIdIndex = halfBodyIdIndexs[data.HalfBodyId];
                    }
                    else
                    {
                        halfBodyIdIndex = 0;
                    }
                    if (halfBodyTextureMappings.ContainsKey(data.HalfBodyId))
                    {
                        halfBodyTexture = halfBodyTextureMappings[data.HalfBodyId];
                    }
                    else
                    {
                        halfBodyTexture = null;
                    }
//                    data.InitAttribute();
                    roleDesc             = data.Desc;
                    hp                   = data.HP;
                    maxHp                = data.MaxHP;
                    physicsAttack        = data.PhysicsAttack;
                    physicsDefense       = data.PhysicsDefense;
                    magicAttack          = data.MagicAttack;
                    magicDefense         = data.MagicDefense;
                    attackSpeed          = data.AttackSpeed;
                    dodge                = data.Dodge;
                    lv                   = data.Lv;
                    difLv4HP             = data.DifLv4HP;
                    difLv4PhysicsAttack  = data.DifLv4PhysicsAttack;
                    difLv4PhysicsDefense = data.DifLv4PhysicsDefense;
                    difLv4MagicAttack    = data.DifLv4MagicAttack;
                    difLv4MagicDefense   = data.DifLv4MagicDefense;
                    difLv4Dodge          = data.DifLv4Dodge;
                    bookDataIdIndexes    = new List <int>();
                    string bookId;
                    for (int i = 0; i < 3; i++)
                    {
                        bookId = data.ResourceBookDataIds.Count > i ? data.ResourceBookDataIds[i] : "";
                        bookDataIdIndexes.Add(bookIdIndexs.ContainsKey(bookId) ? bookIdIndexs[bookId] : 0);
                    }
                    if (weaponIdIndexs.ContainsKey(data.ResourceWeaponDataId))
                    {
                        weaponDataIdIndex = weaponIdIndexs[data.ResourceWeaponDataId];
                    }
                    else
                    {
                        weaponDataIdIndex = 0;
                    }
                    effectSoundIdIndex  = soundIdIndexs.ContainsKey(data.DeadSoundId) ? soundIdIndexs[data.DeadSoundId] : 0;
                    isImmuneMaxHPReduce = data.IsImmuneMaxHPReduce;
                    isStatic            = data.IsStatic;
                    isKnight            = data.IsKnight;
                    isBoss = data.IsBoss;
                    showId = data.Id;
                    data.HometownCityId = data.HometownCityId == null ? "" : data.HometownCityId;
                    homedownCityIdIndex = allCitySceneIdIndexs.ContainsKey(data.HometownCityId) ? allCitySceneIdIndexs[data.HometownCityId] : 0;
                }
                //结束滚动视图
                GUI.EndScrollView();

                if (data != null)
                {
                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY, 800, 555));
                    if (iconTexture != null)
                    {
                        GUI.DrawTexture(new Rect(0, 0, 50, 50), iconTexture);
                    }

                    GUI.Label(new Rect(55, 0, 40, 18), "Id:");
                    showId = EditorGUI.TextField(new Rect(100, 0, 100, 18), showId);
                    GUI.Label(new Rect(205, 0, 40, 18), "姓名:");
                    roleName = EditorGUI.TextField(new Rect(250, 0, 100, 18), roleName);
                    GUI.Label(new Rect(355, 0, 40, 18), "性别:");
                    genderTypeIndex = EditorGUI.Popup(new Rect(400, 0, 100, 18), genderTypeIndex, genderTypeStrs.ToArray());
                    GUI.Label(new Rect(55, 20, 40, 18), "Icon:");
                    iconIndex = EditorGUI.Popup(new Rect(100, 20, 100, 18), iconIndex, iconNames.ToArray());
                    GUI.Label(new Rect(205, 20, 40, 18), "门派:");
                    occupationTypeIndex = EditorGUI.Popup(new Rect(250, 20, 100, 18), occupationTypeIndex, occupationTypeStrs.ToArray());
                    GUI.Label(new Rect(355, 20, 40, 18), "半身像:");
                    halfBodyIdIndex = EditorGUI.Popup(new Rect(400, 20, 100, 18), halfBodyIdIndex, halfBodyNames.ToArray());
                    GUI.Label(new Rect(55, 40, 40, 18), "描述:");
                    roleDesc = GUI.TextArea(new Rect(100, 40, 400, 60), roleDesc);
                    GUI.Label(new Rect(55, 105, 50, 18), "气血:");
                    EditorGUI.Slider(new Rect(100, 105, 165, 18), hp, 1, 1000000);
                    GUI.Label(new Rect(270, 105, 50, 18), "气血上限:");
                    EditorGUI.Slider(new Rect(335, 105, 165, 18), maxHp, 1, 1000000);
                    GUI.Label(new Rect(55, 125, 50, 18), "外功:");
                    EditorGUI.Slider(new Rect(100, 125, 165, 18), physicsAttack, 0, 100000);
                    GUI.Label(new Rect(270, 125, 50, 18), "外防:");
                    EditorGUI.Slider(new Rect(335, 125, 165, 18), physicsDefense, 0, 1000000);
                    GUI.Label(new Rect(55, 145, 50, 18), "内功:");
                    EditorGUI.Slider(new Rect(100, 145, 165, 18), magicAttack, 0, 100000);
                    GUI.Label(new Rect(270, 145, 50, 18), "内防:");
                    EditorGUI.Slider(new Rect(335, 145, 165, 18), magicDefense, 0, 1000000);
                    GUI.Label(new Rect(55, 165, 50, 18), "攻速:");
                    attackSpeed = EditorGUI.Slider(new Rect(100, 165, 165, 18), attackSpeed, 0, 50);
                    GUI.Label(new Rect(270, 165, 50, 18), "轻功:");
                    EditorGUI.Slider(new Rect(335, 165, 165, 18), dodge, 0, 200);
                    GUI.Label(new Rect(55, 185, 50, 18), "秘籍:");
                    bookDataIdIndexes[0] = EditorGUI.Popup(new Rect(110, 185, 100, 18), bookDataIdIndexes[0], bookNames.ToArray());
                    bookDataIdIndexes[1] = EditorGUI.Popup(new Rect(215, 185, 100, 18), bookDataIdIndexes[1], bookNames.ToArray());
                    bookDataIdIndexes[2] = EditorGUI.Popup(new Rect(320, 185, 100, 18), bookDataIdIndexes[2], bookNames.ToArray());
                    GUI.Label(new Rect(55, 205, 50, 18), "兵器:");
                    weaponDataIdIndex = EditorGUI.Popup(new Rect(110, 205, 100, 18), weaponDataIdIndex, weaponNames.ToArray());
                    GUI.Label(new Rect(215, 205, 50, 18), "音效:");
                    effectSoundIdIndex = EditorGUI.Popup(new Rect(270, 205, 100, 18), effectSoundIdIndex, soundNames.ToArray());
                    GUI.Label(new Rect(215, 225, 100, 18), "免疫气血上限衰减:");
                    isImmuneMaxHPReduce = EditorGUI.Toggle(new Rect(320, 225, 20, 18), isImmuneMaxHPReduce);
                    GUI.Label(new Rect(375, 205, 50, 18), "静态:");
                    isStatic = EditorGUI.Toggle(new Rect(405, 205, 20, 18), isStatic);
                    GUI.Label(new Rect(440, 205, 50, 18), "侠客:");
                    isKnight = EditorGUI.Toggle(new Rect(470, 205, 20, 18), isKnight);
                    GUI.Label(new Rect(375, 225, 50, 18), "Boss:");
                    isBoss = EditorGUI.Toggle(new Rect(405, 225, 20, 18), isBoss);
                    GUI.Label(new Rect(55, 225, 50, 18), "故乡:");
                    homedownCityIdIndex = EditorGUI.Popup(new Rect(110, 225, 100, 18), homedownCityIdIndex, allCitySceneNames.ToArray());
                    if (halfBodyTexture != null)
                    {
                        GUI.DrawTexture(new Rect(505, 0, 325, 260), halfBodyTexture);
                    }
                    if (oldIconIndex != iconIndex)
                    {
                        oldIconIndex = iconIndex;
                        iconTexture  = iconTextureMappings[icons[iconIndex].Id];
                    }
                    GUI.Label(new Rect(55, 245, 50, 18), "等级:");
                    try {
                        lv = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(110, 245, 40, 18), lv.ToString())), 1, 120);
                    }
                    catch (Exception e) {
                        lv = 1;
                    }
                    GUI.Label(new Rect(155, 245, 50, 18), "气血差量:");
                    try {
                        difLv4HP = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(205, 245, 40, 18), difLv4HP.ToString())), -1000, 1000);
                    }
                    catch (Exception e) {
                        difLv4HP = 0;
                    }
                    GUI.Label(new Rect(250, 245, 50, 18), "外功差量:");
                    try {
                        difLv4PhysicsAttack = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(305, 245, 40, 18), difLv4PhysicsAttack.ToString())), -1000, 1000);
                    }
                    catch (Exception e) {
                        difLv4PhysicsAttack = 0;
                    }
                    GUI.Label(new Rect(350, 245, 50, 18), "外防差量:");
                    try {
                        difLv4PhysicsDefense = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(405, 245, 40, 18), difLv4PhysicsDefense.ToString())), -5000, 5000);
                    }
                    catch (Exception e) {
                        difLv4PhysicsDefense = 0;
                    }

                    GUI.Label(new Rect(155, 265, 50, 18), "轻功差量:");
                    try {
                        difLv4Dodge = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(205, 265, 40, 18), difLv4Dodge.ToString())), -200, 200);
                    }
                    catch (Exception e) {
                        difLv4Dodge = 0;
                    }
                    GUI.Label(new Rect(250, 265, 50, 18), "内功差量:");
                    try {
                        difLv4MagicAttack = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(305, 265, 40, 18), difLv4MagicAttack.ToString())), -1000, 1000);
                    }
                    catch (Exception e) {
                        difLv4MagicAttack = 0;
                    }
                    GUI.Label(new Rect(350, 265, 50, 18), "内防差量:");
                    try {
                        difLv4MagicDefense = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(405, 265, 40, 18), difLv4MagicDefense.ToString())), -5000, 5000);
                    }
                    catch (Exception e) {
                        difLv4MagicDefense = 0;
                    }
                    if (GUI.Button(new Rect(0, 295, 80, 18), "修改基础属性"))
                    {
                        if (roleName == "")
                        {
                            this.ShowNotification(new GUIContent("招式名不能为空!"));
                            return;
                        }
                        data.Id                   = showId;
                        data.Name                 = roleName;
                        data.IconId               = icons[iconIndex].Id;
                        data.Occupation           = occupationTypeEnums[occupationTypeIndex];
                        data.Gender               = genderTypeEnums[genderTypeIndex];
                        data.HalfBodyId           = halfBodys[halfBodyIdIndex].Id;
                        data.Desc                 = roleDesc;
                        data.HP                   = hp;
                        data.MaxHP                = maxHp;
                        data.PhysicsAttack        = physicsAttack;
                        data.PhysicsDefense       = physicsDefense;
                        data.MagicAttack          = magicAttack;
                        data.MagicDefense         = magicDefense;
                        data.Dodge                = dodge;
                        data.AttackSpeed          = attackSpeed;
                        data.Lv                   = lv;
                        data.DifLv4HP             = difLv4HP;
                        data.DifLv4PhysicsAttack  = difLv4PhysicsAttack;
                        data.DifLv4PhysicsDefense = difLv4PhysicsDefense;
                        data.DifLv4MagicAttack    = difLv4MagicAttack;
                        data.DifLv4MagicDefense   = difLv4MagicDefense;
                        data.DifLv4Dodge          = difLv4Dodge;
                        data.HometownCityId       = allCityScenes[homedownCityIdIndex].Id;
                        data.ResourceBookDataIds.Clear();
                        foreach (int bookIdIndex in bookDataIdIndexes)
                        {
                            if (bookIdIndex > 0)
                            {
                                if (books[bookIdIndex].Occupation == OccupationType.None || books[bookIdIndex].Occupation == data.Occupation)
                                {
                                    if (books[bookIdIndex].LimitWeaponType == WeaponType.None || weapons[weaponDataIdIndex].Type == WeaponType.None || books[bookIdIndex].LimitWeaponType == weapons[weaponDataIdIndex].Type)
                                    {
                                        data.ResourceBookDataIds.Add(books[bookIdIndex].Id);
                                    }
                                    else
                                    {
                                        this.ShowNotification(new GUIContent(string.Format("装备{0}后不能再习练{1},兵器类型不符!", weapons[weaponDataIdIndex].Name, books[bookIdIndex].Name)));
                                        return;
                                    }
                                }
                                else
                                {
                                    this.ShowNotification(new GUIContent(string.Format("秘籍{0}无法装备到{1}身上,门派不符!", books[bookIdIndex].Name, data.Name)));
                                    return;
                                }
                            }
                        }
                        if (weapons[weaponDataIdIndex].Occupation == OccupationType.None || weapons[weaponDataIdIndex].Occupation == data.Occupation)
                        {
                            data.ResourceWeaponDataId = weapons[weaponDataIdIndex].Id;
                        }
                        else
                        {
                            this.ShowNotification(new GUIContent(string.Format("兵器{0}无法装备到{1}身上,门派不符!", weapons[weaponDataIdIndex].Name, data.Name)));
                            return;
                        }
                        data.DeadSoundId         = sounds[effectSoundIdIndex].Id;
                        data.IsImmuneMaxHPReduce = isImmuneMaxHPReduce;
                        data.IsStatic            = isStatic;
                        data.IsKnight            = isKnight;
                        data.IsBoss = isBoss;
                        data.InitAttribute();
                        writeDataToJson();
                        oldSelGridInt = -1;
                        getData();
                        fetchData(searchKeyword);
                        this.ShowNotification(new GUIContent("修改成功"));
                    }
                    GUILayout.EndArea();
                }
            }

            GUILayout.BeginArea(new Rect(listStartX + 205, listStartY + 320, 300, 60));
            switch (toolState)
            {
            case 0:
                if (GUI.Button(new Rect(0, 0, 80, 18), "添加"))
                {
                    toolState = 1;
                }
                if (GUI.Button(new Rect(85, 0, 80, 18), "删除"))
                {
                    toolState = 2;
                }
                break;

            case 1:
                GUI.Label(new Rect(0, 0, 30, 18), "Id:");
                addId = EditorGUI.TextField(new Rect(35, 0, 100, 18), addId);
                GUI.Label(new Rect(140, 0, 60, 18), "角色名:");
                addRoleName = EditorGUI.TextField(new Rect(205, 0, 100, 18), addRoleName);
                if (GUI.Button(new Rect(0, 20, 60, 18), "确定添加"))
                {
                    toolState = 0;
                    if (addId == "")
                    {
                        this.ShowNotification(new GUIContent("Id不能为空!"));
                        return;
                    }
                    if (addRoleName == "")
                    {
                        this.ShowNotification(new GUIContent("角色姓名不能为空!"));
                        return;
                    }
                    if (dataMapping.ContainsKey(addId))
                    {
                        this.ShowNotification(new GUIContent("Id重复!"));
                        return;
                    }
                    RoleData addRoleData = new RoleData();
                    addRoleData.Id   = addId;
                    addRoleData.Name = addRoleName;
                    ResourceSrcData findIcon = icons.Find(item => item.Name.IndexOf(addRoleData.Name) >= 0);
                    if (findIcon != null)
                    {
                        addRoleData.IconId = findIcon.Id;
                    }
                    ResourceSrcData findHalfBodyIcon = halfBodys.Find(item => item.Name.IndexOf(addRoleData.Name) >= 0);
                    if (findHalfBodyIcon != null)
                    {
                        addRoleData.HalfBodyId = findHalfBodyIcon.Id;
                    }
                    dataMapping.Add(addId, addRoleData);
                    writeDataToJson();
                    addedId = addId;
                    getData();
                    fetchData(searchKeyword);
//					addId = "";
                    addRoleName = "";
                    this.ShowNotification(new GUIContent("添加成功"));
                }
                if (GUI.Button(new Rect(65, 20, 60, 18), "取消"))
                {
                    toolState = 0;
                }
                break;

            case 2:
                if (GUI.Button(new Rect(0, 0, 60, 18), "确定删除"))
                {
                    toolState = 0;
                    if (!dataMapping.ContainsKey(data.Id))
                    {
                        this.ShowNotification(new GUIContent("待删除的数据不存在!"));
                        return;
                    }
                    dataMapping.Remove(data.Id);
                    writeDataToJson();
                    selGridInt    = 0;
                    oldSelGridInt = -1;
                    getData();
                    fetchData(searchKeyword);
                    this.ShowNotification(new GUIContent("删除成功"));
                }
                if (GUI.Button(new Rect(65, 0, 60, 18), "取消"))
                {
                    toolState = 0;
                }
                break;

            default:
                break;
            }
            GUILayout.EndArea();
        }
Example #10
0
        //绘制窗口时调用
        void OnGUI()
        {
            data = null;

            GUILayout.BeginArea(new Rect(5, 5, 200, 20));
            GUI.Label(new Rect(0, 0, 50, 18), "搜索名称:");
            searchKeyword = GUI.TextField(new Rect(55, 0, 100, 18), searchKeyword);
            if (GUI.Button(new Rect(160, 0, 30, 18), "搜索"))
            {
                selGridInt = 0;
                fetchData(searchKeyword);
            }
            GUILayout.EndArea();

            float listStartX   = 5;
            float listStartY   = 25;
            float scrollHeight = Screen.currentResolution.height - 110;

            if (listNames != null && listNames.Count > 0)
            {
                float contextHeight = listNames.Count * 21;
                //开始滚动视图
                scrollPosition = GUI.BeginScrollView(new Rect(listStartX, listStartY, 200, scrollHeight), scrollPosition, new Rect(5, 5, 190, contextHeight), false, scrollHeight < contextHeight);

                selGridInt = GUILayout.SelectionGrid(selGridInt, listNames.ToArray(), 1, GUILayout.Width(190));
                selGridInt = selGridInt >= listNames.Count ? listNames.Count - 1 : selGridInt;
                data       = showListData[selGridInt];
                if (selGridInt != oldSelGridInt)
                {
                    oldSelGridInt = selGridInt;
                    toolState     = 0;
                    showId        = data.Id;
                    weaponName    = data.Name;
                    if (iconIdIndexs.ContainsKey(data.IconId))
                    {
                        iconIndex = iconIdIndexs[data.IconId];
                    }
                    else
                    {
                        iconIndex = 0;
                    }
                    if (iconTextureMappings.ContainsKey(data.IconId))
                    {
                        iconTexture = iconTextureMappings[data.IconId];
                    }
                    else
                    {
                        iconTexture = null;
                    }
                    weaponTypeIndex     = weaponTypeIndexMapping.ContainsKey(data.Type) ? weaponTypeIndexMapping[data.Type] : 0;
                    qualityTypeIndex    = qualityTypeIndexMapping[data.Quality];
                    rates               = data.Rates;
                    weaponDesc          = data.Desc;
                    weaponWidth         = data.Width;
                    belongToCityIdIndex = Base.AllCitySceneIdIndexs.ContainsKey(data.BelongToCityId) ? Base.AllCitySceneIdIndexs[data.BelongToCityId] : 0;
                    physicsAttackPlus   = data.PhysicsAttackPlus;
                    fixedDamagePlus     = data.FixedDamagePlus;
                    damageRatePlus      = data.DamageRatePlus;
                    attackSpeedPlus     = data.AttackSpeedPlus;
                    occupationIndex     = Base.OccupationTypeIndexMapping.ContainsKey(data.Occupation) ? Base.OccupationTypeIndexMapping[data.Occupation] : 0;
                    justBelongToHost    = data.JustBelongToHost;
                    belongToRoleIdIndex = !string.IsNullOrEmpty(data.BelongToRoleId) && roleIdIndexesMapping.ContainsKey(data.BelongToRoleId) ? roleIdIndexesMapping[data.BelongToRoleId] : 0;
                    needsTypeIndexes    = new List <int>();
                    needsNums           = new List <float>();
                    foreach (ResourceData need in data.Needs)
                    {
                        needsTypeIndexes.Add(Base.ResourceTypeIndexMapping.ContainsKey(need.Type) ? Base.ResourceTypeIndexMapping[need.Type] : 0);
                        needsNums.Add((float)need.Num);
                    }
                }
                //结束滚动视图
                GUI.EndScrollView();

                if (GUI.Button(new Rect(listStartX + 205, 5, 100, 18), "生成兵器Excel"))
                {
                    Excel      outputXls   = new Excel();
                    ExcelTable outputTable = new ExcelTable();
                    outputTable.TableName = "兵器数值";
                    string outputPath = ExcelEditor.DocsPath + "/兵器数值.xlsx";
                    outputXls.Tables.Add(outputTable);
                    outputXls.Tables[0]           = new ExcelTable();
                    outputXls.Tables[0].TableName = "兵器数值";
                    outputXls.Tables[0].SetValue(1, 1, "1兵器id");
                    outputXls.Tables[0].SetValue(1, 2, "2兵器名称");
                    outputXls.Tables[0].SetValue(1, 3, "3暴击1.25倍");
                    outputXls.Tables[0].SetValue(1, 4, "4暴击1.5倍");
                    outputXls.Tables[0].SetValue(1, 5, "5暴击2倍");
                    outputXls.Tables[0].SetValue(1, 6, "6兵器长度");
                    outputXls.Tables[0].SetValue(1, 7, "7外功增量");
                    outputXls.Tables[0].SetValue(1, 8, "8固定伤害增量");
                    outputXls.Tables[0].SetValue(1, 9, "9伤害比例增量");
                    outputXls.Tables[0].SetValue(1, 10, "10攻速增量");
                    outputXls.Tables[0].SetValue(1, 11, "11材料一");
                    outputXls.Tables[0].SetValue(1, 12, "12材料一数量");
                    outputXls.Tables[0].SetValue(1, 13, "13材料二");
                    outputXls.Tables[0].SetValue(1, 14, "14材料二数量");
                    outputXls.Tables[0].SetValue(1, 15, "15材料三");
                    outputXls.Tables[0].SetValue(1, 16, "16材料三数量");
                    outputXls.Tables[0].SetValue(1, 17, "17材料四");
                    outputXls.Tables[0].SetValue(1, 18, "18材料四数量");
                    outputXls.Tables[0].SetValue(1, 19, "19材料五");
                    outputXls.Tables[0].SetValue(1, 20, "20材料五数量");
                    outputXls.Tables[0].SetValue(1, 21, "21所属城镇Id");
                    outputXls.Tables[0].SetValue(1, 22, "22所属角色Id");
                    outputXls.Tables[0].SetValue(1, 23, "23单一家丁生产耗时");
                    outputXls.Tables[0].SetValue(1, 24, "24单一家丁生产耗时");

                    int startIndex = 2;
                    int costSeconds;
                    foreach (WeaponData weapon in dataMapping.Values)
                    {
                        outputXls.Tables[0].SetValue(startIndex, 1, weapon.Id);
                        outputXls.Tables[0].SetValue(startIndex, 2, weapon.Name);
                        outputXls.Tables[0].SetValue(startIndex, 3, weapon.Rates[1].ToString());
                        outputXls.Tables[0].SetValue(startIndex, 4, weapon.Rates[2].ToString());
                        outputXls.Tables[0].SetValue(startIndex, 5, weapon.Rates[3].ToString());
                        outputXls.Tables[0].SetValue(startIndex, 6, weapon.Width.ToString());
                        outputXls.Tables[0].SetValue(startIndex, 7, weapon.PhysicsAttackPlus.ToString());
                        outputXls.Tables[0].SetValue(startIndex, 8, weapon.FixedDamagePlus.ToString());
                        outputXls.Tables[0].SetValue(startIndex, 9, weapon.DamageRatePlus.ToString());
                        outputXls.Tables[0].SetValue(startIndex, 10, weapon.AttackSpeedPlus.ToString());
                        outputXls.Tables[0].SetValue(startIndex, 11, weapon.Needs.Count > 0 ? weapon.Needs[0].Type.ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 12, weapon.Needs.Count > 0 ? ((int)weapon.Needs[0].Num).ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 13, weapon.Needs.Count > 1 ? weapon.Needs[1].Type.ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 14, weapon.Needs.Count > 1 ? ((int)weapon.Needs[1].Num).ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 15, weapon.Needs.Count > 2 ? weapon.Needs[2].Type.ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 16, weapon.Needs.Count > 2 ? ((int)weapon.Needs[2].Num).ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 17, weapon.Needs.Count > 3 ? weapon.Needs[3].Type.ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 18, weapon.Needs.Count > 3 ? ((int)weapon.Needs[3].Num).ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 19, weapon.Needs.Count > 4 ? weapon.Needs[4].Type.ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 20, weapon.Needs.Count > 4 ? ((int)weapon.Needs[4].Num).ToString() : "无");
                        outputXls.Tables[0].SetValue(startIndex, 21, weapon.BelongToCityId);
                        outputXls.Tables[0].SetValue(startIndex, 22, weapon.BelongToRoleId);
                        costSeconds = 0;
                        for (int i = 0, len = weapon.Needs.Count; i < len; i++)
                        {
                            costSeconds += (int)((double)getBeedSecond(weapon.Needs[i].Type) * weapon.Needs[i].Num);
                        }
                        outputXls.Tables[0].SetValue(startIndex, 23, Statics.GetFullTime(costSeconds));
                        outputXls.Tables[0].SetValue(startIndex, 24, costSeconds.ToString());
                        startIndex++;
                    }

                    ExcelHelper.SaveExcel(outputXls, outputPath); //生成excel
                    this.ShowNotification(new GUIContent("兵器数值Excel已生成\n目录为:" + outputPath));
                }

                if (GUI.Button(new Rect(listStartX + 310, 5, 100, 18), "加载兵器Excel"))
                {
                    Excel      loadExcel = ExcelHelper.LoadExcel(ExcelEditor.DocsPath + "/兵器数值.xlsx");
                    ExcelTable table     = loadExcel.Tables[0];
                    WeaponData weapon;
                    for (int i = 2, len = table.NumberOfRows; i <= len; i++)
                    {
                        if (dataMapping.ContainsKey(table.GetValue(i, 1).ToString()))
                        {
                            weapon = dataMapping[table.GetValue(i, 1).ToString()];
                        }
                        else
                        {
                            weapon    = new WeaponData();
                            weapon.Id = table.GetValue(i, 1).ToString();
                            dataMapping.Add(weapon.Id, weapon);
                        }
                        weapon.Name              = table.GetValue(i, 2).ToString();
                        weapon.Rates[1]          = float.Parse(table.GetValue(i, 3).ToString());
                        weapon.Rates[2]          = float.Parse(table.GetValue(i, 4).ToString());
                        weapon.Rates[3]          = float.Parse(table.GetValue(i, 5).ToString());
                        weapon.Width             = float.Parse(table.GetValue(i, 6).ToString());
                        weapon.PhysicsAttackPlus = float.Parse(table.GetValue(i, 7).ToString());
                        weapon.FixedDamagePlus   = int.Parse(table.GetValue(i, 8).ToString());
                        weapon.DamageRatePlus    = float.Parse(table.GetValue(i, 9).ToString());
                        weapon.AttackSpeedPlus   = float.Parse(table.GetValue(i, 10).ToString());
                        weapon.Needs.Clear();
                        if (table.GetValue(i, 11).ToString() != "无")
                        {
                            weapon.Needs.Add(new ResourceData((ResourceType)Enum.Parse(typeof(ResourceType), table.GetValue(i, 11).ToString()), (double)(int.Parse(table.GetValue(i, 12).ToString()))));
                        }
                        if (table.GetValue(i, 13).ToString() != "无")
                        {
                            weapon.Needs.Add(new ResourceData((ResourceType)Enum.Parse(typeof(ResourceType), table.GetValue(i, 13).ToString()), (double)(int.Parse(table.GetValue(i, 14).ToString()))));
                        }
                        if (table.GetValue(i, 15).ToString() != "无")
                        {
                            weapon.Needs.Add(new ResourceData((ResourceType)Enum.Parse(typeof(ResourceType), table.GetValue(i, 15).ToString()), (double)(int.Parse(table.GetValue(i, 16).ToString()))));
                        }
                        if (table.GetValue(i, 17).ToString() != "无")
                        {
                            weapon.Needs.Add(new ResourceData((ResourceType)Enum.Parse(typeof(ResourceType), table.GetValue(i, 17).ToString()), (double)(int.Parse(table.GetValue(i, 18).ToString()))));
                        }
                        if (table.GetValue(i, 19).ToString() != "无")
                        {
                            weapon.Needs.Add(new ResourceData((ResourceType)Enum.Parse(typeof(ResourceType), table.GetValue(i, 19).ToString()), (double)(int.Parse(table.GetValue(i, 20).ToString()))));
                        }
                        weapon.BelongToCityId = table.GetValue(i, 21).ToString();
                    }
                    oldSelGridInt = -1;
                    fetchData(searchKeyword);
                    this.ShowNotification(new GUIContent("兵器数值Excel的数据已经导入"));
                }

                if (data != null)
                {
                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY, 600, 500));
                    if (iconTexture != null)
                    {
                        GUI.DrawTexture(new Rect(0, 0, 120, 120), iconTexture);
                    }
                    GUI.Label(new Rect(125, 0, 30, 18), "Id:");
                    EditorGUI.TextField(new Rect(155, 0, 50, 18), showId);
                    GUI.Label(new Rect(210, 0, 40, 18), "兵器名:");
                    weaponName = EditorGUI.TextField(new Rect(250, 0, 60, 18), weaponName);
                    GUI.Label(new Rect(125, 20, 60, 18), "类型:");
                    weaponTypeIndex = EditorGUI.Popup(new Rect(190, 20, 100, 18), weaponTypeIndex, weaponTypeStrs.ToArray());
                    GUI.Label(new Rect(315, 0, 40, 18), "开启:");
                    belongToCityIdIndex = EditorGUI.Popup(new Rect(340, 0, 100, 18), belongToCityIdIndex, Base.AllCitySceneNames.ToArray());
                    GUI.Label(new Rect(295, 20, 60, 18), "门派:");
                    occupationIndex = EditorGUI.Popup(new Rect(340, 20, 100, 18), occupationIndex, Base.OccupationTypeStrs.ToArray());
                    GUI.Label(new Rect(295, 40, 60, 18), "主角专属:");
                    justBelongToHost = EditorGUI.Toggle(new Rect(350, 40, 20, 18), justBelongToHost);
                    if (!justBelongToHost)
                    {
                        GUI.Label(new Rect(295, 60, 60, 18), "主人:");
                        belongToRoleIdIndex = EditorGUI.Popup(new Rect(340, 60, 100, 18), belongToRoleIdIndex, roleNames.ToArray());
                    }
                    else
                    {
                        belongToRoleIdIndex = 0;
                    }
                    if (belongToRoleIdIndex > 0)
                    {
                        //有唯一主人的兵器不能作为主角门派动态出现,应该是及时出现在工坊
                        justBelongToHost = false;
                    }
                    GUI.Label(new Rect(125, 40, 60, 18), "Icon:");
                    iconIndex = EditorGUI.Popup(new Rect(190, 40, 100, 18), iconIndex, iconNames.ToArray());
                    GUI.Label(new Rect(125, 60, 60, 18), "品质:");
                    qualityTypeIndex = EditorGUI.Popup(new Rect(190, 60, 100, 18), qualityTypeIndex, qualityTypeStrs.ToArray());
                    GUI.Label(new Rect(125, 80, 100, 18), "25%追加伤害:");
                    rates[1] = EditorGUI.Slider(new Rect(230, 80, 180, 18), rates[1], 0, 1);
                    GUI.Label(new Rect(125, 100, 100, 18), "50%追加伤害:");
                    rates[2] = EditorGUI.Slider(new Rect(230, 100, 180, 18), rates[2], 0, 1);
                    GUI.Label(new Rect(125, 120, 100, 18), "100%追加伤害:");
                    rates[3] = EditorGUI.Slider(new Rect(230, 120, 180, 18), rates[3], 0, 1);
                    GUI.Label(new Rect(125, 140, 100, 18), "兵器长度:");
                    weaponWidth = EditorGUI.Slider(new Rect(230, 140, 180, 18), weaponWidth, 50, 300);
                    GUI.Label(new Rect(0, 160, 100, 18), "外功增量:");
                    physicsAttackPlus = EditorGUI.Slider(new Rect(0, 180, 180, 18), physicsAttackPlus, 0, 100000);
                    GUI.Label(new Rect(200, 160, 100, 18), "固定伤害增量:");
                    fixedDamagePlus = (int)EditorGUI.Slider(new Rect(200, 180, 180, 18), fixedDamagePlus, 0, 100000);
                    GUI.Label(new Rect(0, 200, 100, 18), "伤害比例增量:");
                    damageRatePlus = EditorGUI.Slider(new Rect(0, 220, 180, 18), damageRatePlus, 0, 20);
                    GUI.Label(new Rect(200, 200, 100, 18), "攻速增量:");
                    attackSpeedPlus = EditorGUI.Slider(new Rect(200, 220, 180, 18), attackSpeedPlus, -25, 25);
                    for (int i = 0; i < needsTypeIndexes.Count; i++)
                    {
                        if (needsTypeIndexes.Count > i)
                        {
                            needsTypeIndexes[i] = EditorGUI.Popup(new Rect(0, 240 + i * 20, 100, 18), needsTypeIndexes[i], Base.ResourceTypeStrs.ToArray());
                            needsNums[i]        = EditorGUI.Slider(new Rect(105, 240 + i * 20, 180, 18), needsNums[i], 1, 1000);
                            if (GUI.Button(new Rect(290, 240 + i * 20, 36, 18), "X"))
                            {
                                needsTypeIndexes.RemoveAt(i);
                                needsNums.RemoveAt(i);
                            }
                        }
                    }
                    if (GUI.Button(new Rect(330, 240, 90, 18), "添加原材料"))
                    {
                        if (needsTypeIndexes.Count < 5)
                        {
                            needsTypeIndexes.Add(Base.ResourceTypeIndexMapping[ResourceType.Silver]);
                            needsNums.Add(1);
                        }
                        else
                        {
                            this.ShowNotification(new GUIContent("原材料不能大于5个"));
                        }
                    }
                    GUI.Label(new Rect(0, 360, 60, 18), "描述:");
                    weaponDesc = GUI.TextArea(new Rect(45, 360, 370, 100), weaponDesc);

                    if (oldIconIndex != iconIndex)
                    {
                        oldIconIndex = iconIndex;
                        iconTexture  = iconTextureMappings[icons[iconIndex].Id];
                    }
                    if (GUI.Button(new Rect(332, 470, 80, 18), "修改兵器属性"))
                    {
                        if (weaponName == "")
                        {
                            this.ShowNotification(new GUIContent("兵器名不能为空!"));
                            return;
                        }
                        data.Name              = weaponName;
                        data.IconId            = icons[iconIndex].Id;
                        data.Type              = weaponTypeEnums[weaponTypeIndex];
                        data.Quality           = qualityTypeEnums[qualityTypeIndex];
                        data.Rates[1]          = rates[1];
                        data.Rates[2]          = rates[2];
                        data.Rates[3]          = rates[3];
                        data.Desc              = weaponDesc;
                        data.Width             = weaponWidth;
                        data.BeUsingByRoleId   = "";
                        data.BelongToCityId    = Base.AllCityScenes[belongToCityIdIndex].Id;
                        data.PhysicsAttackPlus = physicsAttackPlus;
                        data.FixedDamagePlus   = fixedDamagePlus;
                        data.DamageRatePlus    = damageRatePlus;
                        data.AttackSpeedPlus   = attackSpeedPlus;
                        data.Occupation        = Base.OccupationTypeEnums[occupationIndex];
                        data.JustBelongToHost  = justBelongToHost;
                        data.BelongToRoleId    = belongToRoleIdIndex > 0 ? roles[belongToRoleIdIndex].Id : "";
                        data.Needs             = new List <ResourceData>();
                        for (int i = 0; i < needsTypeIndexes.Count; i++)
                        {
                            if (needsTypeIndexes.Count > i)
                            {
                                data.Needs.Add(new ResourceData(Base.ResourceTypeEnums[needsTypeIndexes[i]], (double)needsNums[i]));
                            }
                        }
                        writeDataToJson();
                        oldSelGridInt = -1;
                        getData();
                        fetchData(searchKeyword);
                        this.ShowNotification(new GUIContent("修改成功"));
                    }
                    GUILayout.EndArea();
                }
            }

            GUILayout.BeginArea(new Rect(listStartX + 205, listStartY + 500, 500, 60));
            switch (toolState)
            {
            case 0:
                if (GUI.Button(new Rect(0, 0, 80, 18), "添加兵器"))
                {
                    toolState = 1;
                }
                if (GUI.Button(new Rect(85, 0, 80, 18), "删除兵器"))
                {
                    toolState = 2;
                }
                break;

            case 1:
                GUI.Label(new Rect(0, 0, 30, 18), "Id:");
                addId = GUI.TextField(new Rect(35, 0, 80, 18), addId);
                GUI.Label(new Rect(120, 0, 50, 18), "兵器名:");
                addWeaponName = GUI.TextField(new Rect(175, 0, 80, 18), addWeaponName);
                if (GUI.Button(new Rect(260, 0, 80, 18), "添加"))
                {
                    if (addId == "")
                    {
                        this.ShowNotification(new GUIContent("Id不能为空!"));
                        return;
                    }
                    if (addWeaponName == "")
                    {
                        this.ShowNotification(new GUIContent("兵器名不能为空!"));
                        return;
                    }
                    if (dataMapping.ContainsKey(addId))
                    {
                        this.ShowNotification(new GUIContent("Id重复!"));
                        return;
                    }
                    WeaponData weapon = new WeaponData();
                    weapon.Id   = addId;
                    weapon.Name = addWeaponName;
                    ResourceSrcData findIcon = icons.Find(item => item.Name.IndexOf(weapon.Name) >= 0);
                    if (findIcon != null)
                    {
                        weapon.IconId = findIcon.Id;
                    }
                    dataMapping.Add(weapon.Id, weapon);
                    writeDataToJson();
                    addedId = addId;
                    getData();
                    fetchData(searchKeyword);
//					addId = "";
                    addWeaponName = "";
                    this.ShowNotification(new GUIContent("添加成功"));
                }
                if (GUI.Button(new Rect(345, 0, 80, 18), "取消"))
                {
                    toolState = 0;
                }
                break;

            case 2:
                if (GUI.Button(new Rect(0, 0, 80, 18), "确定删除"))
                {
                    toolState = 0;
                    if (data != null && dataMapping.ContainsKey(data.Id))
                    {
                        dataMapping.Remove(data.Id);
                        writeDataToJson();
                        getData();
                        fetchData(searchKeyword);
                        this.ShowNotification(new GUIContent("删除成功"));
                    }
                }
                if (GUI.Button(new Rect(85, 0, 80, 18), "取消"))
                {
                    toolState = 0;
                }
                break;
            }
            GUILayout.EndArea();
        }