Advertisement
Darkhitori

CF_condition

Jan 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using MLSpace;
  6.  
  7. namespace HutongGames.PlayMaker.Actions
  8. {
  9.     [ActionCategory("CombatFramework/Trigger")]
  10.     [Tooltip("Early exit conditions. ")]
  11.     public class CF_condition : FsmStateAction
  12.     {
  13.         [RequiredField]
  14.         [CheckForComponent(typeof(Trigger))]
  15.         public FsmOwnerDefault gameObject;
  16.        
  17.         [ObjectType(typeof(TriggerManagement))]
  18.         public FsmObject trigMan;
  19.         [ActionSection("Return")]
  20.         [UIHint(UIHint.FsmBool)]
  21.         public FsmBool m_ConditionPassed;
  22.        
  23.         public FsmBool everyFrame;
  24.  
  25.         Trigger theScript;
  26.  
  27.  
  28.         public override void Reset()
  29.         {
  30.             gameObject = null;
  31.             trigMan = null;
  32.             m_ConditionPassed = false;
  33.             everyFrame = true;
  34.         }
  35.        
  36.         public override void OnEnter()
  37.         {
  38.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  39.  
  40.             theScript = go.GetComponent<Trigger>();
  41.  
  42.  
  43.             if (!everyFrame.Value)
  44.             {
  45.                 DoTheMethod();
  46.                 Finish();
  47.             }
  48.  
  49.         }
  50.  
  51.         public override void OnUpdate()
  52.         {
  53.             if (everyFrame.Value)
  54.             {
  55.                 DoTheMethod();
  56.             }
  57.         }
  58.  
  59.         void DoTheMethod()
  60.         {
  61.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  62.             if (go == null)
  63.             {
  64.                 return;
  65.             }
  66.             var cTrig = trigMan.Value as TriggerManagement;
  67.             if (cTrig == null)
  68.             {
  69.                 return;
  70.             }
  71.  
  72.             m_ConditionPassed.Value = theScript.condition(cTrig);            
  73.         }
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement