update packages, fix cinemachine

This commit is contained in:
2024-11-21 17:41:25 +02:00
parent 3a072785e2
commit 35837405a5
16 changed files with 714 additions and 324 deletions
+18 -21
View File
@@ -1,4 +1,4 @@
using Cinemachine;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -9,7 +9,7 @@ public class CameraSystem : MonoBehaviour
public Camera MainCamera => _mainCamera;
[SerializeField]
private CinemachineVirtualCamera _camera;
private CinemachineCamera _camera;
[SerializeField]
private float _fieldOfViewMax = 60f;
[SerializeField]
@@ -29,7 +29,7 @@ public class CameraSystem : MonoBehaviour
[SerializeField]
private bool _useMouseRotate;
private Vector3 _followOffset;
private Vector3 _followOffset =new Vector3(0,8,-10);
[SerializeField]
private float _rotateSpeed = 100f;
[SerializeField]
@@ -41,13 +41,12 @@ public class CameraSystem : MonoBehaviour
[SerializeField]
private float _zoomAmount = 3f;
private float _targetFieldOfView = 60f;
private CinemachineTransposer _cinemachineTransposer;
private CinemachineFollow _cinemachineTransposer;
private Bounds _worldBounds;
private void Awake()
{
_cinemachineTransposer = _camera.GetCinemachineComponent<CinemachineTransposer>();
_followOffset = _cinemachineTransposer.m_FollowOffset;
_cinemachineTransposer = _camera.GetCinemachineComponent(CinemachineCore.Stage.Body) as CinemachineFollow;
}
private void Start()
@@ -82,7 +81,7 @@ public class CameraSystem : MonoBehaviour
HandleCameraRotation(rotateDir, _rotateSpeed);
}
float zoomAmount = GameManager.Instance.Input.CameraAction.Zoom.ReadValue<Vector2>().y;
float zoomAmount = GameManager.Instance.Input.CameraAction.Zoom.ReadValue<float>();
if (zoomAmount != 0)
{
HandleCameraZoom_MoveY(zoomAmount);
@@ -98,9 +97,10 @@ public class CameraSystem : MonoBehaviour
private void HandleCameraZoom_MoveForward()
{
Vector3 zoomDir = _followOffset.normalized;
if (Input.mouseScrollDelta.y > 0)
var scrollDelta=GameManager.Instance.Input.CameraAction.Zoom.ReadValue<float>();
if (scrollDelta > 0)
_followOffset -= zoomDir * _zoomAmount;
if (Input.mouseScrollDelta.y < 0)
if (scrollDelta < 0)
_followOffset += zoomDir * _zoomAmount;
if (_followOffset.magnitude < _followOffsetMin)
@@ -109,9 +109,9 @@ public class CameraSystem : MonoBehaviour
if (_followOffset.magnitude > _followOffsetMax)
_followOffset = zoomDir * _followOffsetMax;
Vector3.Lerp(_cinemachineTransposer.m_FollowOffset, _followOffset, Time.deltaTime * _zoomSpeed);
Vector3.Lerp(_cinemachineTransposer.FollowOffset, _followOffset, Time.deltaTime * _zoomSpeed);
_cinemachineTransposer.m_FollowOffset = _followOffset;
_cinemachineTransposer.FollowOffset = _followOffset;
}
private void HandleCameraZoom_MoveY(float _zoomAmount)
@@ -126,21 +126,22 @@ public class CameraSystem : MonoBehaviour
if (_followOffset.magnitude > _followOffsetMax)
_followOffset.y = _zoomAmount * _followOffsetMax;
Vector3.Lerp(_cinemachineTransposer.m_FollowOffset, _followOffset, Time.deltaTime * _zoomSpeed);
Vector3.Lerp(_cinemachineTransposer.FollowOffset, _followOffset, Time.deltaTime * _zoomSpeed);
_cinemachineTransposer.m_FollowOffset = _followOffset;
_cinemachineTransposer.FollowOffset = _followOffset;
}
private void HandleCameraZoom_FOV()
{
if (Input.mouseScrollDelta.y > 0)
var scrollDelta = GameManager.Instance.Input.CameraAction.Zoom.ReadValue<float>();
if (scrollDelta > 0)
_targetFieldOfView -= 5;
if (Input.mouseScrollDelta.y < 0)
if (scrollDelta < 0)
_targetFieldOfView += 5;
_targetFieldOfView = Mathf.Clamp(_targetFieldOfView, _fieldOfViewMin, _fieldOfViewMax);
Mathf.Lerp(_camera.m_Lens.FieldOfView, _targetFieldOfView, Time.deltaTime * _zoomSpeed);
_camera.m_Lens.FieldOfView = _targetFieldOfView;
Mathf.Lerp(_camera.Lens.FieldOfView, _targetFieldOfView, Time.deltaTime * _zoomSpeed);
_camera.Lens.FieldOfView = _targetFieldOfView;
}
private void HandleCameraMovement(Vector2 inputDir)
@@ -186,10 +187,6 @@ public class CameraSystem : MonoBehaviour
private void OnCameraRotate(InputAction.CallbackContext context)
{
if (Mouse.current.middleButton.isPressed)
{
}
float rotateDir = GameManager.Instance.Input.CameraAction.Rotate.ReadValue<Vector2>().x;
//HandleCameraRotation(rotationValue, _mouseRotationSpeed);
transform.eulerAngles += new Vector3(0, rotateDir * _rotateSpeed * Time.deltaTime, 0);
@@ -51,7 +51,10 @@ public class InGameMouseHandler : UnityEngine.Object
public void Update()
{
if (GameManager.Instance.Input.PlayerAction.CancelClick.WasPressedThisFrame())
{
GameManager.Instance.UI.ClosePopupMenu();
}
if (GameManager.Instance.Input.PlayerAction.PointClick.WasPressedThisFrame())
{
ClickToMove(!EventSystem.current.IsPointerOverGameObject());
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.8.2
// version 1.11.2
// from Assets/Scripts/Managers/InputSystem/InputActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
@@ -14,7 +14,6 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
using UnityEngine;
public partial class @InputActions: IInputActionCollection2, IDisposable
{
@@ -32,6 +31,15 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
""name"": ""PointClick"",
""type"": ""Button"",
""id"": ""fb720cef-8db9-45ea-94b8-34ee20907014"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""CancelClick"",
""type"": ""Button"",
""id"": ""a045f2ab-c0ec-42fc-9343-39839caf2ba4"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
@@ -60,6 +68,28 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
""action"": ""PointClick"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""f43a2e12-ac25-49ce-95aa-43fd4e3754b2"",
""path"": ""<Mouse>/rightButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""CancelClick"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""2c0753e9-8ef2-43b1-893f-d360ac7a34d3"",
""path"": ""<Gamepad>/buttonWest"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""CancelClick"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
},
@@ -89,7 +119,7 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
""name"": ""Zoom"",
""type"": ""Value"",
""id"": ""41d86dbc-39e0-4655-bc19-0eab9d5014a6"",
""expectedControlType"": ""Vector2"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
@@ -307,16 +337,44 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
},
{
""name"": """",
""id"": ""8e2aefc6-bf10-4653-8782-6b92d5efc35a"",
""path"": ""<Mouse>/scroll"",
""id"": ""1a09948a-e3d8-4dc0-a257-95fa88786135"",
""path"": ""<Mouse>/scroll/y"",
""interactions"": """",
""processors"": ""NormalizeVector2,InvertVector2(invertX=false)"",
""processors"": """",
""groups"": """",
""action"": ""Zoom"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
},
{
""name"": ""UI"",
""id"": ""1ad3f945-dcff-4ae6-8a8b-3dd44bd67684"",
""actions"": [
{
""name"": ""Click"",
""type"": ""Button"",
""id"": ""cddc5ce5-b808-4da9-b23b-f24a5126f838"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
{
""name"": """",
""id"": ""a16b8b36-6be6-4d2c-85da-20d72f3c8e79"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Click"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
],
""controlSchemes"": []
@@ -324,17 +382,22 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
// Player
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_PointClick = m_Player.FindAction("PointClick", throwIfNotFound: true);
m_Player_CancelClick = m_Player.FindAction("CancelClick", throwIfNotFound: true);
// Camera
m_Camera = asset.FindActionMap("Camera", throwIfNotFound: true);
m_Camera_Move = m_Camera.FindAction("Move", throwIfNotFound: true);
m_Camera_Rotate = m_Camera.FindAction("Rotate", throwIfNotFound: true);
m_Camera_Zoom = m_Camera.FindAction("Zoom", throwIfNotFound: true);
// UI
m_UI = asset.FindActionMap("UI", throwIfNotFound: true);
m_UI_Click = m_UI.FindAction("Click", throwIfNotFound: true);
}
~@InputActions()
{
Debug.Assert(!m_Player.enabled, "This will cause a leak and performance issues, InputActions.Player.Disable() has not been called.");
Debug.Assert(!m_Camera.enabled, "This will cause a leak and performance issues, InputActions.Camera.Disable() has not been called.");
UnityEngine.Debug.Assert(!m_Player.enabled, "This will cause a leak and performance issues, InputActions.Player.Disable() has not been called.");
UnityEngine.Debug.Assert(!m_Camera.enabled, "This will cause a leak and performance issues, InputActions.Camera.Disable() has not been called.");
UnityEngine.Debug.Assert(!m_UI.enabled, "This will cause a leak and performance issues, InputActions.UI.Disable() has not been called.");
}
public void Dispose()
@@ -397,11 +460,13 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
private readonly InputActionMap m_Player;
private List<IPlayerActions> m_PlayerActionsCallbackInterfaces = new List<IPlayerActions>();
private readonly InputAction m_Player_PointClick;
private readonly InputAction m_Player_CancelClick;
public struct PlayerActions
{
private @InputActions m_Wrapper;
public PlayerActions(@InputActions wrapper) { m_Wrapper = wrapper; }
public InputAction @PointClick => m_Wrapper.m_Player_PointClick;
public InputAction @CancelClick => m_Wrapper.m_Player_CancelClick;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
@@ -414,6 +479,9 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
@PointClick.started += instance.OnPointClick;
@PointClick.performed += instance.OnPointClick;
@PointClick.canceled += instance.OnPointClick;
@CancelClick.started += instance.OnCancelClick;
@CancelClick.performed += instance.OnCancelClick;
@CancelClick.canceled += instance.OnCancelClick;
}
private void UnregisterCallbacks(IPlayerActions instance)
@@ -421,6 +489,9 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
@PointClick.started -= instance.OnPointClick;
@PointClick.performed -= instance.OnPointClick;
@PointClick.canceled -= instance.OnPointClick;
@CancelClick.started -= instance.OnCancelClick;
@CancelClick.performed -= instance.OnCancelClick;
@CancelClick.canceled -= instance.OnCancelClick;
}
public void RemoveCallbacks(IPlayerActions instance)
@@ -500,9 +571,56 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
}
}
public CameraActions @Camera => new CameraActions(this);
// UI
private readonly InputActionMap m_UI;
private List<IUIActions> m_UIActionsCallbackInterfaces = new List<IUIActions>();
private readonly InputAction m_UI_Click;
public struct UIActions
{
private @InputActions m_Wrapper;
public UIActions(@InputActions wrapper) { m_Wrapper = wrapper; }
public InputAction @Click => m_Wrapper.m_UI_Click;
public InputActionMap Get() { return m_Wrapper.m_UI; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(UIActions set) { return set.Get(); }
public void AddCallbacks(IUIActions instance)
{
if (instance == null || m_Wrapper.m_UIActionsCallbackInterfaces.Contains(instance)) return;
m_Wrapper.m_UIActionsCallbackInterfaces.Add(instance);
@Click.started += instance.OnClick;
@Click.performed += instance.OnClick;
@Click.canceled += instance.OnClick;
}
private void UnregisterCallbacks(IUIActions instance)
{
@Click.started -= instance.OnClick;
@Click.performed -= instance.OnClick;
@Click.canceled -= instance.OnClick;
}
public void RemoveCallbacks(IUIActions instance)
{
if (m_Wrapper.m_UIActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
public void SetCallbacks(IUIActions instance)
{
foreach (var item in m_Wrapper.m_UIActionsCallbackInterfaces)
UnregisterCallbacks(item);
m_Wrapper.m_UIActionsCallbackInterfaces.Clear();
AddCallbacks(instance);
}
}
public UIActions @UI => new UIActions(this);
public interface IPlayerActions
{
void OnPointClick(InputAction.CallbackContext context);
void OnCancelClick(InputAction.CallbackContext context);
}
public interface ICameraActions
{
@@ -510,4 +628,8 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
void OnRotate(InputAction.CallbackContext context);
void OnZoom(InputAction.CallbackContext context);
}
public interface IUIActions
{
void OnClick(InputAction.CallbackContext context);
}
}
@@ -9,6 +9,15 @@
"name": "PointClick",
"type": "Button",
"id": "fb720cef-8db9-45ea-94b8-34ee20907014",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "CancelClick",
"type": "Button",
"id": "a045f2ab-c0ec-42fc-9343-39839caf2ba4",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
@@ -37,6 +46,28 @@
"action": "PointClick",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f43a2e12-ac25-49ce-95aa-43fd4e3754b2",
"path": "<Mouse>/rightButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "CancelClick",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "2c0753e9-8ef2-43b1-893f-d360ac7a34d3",
"path": "<Gamepad>/buttonWest",
"interactions": "",
"processors": "",
"groups": "",
"action": "CancelClick",
"isComposite": false,
"isPartOfComposite": false
}
]
},
@@ -66,7 +97,7 @@
"name": "Zoom",
"type": "Value",
"id": "41d86dbc-39e0-4655-bc19-0eab9d5014a6",
"expectedControlType": "Vector2",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": true
@@ -284,16 +315,44 @@
},
{
"name": "",
"id": "8e2aefc6-bf10-4653-8782-6b92d5efc35a",
"path": "<Mouse>/scroll",
"id": "1a09948a-e3d8-4dc0-a257-95fa88786135",
"path": "<Mouse>/scroll/y",
"interactions": "",
"processors": "NormalizeVector2,InvertVector2(invertX=false)",
"processors": "",
"groups": "",
"action": "Zoom",
"isComposite": false,
"isPartOfComposite": false
}
]
},
{
"name": "UI",
"id": "1ad3f945-dcff-4ae6-8a8b-3dd44bd67684",
"actions": [
{
"name": "Click",
"type": "Button",
"id": "cddc5ce5-b808-4da9-b23b-f24a5126f838",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "",
"id": "a16b8b36-6be6-4d2c-85da-20d72f3c8e79",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "",
"action": "Click",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": []
+2 -8
View File
@@ -11,13 +11,7 @@ public class RadialMenuItem : MonoBehaviour
private Button _radialMenuItemPrefab;
private Dictionary<RadialMenuActions, RadialMenuActionDescription> _actions;
private UniTaskCompletionSource<RadialMenuActions> tcs = new UniTaskCompletionSource<RadialMenuActions>();
//private float _buttonWidth;
private void Start()
{
// _buttonWidth = _radialMenuItemPrefab.GetComponent<RectTransform>().rect.width;
}
public UniTask<RadialMenuActions> ShowButtons(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions)
{
_actions = actions;
@@ -30,7 +24,7 @@ public class RadialMenuItem : MonoBehaviour
float posX = Mathf.Sin(theta);
float posY = Mathf.Cos(theta);
button.transform.localPosition = new Vector3(posX, posY, 0) * 50f;
button.transform.localPosition = new Vector3(posX, posY, 0) * 100f;
var textMeshPro = button.GetComponentInChildren<TextMeshProUGUI>();
if (textMeshPro != null)