fr.jeanf.eventsystem 0.1.69 → 0.1.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ using System;
2
+ using UnityEngine;
3
+ using UnityEngine.Events;
4
+
5
+ namespace jeanf.EventSystem
6
+ {
7
+ [System.Serializable]
8
+ public class TransformEvent : UnityEvent<Transform>
9
+ {
10
+
11
+ }
12
+ public class TransformEventListener : MonoBehaviour
13
+ {
14
+ [Header("Receiving on channel:")]
15
+ [SerializeField] private TransformEventChannelSO _channel = default;
16
+
17
+ public UnityEvent<Transform> OnEventRaised;
18
+
19
+ private void OnEnable()
20
+ {
21
+ if (_channel != null) _channel.OnEventRaised += Respond;
22
+ }
23
+
24
+ private void OnDisable()
25
+ {
26
+ if (_channel != null) _channel.OnEventRaised -= Respond;
27
+ }
28
+
29
+ private void Respond( Transform transform)
30
+ {
31
+ OnEventRaised?.Invoke(transform);
32
+ }
33
+
34
+ }
35
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: b7ec5aea555107f41ab4b0c5c779dacf
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,67 +1,69 @@
1
1
  using System;
2
- using System.Collections;
3
- using jeanf.EventSystem;
4
2
  using UnityEngine;
5
3
 
6
- public class PingableScriptableObject : MonoBehaviour, IScriptableObjectEventSender, IScriptableObjectEventListener, IDebugBehaviour
4
+ namespace jeanf.EventSystem
7
5
  {
8
- public bool isDebug
9
- {
10
- get => _isDebug;
11
- set => _isDebug = value;
12
- }
13
- [SerializeField] private bool _isDebug = false;
14
-
15
- [SerializeField] private VoidEventChannelSO refreshPingableObjects;
16
- [ReadOnly] [SerializeField] private string id = Guid.NewGuid().ToString();
17
-
18
- public ScriptableObjectEventChannelSO channel
19
- {
20
- get => _channel;
21
- set => _channel = value;
22
- }
23
-
24
- [SerializeField] private ScriptableObjectEventChannelSO _channel;
25
- public ScriptableObjectEvent OnEventRaised { get; set; }
26
-
27
-
28
- private void Awake()
6
+ public class PingableScriptableObject : MonoBehaviour, IScriptableObjectEventSender, IScriptableObjectEventListener, IDebugBehaviour
29
7
  {
30
- refreshPingableObjects.OnEventRaised += RefreshPingable;
31
- }
32
-
33
- private void OnEnable()
34
- {
35
- if (channel != null) channel.OnEventRaised += Respond;
36
- AddScriptableObjectToList(id, channel);
37
- }
38
- private void OnDisable() => Unsubscribe();
39
- private void OnDestroy() => Unsubscribe();
40
- private void Unsubscribe()
41
- {
42
-
43
- if (channel != null)
8
+ public bool isDebug
9
+ {
10
+ get => _isDebug;
11
+ set => _isDebug = value;
12
+ }
13
+ [SerializeField] private bool _isDebug = false;
14
+
15
+ [SerializeField] private VoidEventChannelSO refreshPingableObjects;
16
+ [ReadOnly] [SerializeField] private string id = Guid.NewGuid().ToString();
17
+
18
+ public ScriptableObjectEventChannelSO channel
44
19
  {
45
- channel.UnsubscribeEvent(id, channel);
46
- channel.OnEventRaised -= null;
20
+ get => _channel;
21
+ set => _channel = value;
22
+ }
23
+
24
+ [SerializeField] private ScriptableObjectEventChannelSO _channel;
25
+ public ScriptableObjectEvent OnEventRaised { get; set; }
26
+
27
+
28
+ private void Awake()
29
+ {
30
+ refreshPingableObjects.OnEventRaised += RefreshPingable;
31
+ }
32
+
33
+ private void OnEnable()
34
+ {
35
+ if (channel != null) channel.OnEventRaised += Respond;
36
+ AddScriptableObjectToList(id, channel);
37
+ }
38
+ private void OnDisable() => Unsubscribe();
39
+ private void OnDestroy() => Unsubscribe();
40
+ private void Unsubscribe()
41
+ {
42
+
43
+ if (channel != null)
44
+ {
45
+ channel.UnsubscribeEvent(id, channel);
46
+ channel.OnEventRaised -= null;
47
+ }
48
+
49
+ if (refreshPingableObjects.OnEventRaised != null)
50
+ refreshPingableObjects.OnEventRaised -= null;
51
+ }
52
+
53
+ private void Respond(string id, ScriptableObject value)
54
+ {
55
+ OnEventRaised?.Invoke(value);
56
+ if(isDebug) Debug.Log($" scriptableObject event raised: {value}");
57
+ }
58
+ public void AddScriptableObjectToList(string id, ScriptableObject value)
59
+ {
60
+ channel.RaiseEvent(id, value);
61
+ }
62
+
63
+ public void RefreshPingable()
64
+ {
65
+ AddScriptableObjectToList(id, channel);
47
66
  }
48
-
49
- if (refreshPingableObjects.OnEventRaised != null)
50
- refreshPingableObjects.OnEventRaised -= null;
51
- }
52
-
53
- private void Respond(string id, ScriptableObject value)
54
- {
55
- OnEventRaised?.Invoke(value);
56
- if(isDebug) Debug.Log($" scriptableObject event raised: {value}");
57
- }
58
- public void AddScriptableObjectToList(string id, ScriptableObject value)
59
- {
60
- channel.RaiseEvent(id, value);
61
- }
62
-
63
- public void RefreshPingable()
64
- {
65
- AddScriptableObjectToList(id, channel);
66
67
  }
67
68
  }
69
+
@@ -4,78 +4,82 @@ using jeanf.EventSystem;
4
4
  using UnityEngine;
5
5
  using Object = UnityEngine.Object;
6
6
 
7
- public class ScriptableObjectManager : MonoBehaviour, IDebugBehaviour
7
+ namespace jeanf.EventSystem
8
8
  {
9
- public bool isDebug
10
- {
11
- get => _isDebug;
12
- set => _isDebug = value;
13
- }
14
- [SerializeField] private bool _isDebug = false;
15
-
16
- [SerializeField] private VoidEventChannelSO RefreshPingableObjects;
17
- [SerializeField] private List<ScriptableObjectEventChannelSO> listOfPingableObjects = new List<ScriptableObjectEventChannelSO>();
9
+ public class ScriptableObjectManager : MonoBehaviour, IDebugBehaviour
10
+ {
11
+ public bool isDebug
12
+ {
13
+ get => _isDebug;
14
+ set => _isDebug = value;
15
+ }
16
+ [SerializeField] private bool _isDebug = false;
17
+
18
+ [SerializeField] private VoidEventChannelSO RefreshPingableObjects;
19
+ [SerializeField] private List<ScriptableObjectEventChannelSO> listOfPingableObjects = new List<ScriptableObjectEventChannelSO>();
18
20
 
19
- private Dictionary<Object, Dictionary<string, Object>> genericDictionary = new Dictionary<Object, Dictionary<string, Object>>();
21
+ private Dictionary<Object, Dictionary<string, Object>> genericDictionary = new Dictionary<Object, Dictionary<string, Object>>();
20
22
 
21
- private void OnEnable() => Subscribe();
22
- private void OnDisable() => Unsubscribe();
23
- private void OnDestroy() => Unsubscribe();
23
+ private void OnEnable() => Subscribe();
24
+ private void OnDisable() => Unsubscribe();
25
+ private void OnDestroy() => Unsubscribe();
24
26
 
25
- private void Subscribe()
26
- {
27
- foreach (var so in listOfPingableObjects)
27
+ private void Subscribe()
28
28
  {
29
- Debug.Log($"registering events for channel: {so.name}");
30
- so.OnEventRaised += RegisterSO;
31
- so.OnEventRemove += RemoveSOFromLists;
29
+ foreach (var so in listOfPingableObjects)
30
+ {
31
+ Debug.Log($"registering events for channel: {so.name}");
32
+ so.OnEventRaised += RegisterSO;
33
+ so.OnEventRemove += RemoveSOFromLists;
34
+ }
35
+ RefreshPingableObjects.RaiseEvent();
32
36
  }
33
- RefreshPingableObjects.RaiseEvent();
34
- }
35
37
 
36
- private void Unsubscribe()
37
- {
38
- foreach (var so in listOfPingableObjects)
38
+ private void Unsubscribe()
39
39
  {
40
- Debug.Log($"unregistering events for channel: {so.name}");
41
- so.OnEventRaised -= null;
42
- so.OnEventRemove -= null;
40
+ foreach (var so in listOfPingableObjects)
41
+ {
42
+ Debug.Log($"unregistering events for channel: {so.name}");
43
+ so.OnEventRaised -= null;
44
+ so.OnEventRemove -= null;
45
+ }
46
+ genericDictionary.Clear();
47
+ genericDictionary.TrimExcess();
43
48
  }
44
- genericDictionary.Clear();
45
- genericDictionary.TrimExcess();
46
- }
47
49
 
48
- private void RegisterSO(string id, ScriptableObject so)
49
- {
50
- UpdateLists(id, so);
51
- }
50
+ private void RegisterSO(string id, ScriptableObject so)
51
+ {
52
+ UpdateLists(id, so);
53
+ }
52
54
 
53
- private void UpdateLists(string id, ScriptableObject so)
54
- {
55
- if (so is not ScriptableObjectEventChannelSO mySo) return;
56
- var type = mySo.type;
57
- if(genericDictionary.ContainsKey(type))
55
+ private void UpdateLists(string id, ScriptableObject so)
58
56
  {
59
- if (!genericDictionary[type].ContainsKey(id))
57
+ if (so is not ScriptableObjectEventChannelSO mySo) return;
58
+ var type = mySo.type;
59
+ if(genericDictionary.ContainsKey(type))
60
60
  {
61
- if(isDebug) Debug.Log($"adding [id: {id}] to the list of type {so.name}");
62
- genericDictionary[type].Add(id, mySo);
61
+ if (!genericDictionary[type].ContainsKey(id))
62
+ {
63
+ if(isDebug) Debug.Log($"adding [id: {id}] to the list of type {so.name}");
64
+ genericDictionary[type].Add(id, mySo);
65
+ }
66
+ }
67
+ else
68
+ {
69
+ if(isDebug) Debug.Log($"new type detected, adding a list of type {so.name} and adding [id: {id}] to it");
70
+ genericDictionary.Add(type, new Dictionary<string, Object>(){{id, mySo}});
63
71
  }
64
72
  }
65
- else
73
+
74
+ private void RemoveSOFromLists(string id, ScriptableObject so)
66
75
  {
67
- if(isDebug) Debug.Log($"new type detected, adding a list of type {so.name} and adding [id: {id}] to it");
68
- genericDictionary.Add(type, new Dictionary<string, Object>(){{id, mySo}});
76
+ if (so is not ScriptableObjectEventChannelSO mySo) return;
77
+ var type = mySo.type;
78
+ if (!genericDictionary.ContainsKey(type)) return;
79
+ if (!genericDictionary[type].ContainsKey(id)) return;
80
+ if(isDebug) Debug.Log($"removing [id: {id}] to the list of type {so.name}");
81
+ genericDictionary[type].Remove(id);
69
82
  }
70
83
  }
71
84
 
72
- private void RemoveSOFromLists(string id, ScriptableObject so)
73
- {
74
- if (so is not ScriptableObjectEventChannelSO mySo) return;
75
- var type = mySo.type;
76
- if (!genericDictionary.ContainsKey(type)) return;
77
- if (!genericDictionary[type].ContainsKey(id)) return;
78
- if(isDebug) Debug.Log($"removing [id: {id}] to the list of type {so.name}");
79
- genericDictionary[type].Remove(id);
80
- }
81
85
  }
@@ -1,8 +1,8 @@
1
1
  using UnityEngine;
2
2
  using UnityEngine.Events;
3
3
 
4
- namespace jeanf.EventSystem
5
- {
4
+ namespace jeanf.EventSystem
5
+ {
6
6
  [CreateAssetMenu(menuName = "Events/Teleport Event Channel")]
7
7
  public class TeleportEventChannelSO : DescriptionBaseSO
8
8
  {
@@ -0,0 +1,16 @@
1
+ using UnityEngine;
2
+ using UnityEngine.Events;
3
+
4
+ namespace jeanf.EventSystem
5
+ {
6
+ [CreateAssetMenu(menuName = "Events/Transform Event Channel")]
7
+ public class TransformEventChannelSO : DescriptionBaseSO
8
+ {
9
+ public UnityAction<Transform> OnEventRaised;
10
+
11
+ public void RaiseEvent(Transform value)
12
+ {
13
+ OnEventRaised?.Invoke(value);
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: ad082b8ba1f184e40b683b8289db4f24
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,19 +1,22 @@
1
- using jeanf.EventSystem;
2
1
  using UnityEngine;
3
2
 
4
- public class BoolEventSender : MonoBehaviour, IDebugBehaviour
3
+ namespace jeanf.EventSystem
5
4
  {
6
- public bool isDebug
7
- {
8
- get => _isDebug;
9
- set => _isDebug = value;
10
- }
11
- [SerializeField] private bool _isDebug = false;
5
+ public class BoolEventSender : MonoBehaviour, IDebugBehaviour
6
+ {
7
+ public bool isDebug
8
+ {
9
+ get => _isDebug;
10
+ set => _isDebug = value;
11
+ }
12
+ [SerializeField] private bool _isDebug = false;
12
13
 
13
- [field: Header("Broadcasting on:")] public BoolEventChannelSO boolMessageChannel;
14
+ [field: Header("Broadcasting on:")] public BoolEventChannelSO boolMessageChannel;
14
15
 
15
- public void SendBool(bool value)
16
- {
17
- boolMessageChannel.RaiseEvent(value);
16
+ public void SendBool(bool value)
17
+ {
18
+ boolMessageChannel.RaiseEvent(value);
19
+ }
18
20
  }
19
21
  }
22
+
@@ -1,19 +1,22 @@
1
1
  using jeanf.EventSystem;
2
2
  using UnityEngine;
3
3
 
4
- public class FloatEventSender : MonoBehaviour, IDebugBehaviour
4
+ namespace jeanf.EventSystem
5
5
  {
6
- public bool isDebug
7
- {
8
- get => _isDebug;
9
- set => _isDebug = value;
10
- }
11
- [SerializeField] private bool _isDebug = false;
6
+ public class FloatEventSender : MonoBehaviour, IDebugBehaviour
7
+ {
8
+ public bool isDebug
9
+ {
10
+ get => _isDebug;
11
+ set => _isDebug = value;
12
+ }
13
+ [SerializeField] private bool _isDebug = false;
12
14
 
13
- [field: Header("Broadcasting on:")] public FloatEventChannelSO floatMessageChannel;
15
+ [field: Header("Broadcasting on:")] public FloatEventChannelSO floatMessageChannel;
14
16
 
15
- public void SendFloat(float value)
16
- {
17
- floatMessageChannel.RaiseEvent(value);
17
+ public void SendFloat(float value)
18
+ {
19
+ floatMessageChannel.RaiseEvent(value);
20
+ }
18
21
  }
19
- }
22
+ }
@@ -1,8 +1,11 @@
1
1
  using jeanf.EventSystem;
2
2
  using UnityEngine;
3
3
 
4
- public interface IScriptableObjectEventSender
4
+ namespace jeanf.EventSystem
5
5
  {
6
- ScriptableObjectEventChannelSO channel { get; set; }
7
- void AddScriptableObjectToList(string id, ScriptableObject value);
8
- }
6
+ public interface IScriptableObjectEventSender
7
+ {
8
+ ScriptableObjectEventChannelSO channel { get; set; }
9
+ void AddScriptableObjectToList(string id, ScriptableObject value);
10
+ }
11
+ }
@@ -1,19 +1,22 @@
1
1
  using jeanf.EventSystem;
2
2
  using UnityEngine;
3
3
 
4
- public class IntEventSender : MonoBehaviour, IDebugBehaviour
4
+ namespace jeanf.EventSystem
5
5
  {
6
- public bool isDebug
7
- {
8
- get => _isDebug;
9
- set => _isDebug = value;
10
- }
11
- [SerializeField] private bool _isDebug = false;
6
+ public class IntEventSender : MonoBehaviour, IDebugBehaviour
7
+ {
8
+ public bool isDebug
9
+ {
10
+ get => _isDebug;
11
+ set => _isDebug = value;
12
+ }
13
+ [SerializeField] private bool _isDebug = false;
12
14
 
13
- [field: Header("Broadcasting on:")] public IntEventChannelSO intMessageChannel;
15
+ [field: Header("Broadcasting on:")] public IntEventChannelSO intMessageChannel;
14
16
 
15
- public void SendInt(int value)
16
- {
17
- intMessageChannel.RaiseEvent(value);
17
+ public void SendInt(int value)
18
+ {
19
+ intMessageChannel.RaiseEvent(value);
20
+ }
18
21
  }
19
- }
22
+ }
@@ -1,19 +1,22 @@
1
- using jeanf.EventSystem;
2
1
  using UnityEngine;
3
2
 
4
- public class ScriptableObjectEventSender : MonoBehaviour, IDebugBehaviour
3
+ namespace jeanf.EventSystem
5
4
  {
6
- public bool isDebug
7
- {
8
- get => _isDebug;
9
- set => _isDebug = value;
10
- }
11
- [SerializeField] private bool _isDebug = false;
5
+ public class ScriptableObjectEventSender : MonoBehaviour, IDebugBehaviour
6
+ {
7
+ public bool isDebug
8
+ {
9
+ get => _isDebug;
10
+ set => _isDebug = value;
11
+ }
12
+ [SerializeField] private bool _isDebug = false;
12
13
 
13
- [field: Header("Broadcasting on:")] public ScriptableObjectEventChannelSO scriptableObjectMessageChannel;
14
+ [field: Header("Broadcasting on:")] public ScriptableObjectEventChannelSO scriptableObjectMessageChannel;
14
15
 
15
- public void SendScriptableObject(string id, ScriptableObject value)
16
- {
17
- scriptableObjectMessageChannel.RaiseEvent(id, value);
16
+ public void SendScriptableObject(string id, ScriptableObject value)
17
+ {
18
+ scriptableObjectMessageChannel.RaiseEvent(id, value);
19
+ }
18
20
  }
19
21
  }
22
+
@@ -0,0 +1,44 @@
1
+ using System;
2
+ using UnityEngine;
3
+ using UnityEngine.Serialization;
4
+
5
+ namespace jeanf.EventSystem
6
+ {
7
+ public class TransformEventSender : MonoBehaviour, IDebugBehaviour
8
+ {
9
+ public bool isDebug
10
+ {
11
+ get => _isDebug;
12
+ set => _isDebug = value;
13
+ }
14
+ [SerializeField] private bool _isDebug = false;
15
+ [SerializeField] private bool _sendTransfromOnAwake;
16
+ [SerializeField] private bool _sendCustomTransform;
17
+ [DrawIf("_sendCustomTransform", true, ComparisonType.Equals)]
18
+ [SerializeField] private Transform _transform;
19
+
20
+ [field: Header("Broadcasting on:")] public TransformEventChannelSO transformMessageChannel;
21
+
22
+ public void SendTransform(Transform value)
23
+ {
24
+ transformMessageChannel.RaiseEvent(value);
25
+ }
26
+
27
+ public void SendCustomTransform()
28
+ {
29
+ SendTransform(_transform);
30
+ }
31
+
32
+ private void Awake()
33
+ {
34
+ if(!_sendTransfromOnAwake) return;
35
+
36
+ if(!_sendCustomTransform)SendTransform(this.gameObject.transform);
37
+ else
38
+ {
39
+ SendTransform(_transform);
40
+ }
41
+ }
42
+ }
43
+ }
44
+
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: f46adcd09ab803f46acaba1ebdc5654f
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,27 +1,28 @@
1
- using System;
2
- using jeanf.EventSystem;
3
1
  using UnityEngine;
4
2
 
5
- public class VoidEventSender : MonoBehaviour, IDebugBehaviour
3
+ namespace jeanf.EventSystem
6
4
  {
7
- public bool isDebug
8
- {
9
- get => _isDebug;
10
- set => _isDebug = value;
11
- }
12
- [SerializeField] private bool _isDebug = false;
5
+ public class VoidEventSender : MonoBehaviour, IDebugBehaviour
6
+ {
7
+ public bool isDebug
8
+ {
9
+ get => _isDebug;
10
+ set => _isDebug = value;
11
+ }
12
+ [SerializeField] private bool _isDebug = false;
13
13
 
14
- [field: Header("Broadcasting on:")] public VoidEventChannelSO voidMessageChannel;
14
+ [field: Header("Broadcasting on:")] public VoidEventChannelSO voidMessageChannel;
15
15
 
16
- [SerializeField] private bool sendEventOnAwake = true;
16
+ [SerializeField] private bool sendEventOnAwake = true;
17
17
 
18
- private void Awake()
19
- {
20
- if(sendEventOnAwake) SendVoidEvent();
21
- }
18
+ private void Awake()
19
+ {
20
+ if(sendEventOnAwake) SendVoidEvent();
21
+ }
22
22
 
23
- public void SendVoidEvent()
24
- {
25
- voidMessageChannel.RaiseEvent();
23
+ public void SendVoidEvent()
24
+ {
25
+ voidMessageChannel.RaiseEvent();
26
+ }
26
27
  }
27
- }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name":"fr.jeanf.eventsystem",
3
- "version":"0.1.69",
3
+ "version":"0.1.71",
4
4
  "displayName":"Event System",
5
5
  "description":"This package contains a basic Event System based on Scriptable Objects as communication medium",
6
6
  "unity": "2021.3",