1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // MIT License
- // https://gitlab.com/ilnprj
- // Copyright (c) 2020 ilnprj
- using System;
- using UnityEngine;
- namespace RadarComponents
- {
- /// <summary>
- /// A class that will report when it is possible to update any means of the radar.
- /// </summary>
- public class PlayerLocator : MonoBehaviour
- {
- [SerializeField]
- private Camera cameraPlayer = default;
- public Camera CameraPlayer
- {
- get
- {
- return cameraPlayer;
- }
- }
- public static bool IsInited
- {
- get
- {
- return isInited;
- }
- private set
- {
- isInited = value;
- if (value)
- {
- onInit();
- }
- }
- }
- public static Action onUpdateLocator = delegate { };
- public static event Action onInit = delegate { };
- private static bool isInited = false;
- private Vector3 _position;
- private Quaternion _rotation;
- private Vector3 lastPosition
- {
- set
- {
- if (_position != value)
- {
- _position = value;
- onUpdateLocator();
- }
- }
- }
- private Quaternion lastRotation
- {
- set
- {
- if (_rotation != value)
- {
- _rotation = value;
- onUpdateLocator();
- }
- }
- }
- private void Awake()
- {
- IsInited = true;
- }
- private void FixedUpdate()
- {
- lastPosition = transform.position;
- lastRotation = transform.rotation;
- }
- /// <summary>
- /// Update the locator forcibly from the outside(In case the object (target) moves by itself.
- /// </summary>
- public void UpdateLocator()
- {
- onUpdateLocator();
- }
- }
- }
|