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.
- package/Runtime/Listeners/IScriptableObjectEventListener.cs +25 -0
- package/Runtime/{SenderInterfaces/DateTimeEventSender.cs.meta → Listeners/IScriptableObjectEventListener.cs.meta} +1 -1
- package/Runtime/Listeners/{DateTimeEventListener.cs → ScriptableObjectEventListener.cs} +6 -7
- package/Runtime/Listeners/{DateTimeEventListener.cs.meta → ScriptableObjectEventListener.cs.meta} +1 -1
- package/Runtime/PingSystem/PingableScriptableObject.cs +67 -0
- package/Runtime/{ScriptableObjects/DateTimeEventChannelSO.cs.meta → PingSystem/PingableScriptableObject.cs.meta} +1 -1
- package/Runtime/PingSystem/ScriptableObjectManager.cs +81 -0
- package/Runtime/PingSystem/ScriptableObjectManager.cs.meta +11 -0
- package/Runtime/PingSystem.meta +8 -0
- package/Runtime/ScriptableObjects/ScriptableObjectEventChannelSO.cs +26 -0
- package/Runtime/ScriptableObjects/ScriptableObjectEventChannelSO.cs.meta +11 -0
- package/Runtime/SenderInterfaces/IScriptableObjectEventSender.cs +8 -0
- package/Runtime/SenderInterfaces/IScriptableObjectEventSender.cs.meta +11 -0
- package/Runtime/SenderInterfaces/ScriptableObjectEventSender.cs +19 -0
- package/Runtime/SenderInterfaces/ScriptableObjectEventSender.cs.meta +11 -0
- package/Runtime/jeanf.eventSystem.asmdef +3 -1
- package/Samples/PlayerChannels/RefreshPingableObjects 1.asset +16 -0
- package/Samples/PlayerChannels/RefreshPingableObjects 1.asset.meta +8 -0
- package/Samples/PlayerChannels/RefreshPingableObjects.asset +16 -0
- package/Samples/PlayerChannels/RefreshPingableObjects.asset.meta +8 -0
- package/package.json +2 -2
- package/Runtime/ScriptableObjects/DateTimeEventChannelSO.cs +0 -17
- 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,4 @@
|
|
|
1
|
-
using
|
|
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
|
|
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
|
|
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
|
|
27
|
+
[SerializeField] private ScriptableObjectEventChannelSO _channel = default;
|
|
29
28
|
|
|
30
|
-
public
|
|
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(
|
|
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}");
|
|
@@ -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
|
+
}
|
|
@@ -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,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,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,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,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:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name":"fr.jeanf.eventsystem",
|
|
3
|
-
"version":"0.1.
|
|
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.
|
|
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
|
-
}
|