You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

71 lines
2.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Sends the message to the current target. First, it checks the Actor's methods cache.
  8. /// If the receiving method found in cache, it will be called directly without passing the message to the GameObject.
  9. /// If there's no listener in cache, message will be sent GameObject (and Unity does it VERY slow).
  10. /// </summary>
  11. class ActionSendMessage : ActionInstant
  12. {
  13. protected string message;
  14. protected object param;
  15. protected SendMessageOptions options = SendMessageOptions.DontRequireReceiver;
  16. public ActionSendMessage(string tgtMessage)
  17. : base()
  18. {
  19. message = tgtMessage;
  20. }
  21. public ActionSendMessage(string tgtMessage, object tgtParam)
  22. : base()
  23. {
  24. message = tgtMessage;
  25. param = tgtParam;
  26. }
  27. public ActionSendMessage(string tgtMessage, object tgtParam, SendMessageOptions tgtOptions)
  28. : base()
  29. {
  30. message = tgtMessage;
  31. param = tgtParam;
  32. options = tgtOptions;
  33. }
  34. /// <summary>
  35. /// Returns a copy of the action.
  36. /// </summary>
  37. public override ActionInstant clone()
  38. {
  39. return new ActionSendMessage(message, param, options);
  40. }
  41. /// <summary>
  42. /// Returns the reversed version of the action, if it is possible.
  43. /// </summary>
  44. public override ActionInstant reverse()
  45. {
  46. return new ActionSendMessage(message, param, options);
  47. }
  48. /// <summary>
  49. /// This method is called at the action start.
  50. /// </summary>
  51. public override void start()
  52. {
  53. base.start();
  54. if (param != null)
  55. {
  56. target.ReceiveMessage(message, param, options);
  57. }
  58. else
  59. {
  60. target.ReceiveMessage(message, options);
  61. }
  62. }
  63. }
  64. }