Example #1
0
        public bool CheckCondition(MapEventCondition data, MapEvent pEventData, TriggerConditionType except, params object[] args)
        {
            switch (data.Type)
            {
            case TriggerConditionType.EnterRegion:
            case TriggerConditionType.InitRegion:
            case TriggerConditionType.LeaveRegion:
            {
                return(data.Type == except);
            }

            case TriggerConditionType.WaveIndex:
            case TriggerConditionType.WavesetEnd:
            {
                if (except == data.Type)
                {
                    return((int)args[0] == data.Args.ToInt32());
                }
                else
                {
                    return(false);
                }
            }

            default:
                return(false);
            }
        }
Example #2
0
        public List <MapEventCondition> Conditions2;                                  //间隔触发条件

        public override void Read(XmlNode os)
        {
            foreach (XmlNode current in XmlObject.GetChilds(os))
            {
                switch (current.Name)
                {
                case "Type":
                    this.Type = (MapTriggerType)ReadInt(current);
                    break;

                case "Id":
                    this.Id = ReadInt(current);
                    break;

                case "Active":
                    this.Active = ReadBool(current);
                    break;

                case "Relation1":
                    this.Relation1 = (ConditionRelationType)ReadInt(current);
                    break;

                case "Relation2":
                    this.Relation2 = (ConditionRelationType)ReadInt(current);
                    break;

                case "Conditions1":
                    XmlObject.GetChilds(current).ForEach(delegate(XmlNode pNode)
                    {
                        MapEventCondition data = new MapEventCondition();
                        data.Read(pNode);
                        Conditions1.Add(data);
                    });
                    break;

                case "Conditions2":
                    XmlObject.GetChilds(current).ForEach(delegate(XmlNode pNode)
                    {
                        MapEventCondition data = new MapEventCondition();
                        data.Read(pNode);
                        Conditions2.Add(data);
                    });
                    break;

                case "TriggerNum":
                    this.TriggerNum = ReadInt(current);
                    break;

                case "TriggerInterval":
                    this.TriggerInterval = ReadFloat(current);
                    break;

                case "TriggerDelay":
                    this.TriggerDelay = ReadFloat(current);
                    break;
                }
            }
        }
Example #3
0
        public void ActiveEventsByCondition(TriggerConditionType type, params object[] args)
        {
            for (int i = 0; i < m_Data.Events.Count; i++)
            {
                MapEvent data = m_Data.Events[i];
                if (m_HasActiveEvents.Contains(data) && data.Conditions2 == null)
                {
                    continue;
                }

                int num = 0;
                for (int k = 0; k < data.Conditions1.Count; k++)
                {
                    MapEventCondition pChild = data.Conditions1[k];
                    bool isTrigger           = CheckCondition(pChild, data, type, args);
                    if (isTrigger)
                    {
                        num++;
                    }
                }

                bool active = false;
                switch (data.Relation1)
                {
                case ConditionRelationType.And:
                    active = num >= data.Conditions1.Count;
                    break;

                case ConditionRelationType.Or:
                    active = num > 0;
                    break;
                }

                if (active)
                {
                    GameEntry.Level.StartMapEvent(data, this);
                    if (!m_HasActiveEvents.Contains(data))
                    {
                        m_HasActiveEvents.Add(data);
                    }
                }
            }
        }
Example #4
0
        public override void OnInspectorGUI()
        {
            LevelEvent pElem = target as LevelEvent;

            MapTriggerType pType = (MapTriggerType)EditorGUILayout.EnumPopup("触发事件类型", pElem.Type);

            if (pType != pElem.Type)
            {
                pElem.Type = pType;
                pElem.SetName();
            }

            int pTypeId = EditorGUILayout.IntField("触发事件类型ID", pElem.TypeId);

            if (pTypeId != pElem.TypeId)
            {
                pElem.TypeId = pTypeId;
                pElem.SetName();
            }

            bool pActive = EditorGUILayout.Toggle("激活或者销毁", pElem.Active);

            if (pActive != pElem.Active)
            {
                pElem.Active = pActive;
            }

            ConditionRelationType pR1 = (ConditionRelationType)EditorGUILayout.EnumPopup("首次触发条件之间关系", pElem.Relation1);

            if (pR1 != pElem.Relation1)
            {
                pElem.Relation1 = pR1;
            }

            float pTriggerDelay = EditorGUILayout.FloatField("触发延迟", pElem.TriggerDelay);

            if (pElem.TriggerDelay != pTriggerDelay)
            {
                pElem.TriggerDelay = pTriggerDelay;
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("首次触发条件");
            if (UnityEngine.GUILayout.Button("添加"))
            {
                pElem.Conditions1.Add(new MapEventCondition());
            }
            EditorGUILayout.EndHorizontal();

            int pDeleteIndex1 = -1;

            for (int i = 0; i < pElem.Conditions1.Count; i++)
            {
                EditorGUILayout.Space();
                EditorGUIUtility.labelWidth = 100;
                MapEventCondition data = pElem.Conditions1[i];
                EditorGUILayout.LabelField("条件" + (i + 1));
                EditorGUIUtility.labelWidth = 100;
                TriggerConditionType p = (TriggerConditionType)EditorGUILayout.EnumPopup("类型", data.Type);
                if (p != data.Type)
                {
                    data.Type = p;
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUIUtility.labelWidth = 100;
                string s = EditorGUILayout.TextField("参数", data.Args);
                if (s != data.Args)
                {
                    data.Args = s;
                }

                if (UnityEngine.GUILayout.Button("删除"))
                {
                    pDeleteIndex1 = i;
                }
                EditorGUILayout.EndHorizontal();
            }

            if (pDeleteIndex1 >= 0)
            {
                pElem.Conditions1.RemoveAt(pDeleteIndex1);
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            bool pUseTriggerInterval = EditorGUILayout.Toggle("是否间隔触发", pElem.UseIntervalTrigger);

            if (pElem.UseIntervalTrigger != pUseTriggerInterval)
            {
                pElem.UseIntervalTrigger = pUseTriggerInterval;
            }
            if (pElem.UseIntervalTrigger == false)
            {
                return;
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("间隔触发条件");
            if (UnityEngine.GUILayout.Button("添加"))
            {
                pElem.Conditions2.Add(new MapEventCondition());
            }
            EditorGUILayout.EndHorizontal();

            int pTriggerNum = EditorGUILayout.IntField("间隔触发次数(<=0代表无限)", pElem.TriggerNum);

            if (pElem.TriggerNum != pTriggerNum)
            {
                pElem.TriggerNum = pTriggerNum;
            }

            float pTriggerInterval = EditorGUILayout.FloatField("触发间隔时间", pElem.TriggerInterval);

            if (pElem.TriggerInterval != pTriggerInterval)
            {
                pElem.TriggerInterval = pTriggerInterval;
            }

            int pDeleteIndex2 = -1;

            for (int i = 0; i < pElem.Conditions2.Count; i++)
            {
                EditorGUILayout.Space();
                MapEventCondition    data = pElem.Conditions2[i];
                TriggerConditionType p    = (TriggerConditionType)EditorGUILayout.EnumPopup(GlobalTools.Format("条件{0}:  类型", i + 1), data.Type);
                if (p != data.Type)
                {
                    data.Type = p;
                }
                string s = EditorGUILayout.TextField("参数", data.Args);
                if (s != data.Args)
                {
                    data.Args = s;
                }

                if (UnityEngine.GUILayout.Button("删除"))
                {
                    pDeleteIndex2 = i;
                }
            }

            if (pDeleteIndex2 >= 0)
            {
                pElem.Conditions2.RemoveAt(pDeleteIndex2);
            }
        }