summaryrefslogtreecommitdiff
path: root/Assets/Scripts/AbilitySystem/Trigger.cs
blob: dc173a6da7167a6947bff8658b25a55719b06605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 不同效果的trigger继承这个基类
/// </summary>

public sealed class Trigger
{
	public bool Swallow;

    private ConditionBase m_Condition;
	private List<ActionBase> m_ActionChain = new List<ActionBase>();
	
	public Trigger(ConditionBase condition, List<ActionBase> actions, bool onlyOnce = false, bool swallow = true)
	{
		Swallow = swallow;
		m_Condition = condition;
		m_ActionChain.AddRange(actions);
	}
	public Trigger(ConditionBase condition, ActionBase action, bool onlyOnce = false, bool swallow = true)
	{
		Swallow = swallow;
		m_Condition = condition;
		m_ActionChain.Add(action);
	}

	//重置触发器的参数
	public void Reset()
	{

	}

	/// <summary>
	/// 如果触发执行了,返回true,否则返回false
	/// </summary>
	/// <returns></returns>
	public bool Update()
    {
		if (m_Condition.Evaluate())
		{
			foreach(var action in m_ActionChain)
			{
				action.Execute();
			}
			return true;
		}
		return false;
    }

}