Ejemplo n.º 1
0
        ///检测选项是否可用
        public bool CheckChoiceInfo(ChoiceInfo info)
        {
            if (info.Conditions == null || info.Conditions.Count == 0)
            {
                return(true);
            }
            bool result = false;

            foreach (List <string> conditions in info.Conditions.Values)
            {
                if (!result)
                {
                    result = true;
                    for (int i = 0; i < conditions.Count; i++)
                    {
                        ChoiceCondition con = Data.Instance.GetConditionData(conditions[i]);
                        if (con != null && !CheckCondition(con))
                        {
                            result = false;
                            break;
                        }
                    }
                    if (result)
                    {
                        break;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        ///获取一个事件的固定数量的选项
        public List <ChoiceInfo> GetEventChoice(EventInfo info)
        {
            List <ChoiceInfo> result = new List <ChoiceInfo>();

            for (int i = 0; i < info.Choice.Count; i++)
            {
                ChoiceInfo choice = Data.Instance.GetChoiceData(info.Choice[i]);
                if (choice != null)
                {
                    Debug.Log("1选项" + choice.ID);
                    if (CheckChoiceInfo(choice))
                    {
                        Debug.Log("2选项" + choice.ID);
                        result.Add(choice);
                    }
                }
            }
            if (result.Count > info.ChoiceNum)
            {
                int count = result.Count - info.ChoiceNum;
                for (int i = 0; i < count; i++)
                {
                    result.RemoveAt(Random.Range(0, result.Count));
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
 public void ReplaceChoiceData(string ID, ChoiceInfo info)
 {
     if (ChoiceDatas.ContainsKey(ID))
     {
         ChoiceDatas.Remove(ID);
         ChoiceDatas.Add(info.ID, info);
     }
 }
Ejemplo n.º 4
0
 public bool AddChoiceData(ChoiceInfo info)
 {
     if (!ChoiceDatas.ContainsKey(info.ID))
     {
         ChoiceDatas.Add(info.ID, info);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 5
0
 //获取下一个需要检测的事件对象(外层只需要设置ToIDsIndex增长就可以了)
 public EventInfo GetNextEvent()
 {
     if (ChoiceIndex < Info.Choice.Count)
     {
         ChoiceInfo choice = Data.Instance.GetChoiceData(Info.Choice[ChoiceIndex]);
         if (ToIDsIndex < choice.ToIDs.Count)
         {
             return(Data.Instance.GetEventData(choice.ToIDs[ToIDsIndex]));
         }
         else
         {
             ChoiceIndex++;
             ToIDsIndex = 0;
             return(GetNextEvent());
         }
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
        void ChoiceGUI()
        {
            EditorGUILayout.BeginHorizontal();
            {
                //左侧列表
                EditorGUILayout.BeginVertical();
                {
                    ChoiceScrollVec = EditorGUILayout.BeginScrollView(ChoiceScrollVec);
                    {
                        ChoiceIndex = GUILayout.SelectionGrid(ChoiceIndex, ChoiceTitles.ToArray(), 1);
                    }
                    EditorGUILayout.EndScrollView();
                    //新增按钮
                    if (GUILayout.Button("新选项"))
                    {
                        ChoiceInfo    = new ChoiceInfo();
                        ChoiceInfo.ID = "New ID" + ChoiceTitles.Count;
                        if (Data.Instance.AddChoiceData(ChoiceInfo))
                        {
                            ChoiceTitles.Add(ChoiceInfo.ID + ":" + ChoiceInfo.Content);
                            ChoiceIndex = ChoiceTitles.Count - 1;
                            EditorGUILayout.EndVertical();
                            return;//重新刷新
                        }
                    }
                }
                EditorGUILayout.EndVertical();
                //间隔
                EditorGUILayout.Separator();
                //右侧显示
                EditorGUILayout.BeginVertical();
                {
                    if (ChoiceTitles.Count > 0)
                    {
                        ChoiceInfo = Data.Instance.GetChoiceData(ChoiceTitles[ChoiceIndex].Split(':')[0]);
                        if (ChoiceInfo != null)
                        {
                            //ID
                            ChoiceInfo.ID = EditorGUILayout.TextField("ID:", ChoiceInfo.ID);
                            //Content
                            ChoiceInfo.Content = EditorGUILayout.TextField("Content:", ChoiceInfo.Content);


                            EditorGUILayout.BeginHorizontal();
                            {
                                //保存数据
                                if (GUILayout.Button("保存"))
                                {
                                    Data.Instance.ReplaceChoiceData(ChoiceTitles[ChoiceIndex].Split(':')[0], ChoiceInfo);
                                    ChoiceTitles[EventIndex] = ChoiceInfo.ID + ":" + ChoiceInfo.Content;
                                    //往文件写入

                                    ChoiceIndex = ChoiceTitles.Count - 1;
                                    return;//刷新
                                }
                                //删除数据
                                if (GUILayout.Button("删除"))
                                {
                                    Data.Instance.DeleteChoiceData(ChoiceTitles[ChoiceIndex].Split(':')[0]);
                                    ChoiceTitles.RemoveAt(ChoiceIndex);
                                    //往文件写入

                                    ChoiceIndex = ChoiceTitles.Count - 1;
                                    return;//刷新
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }