Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. public class CharacterState : MonoBehaviour
  5. {
  6.     #region State
  7.     public bool IsLocal { get => GetIsLocal(); }
  8.     public bool IsRemote { get => GetIsRemote(); }
  9.     public bool IsAI { get => GetIsAI(); }
  10.  
  11.     public float Radius { get => (float)GetRadius?.Invoke(); }
  12.     public float Height { get => (float)GetHeight?.Invoke(); }
  13.     public Vector3 Center { get => (Vector3)GetCenter?.Invoke(); }
  14.     public Vector3 Velocity { get => (Vector3)GetVelocity?.Invoke(); }
  15.  
  16.     public bool Grounded { get => (bool)GetGrounded?.Invoke(); }
  17.     public Transform GroundHitTransform { get => GetGroundHitTransform?.Invoke(); }
  18.     public Vector2 MoveAxes { get => (Vector2)GetMoveAxes?.Invoke(); }
  19.     #endregion
  20.  
  21.     #region State Getters
  22.     public Func<float> GetRadius;
  23.     public Func<float> GetHeight;
  24.     public Func<Vector3> GetCenter;
  25.     public Func<Vector3> GetVelocity;
  26.  
  27.     public Func<bool> GetGrounded;
  28.     public Func<Transform> GetGroundHitTransform;
  29.     public Func<Vector2> GetMoveAxes;
  30.  
  31.     private bool? isLocal;
  32.     private bool? isAI;
  33.  
  34.     private bool GetIsLocal()
  35.     {
  36.         if (!isLocal.HasValue)
  37.             isLocal = (GetComponent<ICharacterOwner>() != null);
  38.         return isLocal.Value;
  39.     }
  40.     private bool GetIsRemote()
  41.     {
  42.         if (!isLocal.HasValue)
  43.             isLocal = (GetComponent<ICharacterOwner>() != null);
  44.         return !isLocal.Value;
  45.     }
  46.     private bool GetIsAI()
  47.     {
  48.         if (!isAI.HasValue)
  49.             isAI = (GetComponent<ICharacterAIOwner>() != null);
  50.         return isAI.Value;
  51.     }
  52.     #endregion
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement