IEnumerator startNotificationTest() { // Setup some notifications Debug.Log("Adding listeners for all three notification types"); Notification typeOne = new Notification(NotificationType.OnOtherStuff, "type one here"); Notification typeTwo = new Notification(NotificationType.OnStuff, "type two here"); SuperNotification typeThree = new SuperNotification(NotificationType.OnSomeEvent, 4.5f, 2); yield return(new WaitForSeconds(1.0f)); // Send off all three notifications Debug.Log("Sending all three notifications"); NotificationCenter.defaultCenter.postNotification(typeOne); NotificationCenter.defaultCenter.postNotification(typeTwo); NotificationCenter.defaultCenter.postNotification(typeThree); yield return(new WaitForSeconds(1.0f)); // Remove ourself as a listener for two of the notifications Debug.Log("Removing 2 of the 3 notification listeners"); NotificationCenter.defaultCenter.removeListener(onReceiveNotificationTypeOne, NotificationType.OnOtherStuff); NotificationCenter.defaultCenter.removeListener(onReceiveNotificationTypeTwo, NotificationType.OnStuff); // Send off all three notifications but we should only get one of them this time Debug.Log("Sending all three notifications"); NotificationCenter.defaultCenter.postNotification(typeOne); NotificationCenter.defaultCenter.postNotification(typeTwo); NotificationCenter.defaultCenter.postNotification(typeThree); yield return(new WaitForSeconds(1.0f)); // Remove ourself as a listener for the last notification Debug.Log("Removing the last notification listener"); NotificationCenter.defaultCenter.removeListener(onReceiveNotificationTypeThree, NotificationType.OnSomeEvent); // Send off all three notifications but we should only get one of them this time Debug.Log("Sending all three notifications"); NotificationCenter.defaultCenter.postNotification(typeOne); NotificationCenter.defaultCenter.postNotification(typeTwo); NotificationCenter.defaultCenter.postNotification(typeThree); }
void onReceiveNotificationTypeThree(Notification note) { SuperNotification superNote = (SuperNotification)note; Debug.Log(string.Format("Received notification typeThree with float: {0}", superNote.varFloat)); }