Пример #1
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;
                oldSelGridInt = -1;
                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;
                    willDelete    = false;
                    src           = data.Src;
                    srcName       = data.Name;
                    GameObject showImgObj = Statics.GetPrefabClone(src);
                    iconTexture = showImgObj.GetComponent <Image>().sprite.texture;
                    DestroyImmediate(showImgObj);
                }
                //结束滚动视图
                GUI.EndScrollView();

                if (data != null)
                {
                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY, 300, 120));
                    if (iconTexture != null)
                    {
                        GUI.DrawTexture(new Rect(0, 0, 60, 60), iconTexture);
                    }
                    showId = data.Id;
                    GUI.Label(new Rect(65, 0, 60, 18), "Id:");
                    showId = EditorGUI.TextField(new Rect(130, 0, 100, 18), showId);
                    GUI.Label(new Rect(65, 20, 60, 18), "名称:");
                    srcName = EditorGUI.TextField(new Rect(130, 20, 100, 18), srcName);
                    GUI.Label(new Rect(65, 40, 60, 18), "资源路径:");
                    EditorGUI.TextField(new Rect(130, 40, 200, 18), src);

                    if (!willDelete)
                    {
                        if (GUI.Button(new Rect(0, 70, 80, 36), "修改"))
                        {
                            if (srcName == "")
                            {
                                this.ShowNotification(new GUIContent("名称不能为空!"));
                                return;
                            }
                            if (src == "")
                            {
                                this.ShowNotification(new GUIContent("路径不能为空!"));
                                return;
                            }
                            data.Name = srcName;
                            //data.Src = src;
                            writeDataToJson();
                            oldSelGridInt = -1;
                            getData();
                            fetchData(searchKeyword);
                            this.ShowNotification(new GUIContent("修改成功"));
                        }
                        if (GUI.Button(new Rect(85, 70, 80, 36), "删除"))
                        {
                            willDelete = true;
                        }
                    }
                    else
                    {
                        if (GUI.Button(new Rect(0, 70, 80, 36), "确定删除"))
                        {
                            if (!srcDataMapping.ContainsKey(data.Id))
                            {
                                this.ShowNotification(new GUIContent("要删除的数据不存在!"));
                                return;
                            }
                            srcDataMapping.Remove(data.Id);
                            writeDataToJson();
                            selGridInt    = 0;
                            oldSelGridInt = -1;
                            getData();
                            fetchData(searchKeyword);
                            FileUtil.DeleteFileOrDirectory("Assets/Resources/" + data.Src + ".prefab");
                            AssetDatabase.Refresh();
                            this.ShowNotification(new GUIContent("删除成功"));
                            willDelete = false;
                        }
                        if (GUI.Button(new Rect(85, 70, 80, 36), "取消"))
                        {
                            willDelete = false;
                        }
                    }
                    GUILayout.EndArea();
                }
            }
            GUILayout.BeginArea(new Rect(listStartX + 205, listStartY + 125, 300, 160));
            GUI.Label(new Rect(0, 0, 300, 18), "|----添加新数据----------------------------------------------|");
            GUI.Label(new Rect(0, 20, 60, 18), "Id:");
            addId = EditorGUI.TextField(new Rect(65, 20, 200, 18), addId);
            GUI.Label(new Rect(0, 40, 60, 18), "名称:");
            addSrcName = EditorGUI.TextField(new Rect(65, 40, 200, 18), addSrcName);
            addSprite  = EditorGUI.ObjectField(new Rect(0, 60, 268, 18), "添加头像Sprite", addSprite, typeof(Sprite), true) as Sprite;
            if (GUI.Button(new Rect(0, 85, 80, 36), "添加"))
            {
                if (addSrcName == "")
                {
                    this.ShowNotification(new GUIContent("名称不能为空!"));
                    return;
                }
                if (addId == "")
                {
                    this.ShowNotification(new GUIContent("Id不能为空!"));
                    return;
                }
                if (addSprite == null)
                {
                    this.ShowNotification(new GUIContent("请选择图形!"));
                    return;
                }
                if (srcDataMapping.ContainsKey(addId))
                {
                    this.ShowNotification(new GUIContent("Id已存在!"));
                    return;
                }
                GameObject newObj = new GameObject();
                newObj.name = addId;
                Image img = newObj.AddComponent <Image>();
                img.sprite = addSprite;
                img.SetNativeSize();
                PrefabUtility.CreatePrefab("Assets/Resources/Prefabs/UI/Icons/" + addId + ".prefab", newObj);
                DestroyImmediate(newObj);
                AssetDatabase.Refresh();
                ResourceSrcData srcData = new ResourceSrcData();
                srcData.Id   = addId;
                srcData.Name = addSrcName;
                srcData.Src  = "Prefabs/UI/Icons/" + addId;
                srcDataMapping.Add(addId, srcData);
                writeDataToJson();
                addedId = addId;
                getData();
                fetchData(searchKeyword);
//				addId = "";
//				addSrcName = "";
                addSprite = null;
                this.ShowNotification(new GUIContent("添加成功"));
            }
            GUILayout.EndArea();
        }
