Darkhitori

vItemManager/GetItem

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