Darkhitori

vMeleeAttackObject/OnHit

Jan 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Invector;
  6.  
  7. namespace HutongGames.PlayMaker.Actions
  8. {
  9.     [ActionCategory("Invector/vMeleeAttackObject")]
  10.     [Tooltip("Call Back of hitboxes ")]
  11.     public class vMAO_OnHit : FsmStateAction
  12.     {
  13.         [RequiredField]
  14.         [CheckForComponent(typeof(vMeleeAttackObject))]
  15.         public FsmOwnerDefault gameObject;
  16.        
  17.         [ObjectType(typeof(vHitBox))]
  18.         public FsmObject hitBox;
  19.        
  20.         [ObjectType(typeof(Collider))]
  21.         public FsmObject other;
  22.        
  23.         public FsmEvent sendEvent;
  24.        
  25.         public FsmBool everyFrame;
  26.  
  27.         vMeleeAttackObject theScript;
  28.  
  29.  
  30.         public override void Reset()
  31.         {
  32.             gameObject = null;
  33.             hitBox = null;
  34.             other = null;
  35.             sendEvent = null;
  36.             everyFrame = true;
  37.         }
  38.        
  39.         public override void OnEnter()
  40.         {
  41.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  42.  
  43.             theScript = go.GetComponent<vMeleeAttackObject>();
  44.  
  45.  
  46.             if (!everyFrame.Value)
  47.             {
  48.                 DoTheMagic();
  49.                 Finish();
  50.             }
  51.  
  52.         }
  53.  
  54.         public override void OnUpdate()
  55.         {
  56.             if (everyFrame.Value)
  57.             {
  58.                 DoTheMagic();
  59.             }
  60.         }
  61.  
  62.         void DoTheMagic()
  63.         {
  64.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  65.             if (go == null)
  66.             {
  67.                 return;
  68.             }
  69.             var vHit = hitBox.Value as vHitBox;
  70.             if (vHit == null)
  71.             {
  72.                 return;
  73.             }
  74.             var vOther = other.Value as Collider;
  75.             if (vOther == null)
  76.             {
  77.                 return;
  78.             }
  79.            
  80.             theScript.OnHit(vHit, vOther);
  81.             if(sendEvent == null)
  82.             {
  83.                 return;
  84.             }
  85.             else
  86.             {
  87.                 Fsm.Event(sendEvent);
  88.             }
  89.         }
  90.  
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment