fr.jeanf.eventsystem 0.0.1
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/.github/workflows/publish.yml +23 -0
- package/.github/workflows.meta +8 -0
- package/README.md +8 -0
- package/README.md.meta +7 -0
- package/Runtime/BaseClasses/DescriptionBaseSO.cs +12 -0
- package/Runtime/BaseClasses/DescriptionBaseSO.cs.meta +11 -0
- package/Runtime/BaseClasses/SerializableScriptableObject.cs +22 -0
- package/Runtime/BaseClasses/SerializableScriptableObject.cs.meta +11 -0
- package/Runtime/BaseClasses.meta +8 -0
- package/Runtime/Listeners/IntEventListener.cs +42 -0
- package/Runtime/Listeners/IntEventListener.cs.meta +11 -0
- package/Runtime/Listeners/StringEventListener.cs +41 -0
- package/Runtime/Listeners/StringEventListener.cs.meta +11 -0
- package/Runtime/Listeners/VoidEventListener.cs +33 -0
- package/Runtime/Listeners/VoidEventListener.cs.meta +11 -0
- package/Runtime/Listeners.meta +8 -0
- package/Runtime/ScriptableObjects/IntEventChannelSO.cs +21 -0
- package/Runtime/ScriptableObjects/IntEventChannelSO.cs.meta +11 -0
- package/Runtime/ScriptableObjects/StringEventChannelSO.cs +20 -0
- package/Runtime/ScriptableObjects/StringEventChannelSO.cs.meta +11 -0
- package/Runtime/ScriptableObjects/VoidEventChannelSO.cs +17 -0
- package/Runtime/ScriptableObjects/VoidEventChannelSO.cs.meta +11 -0
- package/Runtime/ScriptableObjects.meta +8 -0
- package/Runtime/Senders/EventSender.cs +11 -0
- package/Runtime/Senders/EventSender.cs.meta +11 -0
- package/Runtime/Senders.meta +8 -0
- package/Runtime/jeanf.eventSystem.asmdef +14 -0
- package/Runtime/jeanf.eventSystem.asmdef.meta +7 -0
- package/Runtime.meta +8 -0
- package/Samples/Channels/String Message Channel SO.asset +18 -0
- package/Samples/Channels/String Message Channel SO.asset.meta +8 -0
- package/Samples/Channels.meta +8 -0
- package/Samples.meta +8 -0
- package/package.json +25 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: "🚀 publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
release:
|
|
10
|
+
name: 🚀 publish
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: 📚 checkout
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
- name: 🟢 node
|
|
16
|
+
uses: actions/setup-node@v3
|
|
17
|
+
with:
|
|
18
|
+
node-version: 16
|
|
19
|
+
registry-url: https://registry.npmjs.org
|
|
20
|
+
- name: 🚀 publish
|
|
21
|
+
run: npm publish --access public
|
|
22
|
+
env:
|
|
23
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
|
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
This Event System is using scriptable objects as communication medium to avoid code-depedency when using events.
|
|
2
|
+
|
|
3
|
+
In order to find this package in unity's package manager make sure to add the scoped registery to unity's ProjectSettings:
|
|
4
|
+
- click new scopedRegisteries (+) in ProjectSettings/Package manager
|
|
5
|
+
- set the following parameters:
|
|
6
|
+
- name: jeanf
|
|
7
|
+
- url: https://registry.npmjs.com
|
|
8
|
+
- scope fr.jeanf
|
package/README.md.meta
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
|
|
3
|
+
namespace jeanf.EventSystem
|
|
4
|
+
{
|
|
5
|
+
/// <summary>
|
|
6
|
+
/// Base class for ScriptableObjects that need a public description field.
|
|
7
|
+
/// </summary>
|
|
8
|
+
public class DescriptionBaseSO : SerializableScriptableObject
|
|
9
|
+
{
|
|
10
|
+
[TextArea] public string description;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
|
|
3
|
+
#if UNITY_EDITOR
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
namespace jeanf.EventSystem
|
|
8
|
+
{
|
|
9
|
+
public class SerializableScriptableObject : ScriptableObject
|
|
10
|
+
{
|
|
11
|
+
[SerializeField, HideInInspector] private string _guid;
|
|
12
|
+
public string Guid => _guid;
|
|
13
|
+
|
|
14
|
+
#if UNITY_EDITOR
|
|
15
|
+
void OnValidate()
|
|
16
|
+
{
|
|
17
|
+
var path = AssetDatabase.GetAssetPath(this);
|
|
18
|
+
_guid = AssetDatabase.AssetPathToGUID(path);
|
|
19
|
+
}
|
|
20
|
+
#endif
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
|
|
4
|
+
/// <summary>
|
|
5
|
+
/// To use a generic UnityEvent type you must override the generic type.
|
|
6
|
+
/// </summary>
|
|
7
|
+
namespace jeanf.EventSystem
|
|
8
|
+
{
|
|
9
|
+
[System.Serializable]
|
|
10
|
+
public class IntEvent : UnityEvent<int>
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// A flexible handler for int events in the form of a MonoBehaviour. Responses can be connected directly from the Unity Inspector.
|
|
17
|
+
/// </summary>
|
|
18
|
+
public class IntEventListener : MonoBehaviour
|
|
19
|
+
{
|
|
20
|
+
[SerializeField] private IntEventChannelSO _channel = default;
|
|
21
|
+
|
|
22
|
+
public IntEvent OnEventRaised;
|
|
23
|
+
|
|
24
|
+
private void OnEnable()
|
|
25
|
+
{
|
|
26
|
+
if (_channel != null)
|
|
27
|
+
_channel.OnEventRaised += Respond;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private void OnDisable()
|
|
31
|
+
{
|
|
32
|
+
if (_channel != null)
|
|
33
|
+
_channel.OnEventRaised -= Respond;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private void Respond(int value)
|
|
37
|
+
{
|
|
38
|
+
if (OnEventRaised != null)
|
|
39
|
+
OnEventRaised.Invoke(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
|
|
4
|
+
/// <summary>
|
|
5
|
+
/// To use a generic UnityEvent type you must override the generic type.
|
|
6
|
+
/// </summary>
|
|
7
|
+
namespace jeanf.EventSystem
|
|
8
|
+
{
|
|
9
|
+
[System.Serializable]
|
|
10
|
+
public class StringEvent : UnityEvent<string>
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// A flexible handler for int events in the form of a MonoBehaviour. Responses can be connected directly from the Unity Inspector.
|
|
17
|
+
/// </summary>
|
|
18
|
+
public class StringEventListener : MonoBehaviour
|
|
19
|
+
{
|
|
20
|
+
[SerializeField] private StringEventChannelSO _channel = default;
|
|
21
|
+
|
|
22
|
+
public StringEvent OnEventRaised;
|
|
23
|
+
|
|
24
|
+
private void OnEnable()
|
|
25
|
+
{
|
|
26
|
+
if (_channel != null)
|
|
27
|
+
_channel.OnEventRaised += Respond;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private void OnDisable()
|
|
31
|
+
{
|
|
32
|
+
if (_channel != null)
|
|
33
|
+
_channel.OnEventRaised -= Respond;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private void Respond(string value)
|
|
37
|
+
{
|
|
38
|
+
OnEventRaised?.Invoke(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
|
|
4
|
+
/// <summary>
|
|
5
|
+
/// A flexible handler for void events in the form of a MonoBehaviour. Responses can be connected directly from the Unity Inspector.
|
|
6
|
+
/// </summary>namespace jeanf.EventSystemnamespace jeanf.EventSystem
|
|
7
|
+
namespace jeanf.EventSystem
|
|
8
|
+
{
|
|
9
|
+
public class VoidEventListener : MonoBehaviour
|
|
10
|
+
{
|
|
11
|
+
[SerializeField] private VoidEventChannelSO _channel = default;
|
|
12
|
+
|
|
13
|
+
public UnityEvent OnEventRaised;
|
|
14
|
+
|
|
15
|
+
private void OnEnable()
|
|
16
|
+
{
|
|
17
|
+
if (_channel != null)
|
|
18
|
+
_channel.OnEventRaised += Respond;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private void OnDisable()
|
|
22
|
+
{
|
|
23
|
+
if (_channel != null)
|
|
24
|
+
_channel.OnEventRaised -= Respond;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private void Respond()
|
|
28
|
+
{
|
|
29
|
+
if (OnEventRaised != null)
|
|
30
|
+
OnEventRaised.Invoke();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
|
|
4
|
+
/// <summary>
|
|
5
|
+
/// This class is used for Events that have one int argument.
|
|
6
|
+
/// Example: An Achievement unlock event, where the int is the Achievement ID.
|
|
7
|
+
/// </summary>
|
|
8
|
+
namespace jeanf.EventSystem
|
|
9
|
+
{
|
|
10
|
+
[CreateAssetMenu(menuName = "Events/Int Event Channel")]
|
|
11
|
+
public class IntEventChannelSO : DescriptionBaseSO
|
|
12
|
+
{
|
|
13
|
+
public UnityAction<int> OnEventRaised;
|
|
14
|
+
|
|
15
|
+
public void RaiseEvent(int value)
|
|
16
|
+
{
|
|
17
|
+
if (OnEventRaised != null)
|
|
18
|
+
OnEventRaised.Invoke(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
|
|
4
|
+
/// <summary>
|
|
5
|
+
/// This class is used for Events that have one int argument.
|
|
6
|
+
/// Example: An Achievement unlock event, where the int is the Achievement ID.
|
|
7
|
+
/// </summary>
|
|
8
|
+
namespace jeanf.EventSystem
|
|
9
|
+
{
|
|
10
|
+
[CreateAssetMenu(menuName = "Events/String Event Channel")]
|
|
11
|
+
public class StringEventChannelSO : DescriptionBaseSO
|
|
12
|
+
{
|
|
13
|
+
public UnityAction<string> OnEventRaised;
|
|
14
|
+
|
|
15
|
+
public void RaiseEvent(string value)
|
|
16
|
+
{
|
|
17
|
+
OnEventRaised?.Invoke(value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Events;
|
|
3
|
+
|
|
4
|
+
namespace jeanf.EventSystem
|
|
5
|
+
{
|
|
6
|
+
[CreateAssetMenu(menuName = "Events/Void Event Channel")]
|
|
7
|
+
public class VoidEventChannelSO : DescriptionBaseSO
|
|
8
|
+
{
|
|
9
|
+
public UnityAction OnEventRaised;
|
|
10
|
+
|
|
11
|
+
public void RaiseEvent()
|
|
12
|
+
{
|
|
13
|
+
if (OnEventRaised != null)
|
|
14
|
+
OnEventRaised.Invoke();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.Serialization;
|
|
3
|
+
|
|
4
|
+
namespace jeanf.EventSystem
|
|
5
|
+
{
|
|
6
|
+
public class EventSender : MonoBehaviour
|
|
7
|
+
{
|
|
8
|
+
[FormerlySerializedAs("_messageChannel")] [Header("Broadcasting on channels")]
|
|
9
|
+
public StringEventChannelSO _stringMessageChannel;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uvs.events",
|
|
3
|
+
"rootNamespace": "",
|
|
4
|
+
"references": [],
|
|
5
|
+
"includePlatforms": [],
|
|
6
|
+
"excludePlatforms": [],
|
|
7
|
+
"allowUnsafeCode": false,
|
|
8
|
+
"overrideReferences": false,
|
|
9
|
+
"precompiledReferences": [],
|
|
10
|
+
"autoReferenced": true,
|
|
11
|
+
"defineConstraints": [],
|
|
12
|
+
"versionDefines": [],
|
|
13
|
+
"noEngineReferences": false
|
|
14
|
+
}
|
package/Runtime.meta
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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: b842bdeec62cc754093c6a5120ac1107, type: 3}
|
|
13
|
+
m_Name: String Message Channel SO
|
|
14
|
+
m_EditorClassIdentifier:
|
|
15
|
+
_guid: a3f2d4caf87f6994092b3187963f8dc3
|
|
16
|
+
description: 'Basic ipad message
|
|
17
|
+
|
|
18
|
+
'
|
package/Samples.meta
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name":"fr.jeanf.eventsystem",
|
|
3
|
+
"version":"0.0.1",
|
|
4
|
+
"displayName":"Event System",
|
|
5
|
+
"description":"This package contains a basic Event System based on Scriptable Objects as communication medium",
|
|
6
|
+
"unity": "2021.3",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"jeanf",
|
|
9
|
+
"event system"
|
|
10
|
+
],
|
|
11
|
+
"author":{
|
|
12
|
+
"name":"Jean-François Robin",
|
|
13
|
+
"email":"robin.jeanfrancois@gmail.com",
|
|
14
|
+
"url":"https://jeanfrancoisrobin.art"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
},
|
|
18
|
+
"samples": [
|
|
19
|
+
{
|
|
20
|
+
"displayName": "Channels",
|
|
21
|
+
"description": "A set of usefull default channels",
|
|
22
|
+
"path": "Samples/Channels"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|