using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; //using UnityGameFramework.Runtime; using UnityStandardAssets.Characters.FirstPerson; namespace UnityCommon { [DisallowMultipleComponent] public sealed class CameraController : MonoBehaviour { public static CameraController Instance; public InputCtrlCamera.CameraCtrlActions inputActions; [HideInInspector] public CharacterController characterController; [HideInInspector] public MyFirstPersonController fpsController; [HideInInspector] public Camera cameraMain; public CameraState cameraStateCurrent; void Awake() { Instance = this; inputActions = new InputCtrlCamera().CameraCtrl; inputActions.Enable(); characterController = GetComponent(); fpsController = GetComponent(); cameraMain = transform.Find("CameraMain").GetComponent(); //cameraMain.transform.SetParent(null); } public void Enter(CameraState cameraState) { cameraStateCurrent?.Exit(); cameraState.preCameraState = cameraStateCurrent; cameraStateCurrent = cameraState; cameraStateCurrent?.Enter(); } private bool isPointerOverUI { get { return Utility.IsPointerOverUIObject(); } } private void LateUpdate() { var vec2Move = inputActions.Move.ReadValue(); var axis_updown = inputActions.UpDown.ReadValue(); if (!isPointerOverUI) { Vector3 vec3Move = new Vector3(vec2Move.x, vec2Move.y, axis_updown); cameraStateCurrent?.OnMove(vec3Move); var vec2Rotate = inputActions.Rotate.ReadValue(); cameraStateCurrent?.OnRotate(vec2Rotate); var sv = inputActions.Zoom.ReadValue(); //var sv = Mouse.current.scroll.ReadValue().y; //Input.GetAxis("Mouse ScrollWheel"); cameraStateCurrent?.OnZoom(sv * 0.001f); var translation = inputActions.Translation.ReadValue(); cameraStateCurrent?.OnTranlation(translation); var addSpeed = inputActions.AddSpeed.ReadValue(); cameraStateCurrent?.OnAddSpeed(addSpeed); var speedScale = inputActions.SpeedScale.ReadValue(); cameraStateCurrent?.OnChangeSpeedScale(speedScale); } } private void Update() { cameraStateCurrent?.Update(); } } }