Esempio n. 1
0
        private List <string[]> TransferGoodsIdsToString(MyNpc trader)
        {
            List <string[]> goodsListTotal = new List <string[]> ();

            for (int i = 0; i < trader.goodsGroupList.Count; i++)
            {
                GoodsGroup gg = trader.goodsGroupList [i];

                string[] idsInString = new string[5];

                for (int j = 0; j < 5; j++)
                {
                    Goods g = gg.goodsList [j];

                    StringBuilder sb = new StringBuilder();

                    for (int k = 0; k < g.possibleItemIdsAsGoods.Length; k++)
                    {
                        sb.AppendFormat("{0}_", g.possibleItemIdsAsGoods [k].ToString());
                    }

                    sb.Remove(sb.Length - 1, 1);

                    idsInString [j] = sb.ToString();
                }

                goodsListTotal.Add(idsInString);
            }

            return(goodsListTotal);
        }
Esempio n. 2
0
        public void OnGUI()
        {
            Rect windowRect = npcEditor.position;

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, new GUILayoutOption[] {
                GUILayout.Height(windowRect.height),
                GUILayout.Width(windowRect.width)
            });

            EditorGUILayout.LabelField("please input information of npc");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("npc数据源", labelLayouts);

            rect        = EditorGUILayout.GetControlRect(GUILayout.Width(300));
            npcDataPath = EditorGUI.TextField(rect, npcDataPath);
            //如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在位置在文本输入框内
            if ((UnityEngine.Event.current.type == UnityEngine.EventType.DragUpdated ||
                 UnityEngine.Event.current.type == UnityEngine.EventType.DragExited) &&
                rect.Contains(UnityEngine.Event.current.mousePosition))
            {
                //改变鼠标的外表
                DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                {
                    npcDataPath = DragAndDrop.paths [0];
                }
            }


            EditorGUILayout.EndHorizontal();

            bool loadNpcData = GUILayout.Button("加载npc数据", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(150)
            });

            if (loadNpcData)
            {
                dialogGroups.Clear();
                chatDialogGroups.Clear();
                taskDialogGroups.Clear();

                dialogGroupFoldoutList.Clear();
                dialogFoldoutList.Clear();
                rewardTypeCountList.Clear();
                taskFoldoutList.Clear();

                string npcDataFileName = Path.GetFileName(npcDataPath);

                npcDataPath = string.Format("{0}/NPCs/{1}", CommonData.originDataPath, npcDataFileName);

                string npcTypeStr = npcDataFileName.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)[0];


                npc = DataHandler.LoadDataToSingleModelWithPath <MyNpc> (npcDataPath);



                switch (npcTypeStr)
                {
                case "Normal":
                    npcType = NPCType.Normal;
                    break;

                case "Trader":
                    npcType          = NPCType.Trader;
                    goodsIdsInString = TransferGoodsIdsToString(npc);
                    break;
                }

                Debug.Log(npcDataPath);

                for (int i = 0; i < npc.chatDialogGroups.Count; i++)
                {
                    dialogGroups.Add(npc.chatDialogGroups [i]);
                    chatDialogGroups.Add(npc.chatDialogGroups [i]);

                    bool foldout = false;
                    dialogGroupFoldoutList.Add(foldout);

                    List <bool> foldoutList = new List <bool> ();
                    dialogFoldoutList.Add(foldoutList);

                    List <int> rewardTypeCounts = new List <int> ();
                    rewardTypeCountList.Add(rewardTypeCounts);

                    for (int j = 0; j < npc.chatDialogGroups [i].dialogs.Count; j++)
                    {
                        Dialog d             = npc.chatDialogGroups [i].dialogs [j];
                        bool   dialogFoldout = false;
                        foldoutList.Add(dialogFoldout);

                        rewardTypeCounts.Add(d.rewardIds.Length);
                    }
                }

                for (int i = 0; i < npc.tasks.Count; i++)
                {
                    dialogGroups.Add(npc.tasks [i].taskDialogGroup);
                    bool foldout = false;
                    taskFoldoutList.Add(foldout);
                    dialogGroupFoldoutList.Add(dialogGroupFoldout);
                    List <bool> foldoutList = new List <bool> ();
                    dialogFoldoutList.Add(foldoutList);
                    List <int> rewardTypeCounts = new List <int> ();
                    rewardTypeCountList.Add(rewardTypeCounts);

                    for (int j = 0; j < npc.tasks [i].taskDialogGroup.dialogs.Count; j++)
                    {
                        Dialog d             = npc.tasks [i].taskDialogGroup.dialogs [j];
                        bool   dialogFoldout = false;
                        foldoutList.Add(dialogFoldout);

                        rewardTypeCounts.Add(d.rewardIds.Length);
                    }
                }

                for (int i = 0; i < npc.attachedFunctions.Length; i++)
                {
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.SkillPromotion)
                    {
                        skillPromotionFunction = true;
                    }
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.PropertyPromotion)
                    {
                        propertyPromotionFunction = true;
                    }
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.Task)
                    {
                        taskFunction = true;
                    }
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.CharactersTrade)
                    {
                        characterTradeFunction = true;
                    }
                }
            }

            CreateNPCBaseInformationGUI();



            EditorGUILayout.BeginHorizontal();
            bool createNewDialogGroup = GUILayout.Button("新建对话组", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            bool removeLastDialogGroup = GUILayout.Button("删除尾部对话组", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            EditorGUILayout.EndHorizontal();

            if (createNewDialogGroup)
            {
                DialogGroup chatDialogGroup = new DialogGroup();
                dialogGroups.Add(chatDialogGroup);
                bool foldout = true;
                dialogGroupFoldoutList.Add(foldout);
                List <bool> foldoutList = new List <bool> ();
                dialogFoldoutList.Add(foldoutList);
                List <int> rewardTypeCounts = new List <int> ();
                rewardTypeCountList.Add(rewardTypeCounts);
                ReCalculateDialogGroups();
            }

            if (removeLastDialogGroup && chatDialogGroups.Count > 0)
            {
                DialogGroup dg = chatDialogGroups [chatDialogGroups.Count - 1];

                int index = dialogGroups.FindIndex(delegate(DialogGroup obj) {
                    return(obj == dg);
                });
                dialogGroupFoldoutList.RemoveAt(index);
                dialogFoldoutList.RemoveAt(index);
                rewardTypeCountList.RemoveAt(index);

                chatDialogGroups.Remove(dg);
                dialogGroups.Remove(dg);

                ReCalculateDialogGroups();
            }



            for (int i = 0; i < chatDialogGroups.Count; i++)
            {
                DialogGroup dg = chatDialogGroups [i];

                int index = dialogGroups.FindIndex(delegate(DialogGroup obj) {
                    return(obj == dg);
                });

                List <bool> currentDialogFoldoutList = dialogFoldoutList [index];

                List <int> currentDialogRewardTypeCountList = rewardTypeCountList [index];

                dialogGroupFoldoutList [index] = EditorGUILayout.Foldout(dialogGroupFoldoutList [index], "对话组编辑区");

                if (dialogGroupFoldoutList [index])
                {
                    CreateDialogGroupGUI(dg, currentDialogFoldoutList, currentDialogRewardTypeCountList);
                }
            }


            EditorGUILayout.BeginHorizontal();
            bool createNewTask = GUILayout.Button("新建任务", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            bool removeLastTask = GUILayout.Button("删除尾部任务", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            EditorGUILayout.EndHorizontal();


            if (createNewTask)
            {
                Task task = new Task();
                npc.tasks.Add(task);
                DialogGroup taskDialogGroup = new DialogGroup();
                dialogGroups.Add(taskDialogGroup);
                task.taskDialogGroup = taskDialogGroup;
                bool foldout = true;
                taskFoldoutList.Add(foldout);
                dialogGroupFoldoutList.Add(dialogGroupFoldout);
                List <bool> foldoutList = new List <bool> ();
                dialogFoldoutList.Add(foldoutList);
                List <int> rewardIdsCount = new List <int> ();
                rewardTypeCountList.Add(rewardIdsCount);
                ReCalculateDialogGroups();
            }

            if (removeLastTask && npc.tasks.Count > 0)
            {
                Task task = npc.tasks [npc.tasks.Count - 1];

                npc.tasks.RemoveAt(npc.tasks.Count - 1);

                taskFoldoutList.RemoveAt(taskFoldoutList.Count - 1);



                int index = dialogGroups.FindIndex(delegate(DialogGroup obj) {
                    return(obj == task.taskDialogGroup);
                });

                dialogGroupFoldoutList.RemoveAt(index);
                dialogFoldoutList.RemoveAt(index);
                rewardTypeCountList.RemoveAt(index);

                taskDialogGroups.Remove(task.taskDialogGroup);
                dialogGroups.Remove(task.taskDialogGroup);

                ReCalculateDialogGroups();
            }

            for (int i = 0; i < npc.tasks.Count; i++)
            {
                Task task = npc.tasks [i];
                taskFoldoutList [i] = EditorGUILayout.Foldout(taskFoldoutList [i], "任务编辑区");
                if (taskFoldoutList [i])
                {
                    CreateTaskGUI(task);
                }
            }

//			EditorGUILayout.Separator ();
//			EditorGUILayout.LabelField ("************************结束*************************", new GUILayoutOption[] {
//				GUILayout.Height (20),
//				GUILayout.Width (600)
//			});
            bool saveNpcData = GUILayout.Button("保存NPC数据", new GUILayoutOption[] {
                GUILayout.Width(500),
                GUILayout.Height(20)
            });

            if (saveNpcData)
            {
                SaveNpcData();
            }



            EditorGUILayout.EndScrollView();
        }