Darkhitori

ThirdPersonCamera/ScreenPointToRay

Jan 12th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Invector.CharacterController;
  6.  
  7. namespace HutongGames.PlayMaker.Actions
  8. {
  9.     [ActionCategory("Invector/vThirdPersonCamera")]
  10.     [Tooltip("Convert a point in the screen in a Ray for the world ")]
  11.     public class vTPC_ScreenPointToRay : FsmStateAction
  12.     {
  13.         [RequiredField]
  14.         [CheckForComponent(typeof(vThirdPersonCamera))]
  15.         public FsmOwnerDefault gameObject;
  16.        
  17.         public FsmVector3 point;
  18.        
  19.         [ActionSection("Return Ray")]
  20.         [UIHint(UIHint.FsmVector3)]
  21.         public FsmVector3 origin;
  22.         [UIHint(UIHint.FsmVector3)]
  23.         public FsmVector3 direction;
  24.        
  25.         public FsmBool everyFrame;
  26.  
  27.         vThirdPersonCamera theScript;
  28.        
  29.  
  30.         public override void Reset()
  31.         {
  32.             gameObject = null;
  33.             point = new Vector3(0,0,0);
  34.             origin = new Vector3(0,0,0);
  35.             direction = new Vector3(0,0,0);
  36.             everyFrame = true;
  37.         }
  38.        
  39.         public override void OnEnter()
  40.         {
  41.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  42.  
  43.             theScript = go.GetComponent<vThirdPersonCamera>();
  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.            
  70.            
  71.             origin.Value = theScript.ScreenPointToRay(point.Value).origin;
  72.             direction.Value = theScript.ScreenPointToRay(point.Value).direction;
  73.         }
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment