-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathBehaviourEnabledObserver2.cs
More file actions
62 lines (56 loc) · 2.02 KB
/
Copy pathBehaviourEnabledObserver2.cs
File metadata and controls
62 lines (56 loc) · 2.02 KB
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
53
54
55
56
57
58
59
60
61
62
namespace Zinnia.Event
{
using UnityEngine;
using UnityEngine.Events;
using Malimbe.BehaviourStateRequirementMethod;
using Malimbe.MemberClearanceMethod;
using Malimbe.PropertySerializationAttribute;
using Malimbe.XmlDocumentationAttribute;
using Zinnia.Data.Collection.List;
using Zinnia.Extension;
using Zinnia.Process;
using Zinnia.Rule;
/// <summary>
/// Emits an event once a list of <see cref="Behaviour"/>s all are <see cref="Behaviour.isActiveAndEnabled"/>.
/// </summary>
public class BehaviourEnabledObserver2 : MonoBehaviour, IProcessable
{
/// <summary>
/// The <see cref="Behaviour"/>s to observe.
/// </summary>
[Serialized]
[field: DocumentedByXml]
public BehaviourObservableList Behaviours { get; set; }
/// <summary>
/// The rule to match against the Behaviours.
/// </summary>
[Serialized, Cleared]
[field: DocumentedByXml]
public RuleContainer Rule { get; set; }
/// <summary>
/// Emitted when all <see cref="Behaviours"/> are <see cref="Behaviour.isActiveAndEnabled"/>.
/// </summary>
[DocumentedByXml]
public UnityEvent ActiveAndEnabled = new UnityEvent();
/// <summary>
/// Checks whether all <see cref="Behaviours"/> are <see cref="Behaviour.isActiveAndEnabled"/> and emits <see cref="ActiveAndEnabled"/> if they are.
/// </summary>
/// <returns>Whether all <see cref="Behaviours"/> are active and enabled.</returns>
[RequiresBehaviourState]
public virtual void Process()
{
if (Behaviours == null || Behaviours.NonSubscribableElements.Count == 0)
{
return;
}
foreach (Behaviour behaviour in Behaviours.NonSubscribableElements)
{
if (!Rule.Accepts(behaviour))
{
return;
}
}
ActiveAndEnabled?.Invoke();
}
}
}