Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ZoneEventManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using Newtonsoft.Json;
4using UnityEngine;
5
6public class ZoneEventManager : EClass
7{
8 public Zone zone;
9
10 [JsonProperty]
11 public List<ZoneEvent> list = new List<ZoneEvent>();
12
13 [JsonProperty]
14 public List<ZonePreEnterEvent> listPreEnter = new List<ZonePreEnterEvent>();
15
16 public void OnLoad(Zone _zone)
17 {
18 zone = _zone;
19 foreach (ZoneEvent item in list)
20 {
21 item.OnLoad(zone);
22 }
23 }
24
25 public void Add<T>(bool allowDuplicate = false) where T : ZoneEvent
26 {
27 Add(Activator.CreateInstance<T>(), allowDuplicate);
28 }
29
30 public void Add(ZoneEvent e, bool allowDuplicate = false)
31 {
33 {
34 return;
35 }
36 if (!allowDuplicate)
37 {
38 foreach (ZoneEvent item in list)
39 {
40 if (e.GetType() == item.GetType())
41 {
42 return;
43 }
44 }
45 }
46 list.Add(e);
47 e.zone = zone;
48 e.Init();
49 Debug.Log("#game zone event " + e.GetType()?.ToString() + " added.");
50 }
51
52 public void AddPreEnter(ZonePreEnterEvent e, bool executeIfActiveZone = true)
53 {
54 if (zone.IsActiveZone && executeIfActiveZone)
55 {
56 e.Execute();
57 }
58 else
59 {
60 listPreEnter.Add(e);
61 }
62 }
63
64 public T GetEvent<T>() where T : ZoneEvent
65 {
66 foreach (ZoneEvent item in list)
67 {
68 if (item is T)
69 {
70 return item as T;
71 }
72 }
73 return null;
74 }
75
76 public void Remove<T>() where T : ZoneEvent
77 {
78 for (int num = list.Count - 1; num >= 0; num--)
79 {
80 if (list[num] is T)
81 {
82 list[num].Kill();
83 }
84 }
85 }
86
87 public void Remove(ZoneEvent e)
88 {
89 list.Remove(e);
90 }
91
92 public void Clear()
93 {
94 list.Clear();
95 }
96
97 public void Tick(float delta)
98 {
99 list.ForeachReverse(delegate(ZoneEvent e)
100 {
101 e.Tick(delta);
102 });
103 }
104
105 public void OnVisit()
106 {
107 foreach (ZoneEvent item in list)
108 {
109 item.OnVisit();
110 }
111 }
112
113 public void OnLeaveZone()
114 {
115 foreach (ZoneEvent item in list)
116 {
117 item.OnLeaveZone();
118 }
119 }
120
121 public void OnSimulateHour()
122 {
123 if (list.Count == 0)
124 {
125 return;
126 }
127 foreach (ZoneEvent item in list.Copy())
128 {
129 item.OnSimulateHour();
130 }
131 }
132}
bool skipEvent
Definition: CoreDebug.cs:161
Definition: EClass.cs:5
static Zone _zone
Definition: EClass.cs:20
static CoreDebug debug
Definition: EClass.cs:48
List< ZoneEvent > list
void Add< T >(bool allowDuplicate=false)
List< ZonePreEnterEvent > listPreEnter
void Add(ZoneEvent e, bool allowDuplicate=false)
void OnLoad(Zone _zone)
void Tick(float delta)
void AddPreEnter(ZonePreEnterEvent e, bool executeIfActiveZone=true)
void Remove(ZoneEvent e)
void Tick(float delta)
Definition: ZoneEvent.cs:48
virtual bool debugSkip
Definition: ZoneEvent.cs:31
void Init()
Definition: ZoneEvent.cs:64
virtual void Execute()
Definition: Zone.cs:12
bool IsActiveZone
Definition: Zone.cs:486