| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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<CharacterController>();
- fpsController = GetComponent<MyFirstPersonController>();
- cameraMain = transform.Find("CameraMain").GetComponent<Camera>();
- //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<Vector2>();
- var axis_updown = inputActions.UpDown.ReadValue<float>();
- if (!isPointerOverUI)
- {
- Vector3 vec3Move = new Vector3(vec2Move.x, vec2Move.y, axis_updown);
- cameraStateCurrent?.OnMove(vec3Move);
- var vec2Rotate = inputActions.Rotate.ReadValue<Vector2>();
- cameraStateCurrent?.OnRotate(vec2Rotate);
- var sv = inputActions.Zoom.ReadValue<float>();
- //var sv = Mouse.current.scroll.ReadValue().y; //Input.GetAxis("Mouse ScrollWheel");
- cameraStateCurrent?.OnZoom(sv * 0.001f);
- var translation = inputActions.Translation.ReadValue<Vector2>();
- cameraStateCurrent?.OnTranlation(translation);
- var addSpeed = inputActions.AddSpeed.ReadValue<float>();
- cameraStateCurrent?.OnAddSpeed(addSpeed);
- var speedScale = inputActions.SpeedScale.ReadValue<float>();
- cameraStateCurrent?.OnChangeSpeedScale(speedScale);
- }
- }
- private void Update()
- {
- cameraStateCurrent?.Update();
- }
- }
- }
|