|
Post by pixelknight on Jun 13, 2016 18:12:42 GMT
Hi all,
I'm trying to figure out how to use the custom events on killables. I have coregamekit and masteraudio and can't get it working as I'd expect.
I've created a custom event in LevelWaveSettings, set it to Always send to receivers and valid receivers = all.
Then in my prefab, I have a killable script and in the "Death prefab and settings event" I have "Death Cust. Event" ticked and selected my custom event defined above.
However, I cannot for the life of me figure out how do I listen for this event? I've setup a class with a despawner method in there like so
public class CListenTest : KillableListener
{
public override void Despawning(TriggeredSpawner.EventType eType)
{
Debug.Log("DESPAWN");
base.Despawning(eType);
// your code here.
}
}
But I never see that being hit.
Also I've tried implementing ICgkEventReceiver, I get an error in the console when I try this saying
GameObject (named 'Player') references runtime script in scene file. Fixing!
And then the script is disabled.
Can someone point me in the way of some documentation on how to use this feature please?
Thanks in advance
// Carl
|
|
|
Post by pixelknight on Jun 13, 2016 18:43:13 GMT
OK silly me, i'd removed the inheritance from monobehaviour so that gets rid of the runtime script error, but still not getting any events
|
|
|
Post by DarkTonic Dev on Jun 13, 2016 19:14:57 GMT
Send over your class that is implementing ICGKCustomEventListener. Probably will be easy to spot the problem. Note that KillableListener (you are subclassing above) has nothing to do with Custom Events.
Triggered spawners can respond to Custom Events without you writing any code also.
|
|
|
Post by pixelknight on Jun 13, 2016 19:20:05 GMT
Even a simple class like this, attached to a prefab which I do spawn using coregamekit doesn't respond
using UnityEngine;
using System.Collections;
using DarkTonic.CoreGameKit;
public class CEventListen : MonoBehaviour, ICgkEventReceiver
{
public void CheckForIllegalCustomEvents()
{
}
public void ReceiveEvent(string customEventName, Vector3 eventOrigin)
{
Debug.Log("Received Event " + customEventName);
if (customEventName == "ZombieDeath")
{
Debug.Log("W00T Zombie death");
}
}
public bool SubscribesToEvent(string customEventName)
{
Debug.Log("Subscribe to ? " + customEventName);
return (customEventName == "ZombieDeath");
}
public void RegisterReceiver()
{
}
public void UnregisterReceiver()
{
}
}
|
|
|
Post by DarkTonic Dev on Jun 13, 2016 19:27:52 GMT
That's because you need to add code to RegisterReceiver (and unregister too). You can copy what TriggeredSpawner does for those.
|
|
|
Post by pixelknight on Jun 13, 2016 19:46:28 GMT
Thank you for the prompt reply, but I still can't get it working, I changed both reg + unreg to
public virtual void RegisterReceiver()
{
LevelSettings.AddCustomEventReceiver(this, this.transform);
}
public virtual void UnregisterReceiver()
{
LevelSettings.RemoveCustomEventReceiver(this);
}
But still nothing, at runtime, it still shows 0 listeners on the inspector.
|
|
|
Post by DarkTonic Dev on Jun 13, 2016 23:21:31 GMT
Right, the final piece is you have to add code to call Register and Unregister, like this:
void OnEnable() { RegisterReceiver (); }
void OnDisable() { UnregisterReceiver(); }
As TriggeredSpawner does.
|
|
|
Post by pixelknight on Jun 14, 2016 17:27:13 GMT
omg can't believe I'd missed that! Thank you so much, yep works fine now Tonight i'm integrating master audio and getting rid of all my old audio code so expect plenty of n00b posts about that next
|
|
|
Post by DarkTonic Dev on Jun 14, 2016 18:43:46 GMT
Haha awesome. I look forward to helping you out when you need it.
|
|