Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- public class CharacterState : MonoBehaviour
- {
- #region State
- public bool IsLocal { get => GetIsLocal(); }
- public bool IsRemote { get => GetIsRemote(); }
- public bool IsAI { get => GetIsAI(); }
- public float Radius { get => (float)GetRadius?.Invoke(); }
- public float Height { get => (float)GetHeight?.Invoke(); }
- public Vector3 Center { get => (Vector3)GetCenter?.Invoke(); }
- public Vector3 Velocity { get => (Vector3)GetVelocity?.Invoke(); }
- public bool Grounded { get => (bool)GetGrounded?.Invoke(); }
- public Transform GroundHitTransform { get => GetGroundHitTransform?.Invoke(); }
- public Vector2 MoveAxes { get => (Vector2)GetMoveAxes?.Invoke(); }
- #endregion
- #region State Getters
- public Func<float> GetRadius;
- public Func<float> GetHeight;
- public Func<Vector3> GetCenter;
- public Func<Vector3> GetVelocity;
- public Func<bool> GetGrounded;
- public Func<Transform> GetGroundHitTransform;
- public Func<Vector2> GetMoveAxes;
- private bool? isLocal;
- private bool? isAI;
- private bool GetIsLocal()
- {
- if (!isLocal.HasValue)
- isLocal = (GetComponent<ICharacterOwner>() != null);
- return isLocal.Value;
- }
- private bool GetIsRemote()
- {
- if (!isLocal.HasValue)
- isLocal = (GetComponent<ICharacterOwner>() != null);
- return !isLocal.Value;
- }
- private bool GetIsAI()
- {
- if (!isAI.HasValue)
- isAI = (GetComponent<ICharacterAIOwner>() != null);
- return isAI.Value;
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement