Hi there,
I would like to combine ScriptableObject along with UnityEvent and GenericObject usage. My ultimate goal is to create generic event and listener and then use ScriptableObject to create specific events e.g. GameObject, int and etc. and handle these with respective listeners.
Here is the code I have so far:
EventTemplate.cs
```csharp
**using System.Collections.Generic;
using UnityEngine;
public class EventTemplate : ScriptableObject {
private List<ListenerTemplate> listeners = new List<ListenerTemplate>();
public void Raise(T go) {
for (int i = listeners.Count - 1; i >= 0; i--) {
listeners[i].OnEventRaised(go);
}
}
public void RegisterListener(ListenerTemplate<T> listener) {
listeners.Add(listener);
}
public void UnregisterListener(ListenerTemplate<T> listener) {
listeners.Remove(listener);
}
}**
** **ListenerTemplate.cs** **
csharp
**using UnityEngine;
using UnityEngine.Events;
[System.Serializable]
public class ResponseEvent : UnityEvent { }
public class ListenerTemplate : MonoBehaviour {
//[SerializeField]
public EventTemplate gameEvent;
//[SerializeField]
public ResponseEvent<T> response;
private void OnEnable() {
gameEvent.RegisterListener(this);
}
private void OnDisable() {
gameEvent.UnregisterListener(this);
}
public void OnEventRaised(T go) {
response.Invoke(go);
}
}**
** **Now, when I have both generic types, I created one Event and one Listener for
int type.** **These are two files:** **EventInt.cs** **
csharp
**using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = “New Event Template”, menuName = “Stage Management/Event Templates/Event Int”)]
public class EventInt : EventTemplate {
}**
```
and ListenerInt.cs
```csharp
**using UnityEngine;
using UnityEngine.Events;
[System.Serializable]
public class ResponseInt : ResponseEvent { }
public class ListenerInt : ListenerTemplate {
}**
** **then my expectation was, once I add
ListenerInt.csto specific game component via Editor, I will able to access
gameEventand
responsein the same fashion I can access them as if I define UnityEvent for int type.** **However, the reality is that I cannot see / access neither
gameEventnor
response``` via the Editor.