Guest User

Untitled

a guest
Mar 20th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public class EventExample : MonoBehaviour
  2. {
  3. public delegate void ExampleEventHandler();
  4. public static event ExampleEventHandler OneDayPassed;
  5.  
  6. public static void NextTurn()
  7. {
  8. // do stuff then send event
  9. if (OneDayPassed != null)
  10. OneDayPassed();
  11. }
  12. }
  13.  
  14. public class EntityWatcher: MonoBehaviour
  15. {
  16. void Start()
  17. {
  18. EventExample.OneDayPassed += this.PrepareNextDay;
  19. }
  20.  
  21. public void PrepareNextDay()
  22. {
  23. // Do other stuff that happen after the day is done
  24.  
  25. }
  26. }
  27.  
  28. public UnityEvent whoa;
  29.  
  30. using UnityEngine;
  31. using System.Collections;
  32. using UnityEngine.Events;
  33.  
  34. public class BigScript:MonoBehaviour
  35. {
  36. [Header("Here's a cool event! Drag anything here!")]
  37. public UnityEvent whoa;
  38. }
  39.  
  40. public class BigScript:MonoBehaviour
  41. {
  42. [Header("Here's a cool event! Drag anything here!")]
  43. public UnityEvent whoa;
  44.  
  45. private void YourFunction()
  46. {
  47. whoa.Invoke();
  48. }
  49.  
  50. whoa.AddListener(ScreenMaybeChanged);
  51.  
  52. ...
  53. using UnityEngine.Events;
  54.  
  55. // example, function has one float argument:
  56. // ADD THIS at the top of the file:
  57. [System.Serializable]
  58. public class _UnityEventFloat:UnityEvent<float> {}
  59.  
  60. public class SimpleFingerResize : MonoBehaviour
  61. {
  62. public _UnityEventFloat changedLength;
  63. public _UnityEventFloat changedHeight;
  64.  
  65. ... and then ...
  66.  
  67. void ProcessValues(float v)
  68. {
  69. ....
  70. if (changedLength != null) changedLength.Invoke(1.4455f);
  71. }
  72. }
Add Comment
Please, Sign In to add comment