Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Fungus;
  4.  
  5. [EventHandlerInfo("Custom",
  6.                       "Trigger2D Enter",
  7.                       "Fires when anything hits the target collider, and returns the object that hit")]
  8. [AddComponentMenu("")]
  9. public class Custom_EventHandler_Trigger2D : EventHandler
  10. {
  11.  
  12.     /*
  13.     Raising the event:
  14.     Fungus.FungusManager.Instance.EventDispatcher.Raise(new Custom_EventHandler_Trigger2D.Custom_EventHandlerEvent() { target = targetCollider });
  15.  
  16.      */
  17.  
  18.     public Collider2D target;
  19.     [VariableProperty(typeof(GameObjectVariable))]
  20.     public GameObjectVariable returnObj;
  21.  
  22.  
  23.     public class Custom_EventHandlerEvent
  24.     {
  25.         public Collider2D hitObject;
  26.         public Collider2D source;
  27.     }
  28.  
  29.     protected EventDispatcher eventDispatcher;
  30.  
  31.     protected virtual void OnEnable()
  32.     {
  33.         eventDispatcher = FungusManager.Instance.EventDispatcher;
  34.  
  35.         eventDispatcher.AddListener<Custom_EventHandlerEvent>(OnCustom_EventHandlerEvent);
  36.     }
  37.  
  38.     protected virtual void OnDisable()
  39.     {
  40.         eventDispatcher.RemoveListener<Custom_EventHandlerEvent>(OnCustom_EventHandlerEvent);
  41.  
  42.         eventDispatcher = null;
  43.     }
  44.  
  45.     void OnCustom_EventHandlerEvent(Custom_EventHandlerEvent evt)
  46.     {
  47.         if (target == evt.source)
  48.         {
  49.             if (returnObj != null)
  50.             {
  51.                 returnObj.Value = evt.hitObject.gameObject;
  52.             }
  53.             ExecuteBlock();
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement