using Cinemachine; using PMaker.DependencyInjection; using StarterAssets; using UniRx; using UniRx.Triggers; using UnityEngine; using UnityEngine.InputSystem; public class ThirdPersonLogic : SingletonMonobehaviour { [SerializeField] private StarterAssetsInputs _starterAssetsInputs; [SerializeField] private ThirdPersonController _thirdPersonController; private Vector3 _defaultPos; private Quaternion _defaultRot; private float _cinemachineTargetYaw; private float _cinemachineTargetPitch; private void Reset() { _starterAssetsInputs = this.GetComponentInChildren(); _thirdPersonController = this.GetComponentInChildren(); } void Start() { _defaultPos = _thirdPersonController.transform.localPosition; _defaultRot = _thirdPersonController.transform.localRotation; _cinemachineTargetYaw = _thirdPersonController.CinemachineTargetYaw; _cinemachineTargetPitch = _thirdPersonController.CinemachineTargetPitch; this.UpdateAsObservable() .Subscribe(_ => { if (Mouse.current.rightButton.isPressed) { _starterAssetsInputs.cursorInputForLook = true; } else { _starterAssetsInputs.cursorInputForLook = false; _starterAssetsInputs.look = Vector2.zero; } }) .AddTo(this); } void Update() { #if UNITY_EDITOR if (Keyboard.current[Key.R].wasPressedThisFrame) { this.ResetState(); } #endif } public void SetPlayer(bool value) { this.enabled = value; } public void SetActive(bool value) { this.transform.GetChild(0).gameObject.SetActive(value); this.transform.GetChild(1).gameObject.SetActive(value); } public void Begin() { this.ResetState(); this.SetActive(true); } public void End() { this.SetActive(false); this.ResetState(); } [ContextMenu("ResetState")] public void ResetState() { this._thirdPersonController.transform.localPosition = _defaultPos; this._thirdPersonController.transform.localRotation = _defaultRot; this._thirdPersonController.CinemachineTargetYaw = this._cinemachineTargetYaw; this._thirdPersonController.CinemachineTargetYaw = this._cinemachineTargetPitch; } } namespace StarterAssets { public partial class ThirdPersonController { public float CinemachineTargetYaw { get => this._cinemachineTargetYaw; set => this._cinemachineTargetYaw = value; } public float CinemachineTargetPitch { get => this._cinemachineTargetPitch; set => this._cinemachineTargetPitch = value; } } }