Пример #2
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;
                    name             = data.Name;
                    defaultDialogMsg = data.DefaultDialogMsg;
                    iconIdIndex      = Base.IconIdIndexs.ContainsKey(data.IconId) ? Base.IconIdIndexs[data.IconId] : 0;
                    iconTexture      = Base.IconTextureMappings.ContainsKey(data.IconId) ? Base.IconTextureMappings[data.IconId] : null;
                    isActive         = data.IsActive;
                    npcTypeIndex     = Base.NpcTypeIndexMapping.ContainsKey(data.Type) ? Base.NpcTypeIndexMapping[data.Type] : 0;
                    fightIdIndex     = allFightIdIndexs.ContainsKey(data.CurrentFightId) ? allFightIdIndexs[data.CurrentFightId] : 0;
                    taskIdIndex      = allTaskIdIndexs.ContainsKey(data.ShowAfterTaskId) ? allTaskIdIndexs[data.ShowAfterTaskId] : 0;
                }
                //结束滚动视图
                GUI.EndScrollView();
                if (data != null)
                {
                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY, 600, 300));
                    GUI.Label(new Rect(0, 0, 60, 18), "Id:");
                    EditorGUI.TextField(new Rect(65, 0, 150, 18), showId);
                    GUI.Label(new Rect(0, 20, 60, 18), "Npc名称:");
                    name = EditorGUI.TextField(new Rect(65, 20, 150, 18), name);
                    GUI.Label(new Rect(220, 0, 50, 18), "一句话:");
                    defaultDialogMsg = EditorGUI.TextArea(new Rect(265, 0, 180, 36), defaultDialogMsg);
                    if (iconTexture != null)
                    {
                        GUI.DrawTexture(new Rect(0, 40, 50, 50), iconTexture);
                    }
                    iconIdIndex = EditorGUI.Popup(new Rect(65, 40, 150, 18), iconIdIndex, Base.IconNames.ToArray());
                    if (oldIconIndex != iconIdIndex)
                    {
                        oldIconIndex = iconIdIndex;
                        iconTexture  = Base.IconTextureMappings[Base.Icons[iconIdIndex].Id];
                    }
                    GUI.Label(new Rect(65, 60, 60, 18), "Npc类型:");
                    npcTypeIndex = EditorGUI.Popup(new Rect(130, 60, 80, 18), npcTypeIndex, Base.NpcTypeStrs.ToArray());
                    if (Base.NpcTypeEnums[npcTypeIndex] == NpcType.Fight)
                    {
                        fightIdIndex = EditorGUI.Popup(new Rect(215, 60, 150, 18), fightIdIndex, allFightNames.ToArray());
                    }
                    else if (Base.NpcTypeEnums[npcTypeIndex] == NpcType.AfterTask)
                    {
                        taskIdIndex = EditorGUI.Popup(new Rect(215, 60, 150, 18), taskIdIndex, allTaskNames.ToArray());
                    }
                    GUI.Label(new Rect(220, 40, 50, 18), "动态Npc:");
                    isActive = EditorGUI.Toggle(new Rect(275, 40, 18, 18), isActive);
                    if (GUI.Button(new Rect(0, 120, 100, 18), "修改"))
                    {
                        if (name == "")
                        {
                            this.ShowNotification(new GUIContent("Npc名不能为空!"));
                            return;
                        }
                        data.Name             = name;
                        data.DefaultDialogMsg = defaultDialogMsg;
                        data.IconId           = Base.Icons[iconIdIndex].Id;
                        data.IsActive         = isActive;
                        data.Type             = Base.NpcTypeEnums[npcTypeIndex];
                        data.CurrentFightId   = allFights.Count > fightIdIndex ? allFights[fightIdIndex].Id : "";
                        data.ShowAfterTaskId  = allTasks[taskIdIndex].Id;
                        writeDataToJson();
                        oldSelGridInt = -1;
                        getData();
                        fetchData(searchKeyword);
                        this.ShowNotification(new GUIContent("修改成功"));
                    }
                    GUILayout.EndArea();
                }
            }

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

            case 1:
                GUI.Label(new Rect(0, 20, 30, 18), "Id:");
                addId = GUI.TextField(new Rect(35, 20, 80, 18), addId);
                GUI.Label(new Rect(120, 20, 50, 18), "Npc名:");
                addName = GUI.TextField(new Rect(175, 20, 80, 18), addName);
                if (GUI.Button(new Rect(260, 20, 80, 18), "添加"))
                {
                    if (addId == "")
                    {
                        this.ShowNotification(new GUIContent("Id不能为空!"));
                        return;
                    }
                    if (addName == "")
                    {
                        this.ShowNotification(new GUIContent("Npc名不能为空!"));
                        return;
                    }
                    if (dataMapping.ContainsKey(addId))
                    {
                        this.ShowNotification(new GUIContent("Id重复!"));
                        return;
                    }

                    NpcData npcData = new NpcData();
                    npcData.Id   = addId;
                    npcData.Name = addName;
                    ResourceSrcData findIcon = Base.Icons.Find(item => item.Name.IndexOf(npcData.Name) >= 0);
                    if (findIcon != null)
                    {
                        npcData.IconId = findIcon.Id;
                    }
                    dataMapping.Add(npcData.Id, npcData);
                    writeDataToJson();
                    addedId = addId;
                    getData();
                    fetchData(searchKeyword);
//					addId = "";
                    addName       = "";
                    oldSelGridInt = -1;
                    this.ShowNotification(new GUIContent("添加成功"));
                }
                if (GUI.Button(new Rect(345, 20, 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);
                        oldSelGridInt = -1;
                        this.ShowNotification(new GUIContent("删除成功"));
                    }
                }
                if (GUI.Button(new Rect(85, 0, 80, 18), "取消"))
                {
                    toolState = 0;
                }
                break;
            }
            GUILayout.EndArea();
        }
Пример #3
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("对应简表创建完毕");
            }
            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;
                    isStatic            = data.IsStatic;
                    isKnight            = data.IsKnight;
                    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);
                    }
                    showId = data.Id;
                    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, 100000);
                    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, 100000);
                    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, 100);
                    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(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(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())), -10, 10);
                    }
                    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())), -10, 10);
                    }
                    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())), -10, 10);
                    }
                    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())), -10, 10);
                    }
                    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())), -10, 10);
                    }
                    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())), -10, 10);
                    }
                    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.IsStatic    = isStatic;
                        data.IsKnight    = isKnight;
                        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();
        }
Пример #4
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();

            if (GUI.Button(new Rect(210, 5, 100, 18), "技能描述批量生成"))
            {
                SkillData d;
                for (int i = 0, len = allSkillDatas.Count; i < len; i++)
                {
                    d = allSkillDatas[i];
                    if (d != null)
                    {
                        d.Desc = createSkillDesc(d);
                    }
                }
                writeDataToJson();
                this.ShowNotification(new GUIContent(string.Format("共有{0}个招数描述被创建", allSkillDatas.Count)));
            }

            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;
                    skillName          = data.Name;
                    effectSrc          = data.EffectSrc;
                    effectSoundIdIndex = soundIdIndexs.ContainsKey(data.EffectSoundId) ? soundIdIndexs[data.EffectSoundId] : 0;

                    if (iconIdIndexs.ContainsKey(data.IconId))
                    {
                        iconIndex = iconIdIndexs[data.IconId];
                    }
                    else
                    {
                        iconIndex = 0;
                    }
                    if (iconTextureMappings.ContainsKey(data.IconId))
                    {
                        iconTexture = iconTextureMappings[data.IconId];
                    }
                    else
                    {
                        iconTexture = null;
                    }
                    skillTypeIndex = skillTypeIndexMapping[data.Type];
                    rate           = data.Rate;
                    cdTime         = data.CDTime;

                    theBuffTypeIndexs   = new List <int>();
                    theBuffRates        = new List <float>();
                    theBuffRoundNumbers = new List <int>();
                    theBuffValues       = new List <float>();
                    theBuffFirstEffects = new List <bool>();
                    foreach (BuffData buff in data.BuffDatas)
                    {
                        theBuffTypeIndexs.Add(buffTypeIndexMapping[buff.Type]);
                        theBuffRates.Add(buff.Rate);
                        theBuffRoundNumbers.Add(buff.RoundNumber);
                        theBuffValues.Add(buff.Value);
                        theBuffFirstEffects.Add(buff.FirstEffect);
                    }

                    theDeBuffTypeIndexs   = new List <int>();
                    theDeBuffRates        = new List <float>();
                    theDeBuffRoundNumbers = new List <int>();
                    theDeBuffValues       = new List <float>();
                    theDeBuffFirstEffects = new List <bool>();
                    foreach (BuffData deBuff in data.DeBuffDatas)
                    {
                        theDeBuffTypeIndexs.Add(buffTypeIndexMapping[deBuff.Type]);
                        theDeBuffRates.Add(deBuff.Rate);
                        theDeBuffRoundNumbers.Add(deBuff.RoundNumber);
                        theDeBuffValues.Add(deBuff.Value);
                        theDeBuffFirstEffects.Add(deBuff.FirstEffect);
                    }
                }
                //结束滚动视图
                GUI.EndScrollView();

                if (data != null)
                {
                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY, 800, 250));
                    if (iconTexture != null)
                    {
                        GUI.DrawTexture(new Rect(0, 0, 50, 50), iconTexture);
                    }
                    showId = data.Id;
                    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), "名称:");
                    skillName = EditorGUI.TextField(new Rect(250, 0, 100, 18), skillName);
                    GUI.Label(new Rect(355, 0, 50, 18), "特效路径:");
                    Rect prefabRect = new Rect(410, 0, 200, 18);
                    effectSrc = EditorGUI.TextField(prefabRect, effectSrc);
                    // 判断当前鼠标正拖拽某对象或者在拖拽的过程中松开了鼠标按键
                    // 同时还需要判断拖拽时鼠标所在位置处于文本输入框内
                    if ((Event.current.type == EventType.DragUpdated ||
                         Event.current.type == EventType.DragExited))
                    {
                        // 判断是否拖拽了文件
                        if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                        {
                            string sfxPath = DragAndDrop.paths [0];
                            // 拖拽的过程中,松开鼠标之后,拖拽操作结束,此时就可以使用获得的 sfxPath 变量了
                            if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragExited)
                            {
                                DragAndDrop.AcceptDrag();
                                if (sfxPath.IndexOf(".prefab") >= 0)
                                {
                                    if (prefabRect.Contains(Event.current.mousePosition))
                                    {
                                        if (sfxPath.IndexOf("Assets/Resources/") == 0)
                                        {
                                            sfxPath   = sfxPath.Replace("Assets/Resources/", "");
                                            sfxPath   = sfxPath.Replace(".prefab", "");
                                            effectSrc = sfxPath;
                                        }
                                        else
                                        {
                                            this.ShowNotification(new GUIContent("只能使用放在Resources目录下的角色模型预设!"));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    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), "类型:");
                    skillTypeIndex = EditorGUI.Popup(new Rect(250, 20, 100, 18), skillTypeIndex, skillTypeStrs.ToArray());
                    GUI.Label(new Rect(355, 20, 50, 18), "音效:");
                    effectSoundIdIndex = EditorGUI.Popup(new Rect(410, 20, 100, 18), effectSoundIdIndex, soundNames.ToArray());
                    GUI.Label(new Rect(55, 40, 40, 18), "概率:");
                    rate = EditorGUI.Slider(new Rect(100, 40, 180, 18), rate, 0, 100);
                    GUI.Label(new Rect(285, 40, 40, 18), "CD时间:");
                    cdTime = EditorGUI.Slider(new Rect(330, 40, 180, 18), cdTime, 1, 1000);
                    if (oldIconIndex != iconIndex)
                    {
                        oldIconIndex = iconIndex;
                        iconTexture  = iconTextureMappings[icons[iconIndex].Id];
                    }
                    if (GUI.Button(new Rect(0, 65, 80, 18), "修改基础属性"))
                    {
                        if (skillName == "")
                        {
                            this.ShowNotification(new GUIContent("招式名不能为空!"));
                            return;
                        }
                        data.Name   = skillName;
                        data.IconId = icons[iconIndex].Id;
                        data.Type   = skillTypeEnums[skillTypeIndex];
                        data.Rate   = rate;
                        data.CDTime = cdTime;
                        data.Desc   = createSkillDesc(data);
                        Debug.Log(data.Desc);
                        data.EffectSrc     = effectSrc;
                        data.EffectSoundId = sounds[effectSoundIdIndex].Id;
                        writeDataToJson();
                        oldSelGridInt = -1;
                        getData();
                        fetchData(searchKeyword);
                        this.ShowNotification(new GUIContent("修改成功"));
                    }
                    buffGridIndex = GUI.SelectionGrid(new Rect(0, 90, 80, 50), buffGridIndex, new string[2] {
                        "Buff", "DeBuff"
                    }, 1);
                    GUI.Label(new Rect(85, 90, 40, 18), "类型:");
                    addBuffOrDeBuffTypeIndex = EditorGUI.Popup(new Rect(130, 90, 100, 18), addBuffOrDeBuffTypeIndex, buffTypeStrs.ToArray());
                    GUI.Label(new Rect(235, 90, 40, 18), "概率:");
                    addBuffOrDeBuffRate = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(280, 90, 40, 18), addBuffOrDeBuffRate.ToString())), 0, 100);
                    GUI.Label(new Rect(325, 90, 40, 18), "持续:");
                    addBuffOrDeBuffRoundNumber = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(370, 90, 40, 18), addBuffOrDeBuffRoundNumber.ToString())), 0, 100);
                    GUI.Label(new Rect(415, 90, 40, 18), "数值:");
