fr.jeanf.eventsystem 0.1.67 → 0.1.69

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.
Files changed (23) hide show
  1. package/Runtime/Listeners/IScriptableObjectEventListener.cs +25 -0
  2. package/Runtime/{SenderInterfaces/DateTimeEventSender.cs.meta → Listeners/IScriptableObjectEventListener.cs.meta} +1 -1
  3. package/Runtime/Listeners/{DateTimeEventListener.cs → ScriptableObjectEventListener.cs} +6 -7
  4. package/Runtime/Listeners/{DateTimeEventListener.cs.meta → ScriptableObjectEventListener.cs.meta} +1 -1
  5. package/Runtime/PingSystem/PingableScriptableObject.cs +67 -0
  6. package/Runtime/{ScriptableObjects/DateTimeEventChannelSO.cs.meta → PingSystem/PingableScriptableObject.cs.meta} +1 -1
  7. package/Runtime/PingSystem/ScriptableObjectManager.cs +81 -0
  8. package/Runtime/PingSystem/ScriptableObjectManager.cs.meta +11 -0
  9. package/Runtime/PingSystem.meta +8 -0
  10. package/Runtime/ScriptableObjects/ScriptableObjectEventChannelSO.cs +26 -0
  11. package/Runtime/ScriptableObjects/ScriptableObjectEventChannelSO.cs.meta +11 -0
  12. package/Runtime/SenderInterfaces/IScriptableObjectEventSender.cs +8 -0
  13. package/Runtime/SenderInterfaces/IScriptableObjectEventSender.cs.meta +11 -0
  14. package/Runtime/SenderInterfaces/ScriptableObjectEventSender.cs +19 -0
  15. package/Runtime/SenderInterfaces/ScriptableObjectEventSender.cs.meta +11 -0
  16. package/Runtime/jeanf.eventSystem.asmdef +3 -1
  17. package/Samples/PlayerChannels/RefreshPingableObjects 1.asset +16 -0
  18. package/Samples/PlayerChannels/RefreshPingableObjects 1.asset.meta +8 -0
  19. package/Samples/PlayerChannels/RefreshPingableObjects.asset +16 -0
  20. package/Samples/PlayerChannels/RefreshPingableObjects.asset.meta +8 -0
  21. package/package.json +2 -2
  22. package/Runtime/ScriptableObjects/DateTimeEventChannelSO.cs +0 -17
  23. package/Runtime/SenderInterfaces/DateTimeEventSender.cs +0 -20
@@ -0,0 +1,25 @@
1
+ using UnityEngine;
2
+
3
+ namespace jeanf.EventSystem
4
+ {
5
+ public interface IScriptableObjectEventListener
6
+ {
7
+ public ScriptableObjectEventChannelSO channel { get; set; }
8
+ public ScriptableObjectEvent OnEventRaised { get; set; }
9
+
10
+ private void OnEnable()
11
+ {
12
+ if (channel != null) channel.OnEventRaised += Respond;
13
+ }
14
+
15
+ private void OnDisable()
16
+ {
17
+ if (channel != null) channel.OnEventRaised -= Respond;
18
+ }
19
+
20
+ private void Respond(string id, ScriptableObject value)
21
+ {
22
+ OnEventRaised?.Invoke(value);
23
+ }
24
+ }
25
+ }
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 0a31a7a249641724797e1e2e4fb0499b
2
+ guid: 97390cba28bf774438ae731e97fe1128
3
3
  MonoImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2
@@ -1,5 +1,4 @@
1
- using System;
2
- using UnityEngine;
1
+ using UnityEngine;
3
2
  using UnityEngine.Events;
4
3
 
5
4
  /// <summary>
@@ -8,7 +7,7 @@ using UnityEngine.Events;
8
7
  namespace jeanf.EventSystem
9
8
  {
10
9
  [System.Serializable]
11
- public class DateTimeEvent : UnityEvent<DateTime>
10
+ public class ScriptableObjectEvent : UnityEvent<ScriptableObject>
12
11
  {
13
12
 
14
13
  }
@@ -16,7 +15,7 @@ namespace jeanf.EventSystem
16
15
  /// <summary>
17
16
  /// A flexible handler for int events in the form of a MonoBehaviour. Responses can be connected directly from the Unity Inspector.
18
17
  /// </summary>
19
- public class DateTimeEventListener : MonoBehaviour, IDebugBehaviour
18
+ public class ScriptableObjectEventListener : MonoBehaviour, IDebugBehaviour
20
19
  {
21
20
  public bool isDebug
22
21
  {
@@ -25,9 +24,9 @@ namespace jeanf.EventSystem
25
24
  }
26
25
  [SerializeField] private bool _isDebug = false;
27
26
 
28
- [SerializeField] private DateTimeEventChannelSO _channel = default;
27
+ [SerializeField] private ScriptableObjectEventChannelSO _channel = default;
29
28
 
30
- public DateTimeEvent OnEventRaised;
29
+ public ScriptableObjectEvent OnEventRaised;
31
30
 
32
31
  private void OnEnable()
33
32
  {
@@ -41,7 +40,7 @@ namespace jeanf.EventSystem
41
40
  _channel.OnEventRaised -= Respond;
42
41
  }
43
42
 
44
- private void Respond(DateTime value)
43
+ private void Respond(string id, ScriptableObject value)
45
44
  {
46
45
  OnEventRaised?.Invoke(value);
47
46
  if(isDebug) Debug.Log($" bool event raised: {value}");
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 31e074f6ae236be418967598416b8727
2
+ guid: fb20777bcb7493246bce5fcaaea49b3f
3
3
  MonoImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2
@@ -0,0 +1,67 @@
1
+ using System;
2
+ using System.Collections;
3
+ using jeanf.EventSystem;
4
+ using UnityEngine;
5
+
6
+ public class PingableScriptableObject : MonoBehaviour, IScriptableObjectEventSender, IScriptableObjectEventListener, IDebugBehaviour
7
+ {
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()
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);
66
+ }
67
+ }
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: ba97a5c1597b7154ba7d47d2de2b0356
2
+ guid: 1eb27c0143f328948a8d8f74efa7e6f7
3
3
  MonoImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2
@@ -0,0 +1,81 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using jeanf.EventSystem;
4
+ using UnityEngine;
5
+ using Object = UnityEngine.Object;
6
+
7
+ public class ScriptableObjectManager : MonoBehaviour, IDebugBehaviour
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>();
18
+
19
+ private Dictionary<Object, Dictionary<string, Object>> genericDictionary = new Dictionary<Object, Dictionary<string, Object>>();
20
+
21
+ private void OnEnable() => Subscribe();
22
+ private void OnDisable() => Unsubscribe();
23
+ private void OnDestroy() => Unsubscribe();
24
+
25
+ private void Subscribe()
26
+ {
27
+ foreach (var so in listOfPingableObjects)
28
+ {
29
+ Debug.Log($"registering events for channel: {so.name}");
30
+ so.OnEventRaised += RegisterSO;
31
+ so.OnEventRemove += RemoveSOFromLists;
32
+ }
33
+ RefreshPingableObjects.RaiseEvent();
34
+ }
35
+
36
+ private void Unsubscribe()
37
+ {
38
+ foreach (var so in listOfPingableObjects)
39
+ {
40
+ Debug.Log($"unregistering events for channel: {so.name}");
41
+ so.OnEventRaised -= null;
42
+ so.OnEventRemove -= null;
43
+ }
44
+ genericDictionary.Clear();
45
+ genericDictionary.TrimExcess();
46
+ }
47
+
48
+ private void RegisterSO(string id, ScriptableObject so)
49
+ {
50
+ UpdateLists(id, so);
51
+ }
52
+
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))
58
+ {
59
+ if (!genericDictionary[type].ContainsKey(id))
60
+ {
61
+ if(isDebug) Debug.Log($"adding [id: {id}] to the list of type {so.name}");
62
+ genericDictionary[type].Add(id, mySo);
63
+ }
64
+ }
65
+ else
66
+ {
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}});
69
+ }
70
+ }
71
+
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
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 7788af4eb8b4bc64fa8ef942656783ce
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 3a1485ddb7699024e8bbaa6e14156380
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,26 @@
1
+ using System;
2
+ using UnityEngine;
3
+ using UnityEngine.Events;
4
+ using Object = UnityEngine.Object;
5
+
6
+ namespace jeanf.EventSystem
7
+ {
8
+ [CreateAssetMenu(menuName = "Events/ScriptableObject Event Channel")]
9
+ public class ScriptableObjectEventChannelSO : DescriptionBaseSO
10
+ {
11
+ public UnityAction<string, ScriptableObject> OnEventRaised;
12
+ public UnityAction<string, ScriptableObject> OnEventRemove;
13
+ public Object type;
14
+ [HideInInspector] public string id;
15
+
16
+ public void RaiseEvent(string id, ScriptableObject value)
17
+ {
18
+ OnEventRaised?.Invoke(id, value);
19
+ }
20
+
21
+ public void UnsubscribeEvent(string id, ScriptableObject value)
22
+ {
23
+ OnEventRemove?.Invoke(id, value);
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: aa3e1a0bacfe3bf43a5357901d7b548d
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ using jeanf.EventSystem;
2
+ using UnityEngine;
3
+
4
+ public interface IScriptableObjectEventSender
5
+ {
6
+ ScriptableObjectEventChannelSO channel { get; set; }
7
+ void AddScriptableObjectToList(string id, ScriptableObject value);
8
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 5adbcdbf352259246b506f4e61b4d94c
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,19 @@
1
+ using jeanf.EventSystem;
2
+ using UnityEngine;
3
+
4
+ public class ScriptableObjectEventSender : MonoBehaviour, IDebugBehaviour
5
+ {
6
+ public bool isDebug
7
+ {
8
+ get => _isDebug;
9
+ set => _isDebug = value;
10
+ }
11
+ [SerializeField] private bool _isDebug = false;
12
+
13
+ [field: Header("Broadcasting on:")] public ScriptableObjectEventChannelSO scriptableObjectMessageChannel;
14
+
15
+ public void SendScriptableObject(string id, ScriptableObject value)
16
+ {
17
+ scriptableObjectMessageChannel.RaiseEvent(id, value);
18
+ }
19
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 72fcfe0b452f6e748a560af8978e794b
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "jeanf.eventsystem",
3
3
  "rootNamespace": "",
4
- "references": [],
4
+ "references": [
5
+ "GUID:e8958e6939af7314a97769de4be4ce25"
6
+ ],
5
7
  "includePlatforms": [],
6
8
  "excludePlatforms": [],
7
9
  "allowUnsafeCode": false,
@@ -0,0 +1,16 @@
1
+ %YAML 1.1
2
+ %TAG !u! tag:unity3d.com,2011:
3
+ --- !u!114 &11400000
4
+ MonoBehaviour:
5
+ m_ObjectHideFlags: 0
6
+ m_CorrespondingSourceObject: {fileID: 0}
7
+ m_PrefabInstance: {fileID: 0}
8
+ m_PrefabAsset: {fileID: 0}
9
+ m_GameObject: {fileID: 0}
10
+ m_Enabled: 1
11
+ m_EditorHideFlags: 0
12
+ m_Script: {fileID: 11500000, guid: d84ad29ba75bd634eb5eda8abf406faf, type: 3}
13
+ m_Name: RefreshPingableObjects 1
14
+ m_EditorClassIdentifier:
15
+ _guid:
16
+ description:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 9aa4febc867c7144b8a17028b2aa9a27
3
+ NativeFormatImporter:
4
+ externalObjects: {}
5
+ mainObjectFileID: 11400000
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,16 @@
1
+ %YAML 1.1
2
+ %TAG !u! tag:unity3d.com,2011:
3
+ --- !u!114 &11400000
4
+ MonoBehaviour:
5
+ m_ObjectHideFlags: 0
6
+ m_CorrespondingSourceObject: {fileID: 0}
7
+ m_PrefabInstance: {fileID: 0}
8
+ m_PrefabAsset: {fileID: 0}
9
+ m_GameObject: {fileID: 0}
10
+ m_Enabled: 1
11
+ m_EditorHideFlags: 0
12
+ m_Script: {fileID: 11500000, guid: d84ad29ba75bd634eb5eda8abf406faf, type: 3}
13
+ m_Name: RefreshPingableObjects
14
+ m_EditorClassIdentifier:
15
+ _guid:
16
+ description:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 509eb5f15058fdf458b9b6a237c5c05f
3
+ NativeFormatImporter:
4
+ externalObjects: {}
5
+ mainObjectFileID: 11400000
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name":"fr.jeanf.eventsystem",
3
- "version":"0.1.67",
3
+ "version":"0.1.69",
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",
@@ -14,7 +14,7 @@
14
14
  "url":"https://jeanfrancoisrobin.art"
15
15
  },
16
16
  "dependencies": {
17
- "fr.jeanf.propertydrawer": "1.0.0"
17
+ "fr.jeanf.propertydrawer": "1.0.5"
18
18
  },
19
19
  "samples": [
20
20
  {
@@ -1,17 +0,0 @@
1
- using System;
2
- using UnityEngine;
3
- using UnityEngine.Events;
4
-
5
- namespace jeanf.EventSystem
6
- {
7
- [CreateAssetMenu(menuName = "Events/DateTime Event Channel")]
8
- public class DateTimeEventChannelSO : DescriptionBaseSO
9
- {
10
- public UnityAction<DateTime> OnEventRaised;
11
-
12
- public void RaiseEvent(DateTime value)
13
- {
14
- OnEventRaised?.Invoke(value);
15
- }
16
- }
17
- }
@@ -1,20 +0,0 @@
1
- using System;
2
- using jeanf.EventSystem;
3
- using UnityEngine;
4
-
5
- public class DateTimeEventSender : MonoBehaviour, IDebugBehaviour
6
- {
7
- public bool isDebug
8
- {
9
- get => _isDebug;
10
- set => _isDebug = value;
11
- }
12
- [SerializeField] private bool _isDebug = false;
13
-
14
- [field: Header("Broadcasting on:")] public DateTimeEventChannelSO boolMessageChannel;
15
-
16
- public void SendBool(DateTime value)
17
- {
18
- boolMessageChannel.RaiseEvent(value);
19
- }
20
- }