//					if (buffGridIndex == 0) {
//						addBuffOrDeBuffValue = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(460, 90, 80, 18), addBuffOrDeBuffValue.ToString())), 0, getBuffValueRangeTop(buffTypeEnums[addBuffOrDeBuffTypeIndex]));
//					}
//					else {
//						addBuffOrDeBuffValue = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(460, 90, 80, 18), addBuffOrDeBuffValue.ToString())), -getBuffValueRangeTop(buffTypeEnums[addBuffOrDeBuffTypeIndex]), 0);
//					}
                    addBuffOrDeBuffValue = float.Parse(EditorGUI.TextField(new Rect(460, 90, 80, 18), addBuffOrDeBuffValue.ToString()));
                    GUI.Label(new Rect(545, 90, 70, 18), "首招生效:");
                    addBuffOrDeBuffFirstEffect = EditorGUI.Toggle(new Rect(620, 90, 30, 18), addBuffOrDeBuffFirstEffect);
                    if (GUI.Button(new Rect(655, 90, 40, 18), "+"))
                    {
                        List <BuffData> buffs = buffGridIndex == 0 ? data.BuffDatas : data.DeBuffDatas;
                        if (buffs.Count < 5)
                        {
                            BuffData buff = buffs.Find((item) => { return(item.Type == buffTypeEnums[addBuffOrDeBuffTypeIndex]); });
                            if (buff == null)
                            {
                                BuffData newBuff = new BuffData();
                                newBuff.Type        = buffTypeEnums[addBuffOrDeBuffTypeIndex];
                                newBuff.Rate        = addBuffOrDeBuffRate;
                                newBuff.RoundNumber = addBuffOrDeBuffRoundNumber;
                                newBuff.Timeout     = (float)newBuff.RoundNumber;
                                newBuff.Value       = addBuffOrDeBuffValue;
                                newBuff.FirstEffect = addBuffOrDeBuffFirstEffect;
                                buffs.Add(newBuff);
                                data.Desc = createSkillDesc(data);
                                writeDataToJson();
                                oldSelGridInt = -1;
                                getData();
                                fetchData(searchKeyword);
                                addBuffOrDeBuffTypeIndex   = 0;
                                addBuffOrDeBuffRate        = 100;
                                addBuffOrDeBuffRoundNumber = 0;
                                addBuffOrDeBuffValue       = 0;
                                addBuffOrDeBuffFirstEffect = true;
                                this.ShowNotification(new GUIContent("添加成功"));
                            }
                            else
                            {
                                this.ShowNotification(new GUIContent("Buff或DeBuff类型已存在, 不能添加!"));
                            }
                        }
                        else
                        {
                            this.ShowNotification(new GUIContent("Buff或DeBuff已到上限,不能添加!"));
                        }
                    }
                    float buffsStartY = 110;
                    if (buffGridIndex == 0)
                    {
                        for (int i = 0; i < theBuffTypeIndexs.Count; i++)
                        {
                            GUI.Label(new Rect(85, buffsStartY + i * 20, 40, 18), "类型:");
                            theBuffTypeIndexs[i] = EditorGUI.Popup(new Rect(130, buffsStartY + i * 20, 100, 18), theBuffTypeIndexs[i], buffTypeStrs.ToArray());
                            GUI.Label(new Rect(235, buffsStartY + i * 20, 40, 18), "概率:");
                            theBuffRates[i] = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(280, buffsStartY + i * 20, 40, 18), theBuffRates[i].ToString())), 0, 100);
                            GUI.Label(new Rect(325, buffsStartY + i * 20, 40, 18), "续数:");
                            theBuffRoundNumbers[i] = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(370, buffsStartY + i * 20, 40, 18), theBuffRoundNumbers[i].ToString())), 0, 100);
                            GUI.Label(new Rect(415, buffsStartY + i * 20, 40, 18), "数值:");
//							theBuffValues[i] = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(460, buffsStartY + i * 20, 80, 18), theBuffValues[i].ToString())), 0, getBuffValueRangeTop(buffTypeEnums[theBuffTypeIndexs[i]]));
                            theBuffValues[i] = float.Parse(EditorGUI.TextField(new Rect(460, buffsStartY + i * 20, 80, 18), theBuffValues[i].ToString()));
                            GUI.Label(new Rect(545, buffsStartY + i * 20, 70, 18), "首招生效:");
                            theBuffFirstEffects[i] = EditorGUI.Toggle(new Rect(620, buffsStartY + i * 20, 30, 18), theBuffFirstEffects[i]);
                            if (GUI.Button(new Rect(655, buffsStartY + i * 20, 40, 18), "修改"))
                            {
                                if (data.BuffDatas.Count > i)
                                {
                                    int buffIndex = data.BuffDatas.FindIndex((item) => { return(item.Type == buffTypeEnums[theBuffTypeIndexs[i]]); });
                                    if (buffIndex >= 0 && buffIndex != i)
                                    {
                                        this.ShowNotification(new GUIContent("Buff或DeBuff类型已存在, 不能修改!"));
                                        return;
                                    }
                                    data.BuffDatas[i].Type        = buffTypeEnums[theBuffTypeIndexs[i]];
                                    data.BuffDatas[i].Rate        = theBuffRates[i];
                                    data.BuffDatas[i].RoundNumber = theBuffRoundNumbers[i];
                                    data.BuffDatas[i].Timeout     = (float)data.BuffDatas[i].RoundNumber;
                                    data.BuffDatas[i].Value       = theBuffValues[i];
                                    data.BuffDatas[i].FirstEffect = theBuffFirstEffects[i];
                                    data.Desc = createSkillDesc(data);
                                    writeDataToJson();
                                    oldSelGridInt = -1;
                                    getData();
                                    fetchData(searchKeyword);
                                    this.ShowNotification(new GUIContent("修改成功"));
                                }
                            }
                            if (GUI.Button(new Rect(700, buffsStartY + i * 20, 40, 18), "-"))
                            {
                                if (data.BuffDatas.Count > i)
                                {
                                    data.BuffDatas.RemoveAt(i);
                                    writeDataToJson();
                                    oldSelGridInt = -1;
                                    getData();
                                    fetchData(searchKeyword);
                                    this.ShowNotification(new GUIContent("删除成功"));
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < theDeBuffTypeIndexs.Count; i++)
                        {
                            GUI.Label(new Rect(85, buffsStartY + i * 20, 40, 18), "类型:");
                            theDeBuffTypeIndexs[i] = EditorGUI.Popup(new Rect(130, buffsStartY + i * 20, 100, 18), theDeBuffTypeIndexs[i], buffTypeStrs.ToArray());
                            GUI.Label(new Rect(235, buffsStartY + i * 20, 40, 18), "概率:");
                            theDeBuffRates[i] = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(280, buffsStartY + i * 20, 40, 18), theDeBuffRates[i].ToString())), 0, 100);
                            GUI.Label(new Rect(325, buffsStartY + i * 20, 40, 18), "持续:");
                            theDeBuffRoundNumbers[i] = Mathf.Clamp(int.Parse(EditorGUI.TextField(new Rect(370, buffsStartY + i * 20, 40, 18), theDeBuffRoundNumbers[i].ToString())), 0, 100);
                            GUI.Label(new Rect(415, buffsStartY + i * 20, 40, 18), "数值:");
//							theDeBuffValues[i] = Mathf.Clamp(float.Parse(EditorGUI.TextField(new Rect(460, buffsStartY + i * 20, 80, 18), theDeBuffValues[i].ToString())), -getBuffValueRangeTop(buffTypeEnums[theDeBuffTypeIndexs[i]]), 0);
                            theDeBuffValues[i] = float.Parse(EditorGUI.TextField(new Rect(460, buffsStartY + i * 20, 80, 18), theDeBuffValues[i].ToString()));
                            GUI.Label(new Rect(545, buffsStartY + i * 20, 70, 18), "首招生效:");
                            theDeBuffFirstEffects[i] = EditorGUI.Toggle(new Rect(620, buffsStartY + i * 20, 30, 18), theDeBuffFirstEffects[i]);
                            if (GUI.Button(new Rect(655, buffsStartY + i * 20, 40, 18), "修改"))
                            {
                                if (data.DeBuffDatas.Count > i)
                                {
                                    int buffIndex = data.DeBuffDatas.FindIndex((item) => { return(item.Type == buffTypeEnums[theDeBuffTypeIndexs[i]]); });
                                    if (buffIndex >= 0 && buffIndex != i)
                                    {
                                        this.ShowNotification(new GUIContent("Buff或DeBuff类型已存在, 不能修改!"));
                                        return;
                                    }
                                    data.DeBuffDatas[i].Type        = buffTypeEnums[theDeBuffTypeIndexs[i]];
                                    data.DeBuffDatas[i].Rate        = theDeBuffRates[i];
                                    data.DeBuffDatas[i].RoundNumber = theDeBuffRoundNumbers[i];
                                    data.DeBuffDatas[i].Timeout     = (float)data.DeBuffDatas[i].RoundNumber;
                                    data.DeBuffDatas[i].Value       = theDeBuffValues[i];
                                    data.DeBuffDatas[i].FirstEffect = theDeBuffFirstEffects[i];
                                    writeDataToJson();
                                    oldSelGridInt = -1;
                                    getData();
                                    fetchData(searchKeyword);
                                    this.ShowNotification(new GUIContent("修改成功"));
                                }
                            }
                            if (GUI.Button(new Rect(700, buffsStartY + i * 20, 40, 18), "-"))
                            {
                                if (data.DeBuffDatas.Count > i)
                                {
                                    data.DeBuffDatas.RemoveAt(i);
                                    writeDataToJson();
                                    oldSelGridInt = -1;
                                    getData();
                                    fetchData(searchKeyword);
                                    this.ShowNotification(new GUIContent("删除成功"));
                                }
                            }
                        }
                    }
                    GUILayout.EndArea();


                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY + 245, 800, 120));
                    GUI.Label(new Rect(0, 0, 800, 18), "|--------额外招式-----------------------------------------------------------------------|");
                    addedSkillIndex = EditorGUI.Popup(new Rect(0, 20, 100, 18), addedSkillIndex, allDataNames.ToArray());
                    if (GUI.Button(new Rect(105, 20, 100, 18), "新增额外招式"))
                    {
                        if (addedSkillIndex <= 0 || allSkillDatas.Count <= addedSkillIndex)
                        {
                            return;
                        }
                        if (data.ResourceAddedSkillIds.Count >= 4)
                        {
                            this.ShowNotification(new GUIContent("一个招式只能拥有最多4个额外招式!"));
                            return;
                        }
                        if (allSkillDatas[addedSkillIndex].Id == data.Id)
                        {
                            this.ShowNotification(new GUIContent("额外招式不能和主招式相同!"));
                            return;
                        }
                        data.ResourceAddedSkillIds.Add(allSkillDatas[addedSkillIndex].Id);
                        data.Desc = createSkillDesc(data);
                        writeDataToJson();
                        oldSelGridInt = -1;
                        getData();
                        fetchData(searchKeyword);
//						addedSkillIndex = 0;
                        this.ShowNotification(new GUIContent("添加成功"));
                    }
                    for (int i = 0; i < data.ResourceAddedSkillIds.Count; i++)
                    {
                        GUI.Label(new Rect(0, 40 + i * 20, 100, 18), dataMapping[data.ResourceAddedSkillIds[i]].Name);
                        GUI.Label(new Rect(105, 40 + i * 20, 100, 18), string.Format("触发概率: {0}%", dataMapping[data.ResourceAddedSkillIds[i]].Rate));
                        if (GUI.Button(new Rect(210, 40 + i * 20, 40, 18), "-"))
                        {
                            if (data.ResourceAddedSkillIds.Count > i)
                            {
                                data.ResourceAddedSkillIds.RemoveAt(i);
                                writeDataToJson();
                                oldSelGridInt = -1;
                                getData();
                                fetchData(searchKeyword);
//								addedSkillIndex = 0;
                                this.ShowNotification(new GUIContent("删除成功"));
                            }
                        }
                    }
                    GUILayout.EndArea();
                }
            }

            GUILayout.BeginArea(new Rect(listStartX + 205, listStartY + 380, 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), "招式名:");
                addSkillName = EditorGUI.TextField(new Rect(205, 0, 100, 18), addSkillName);
                if (GUI.Button(new Rect(0, 20, 60, 18), "确定添加"))
                {
                    toolState = 0;
                    if (addId == "")
                    {
                        this.ShowNotification(new GUIContent("Id不能为空!"));
                        return;
                    }
                    if (addSkillName == "")
                    {
                        this.ShowNotification(new GUIContent("招式名不能为空!"));
                        return;
                    }
                    if (dataMapping.ContainsKey(addId))
                    {
                        this.ShowNotification(new GUIContent("Id重复!"));
                        return;
                    }
                    SkillData addSkillData = new SkillData();
                    addSkillData.Type = SkillType.PhysicsAttack;
                    addSkillData.Id   = addId;
                    addSkillData.Name = addSkillName;
                    dataMapping.Add(addId, addSkillData);
                    addSkillData.Desc = createSkillDesc(addSkillData);
                    ResourceSrcData findIcon = icons.Find(item => item.Name.IndexOf(addSkillData.Name) >= 0);
                    if (findIcon != null)
                    {
                        addSkillData.IconId = findIcon.Id;
                    }
                    writeDataToJson();
                    addedId = addId;
                    getData();
                    fetchData(searchKeyword);
//					addId = "";
                    addSkillName      = "";
                    addSkillData.Desc = createSkillDesc(addSkillData);
                    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();
        }
Пример #5
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();
        }