Space-Smash-Out/Assets/Plugins/PrimeTween/Demo/Scripts/CameraController.cs
Jakob Feldmann 64162cb4a1 feat: whole project restructuring
This can be seen as the initial state of the project after the released demo.

The changes include:
- New ship models
- Singleton manager structure to keep project scaleable in the future
     - Managing players, their settings, character choices, statistics, match setups, controls etc. in a separate decoupled scene
- Main menu with transitions to the arena scene
- Beginnings of a custom audio solution
- Logging with Log4Net

It is really a complete overhaul of the projects structure and management.
2024-04-01 23:06:39 +02:00

55 lines
2.0 KiB
C#

#if PRIME_TWEEN_INSTALLED
using PrimeTween;
using UnityEngine;
using UnityEngine.EventSystems;
namespace PrimeTweenDemo {
public class CameraController : MonoBehaviour {
[SerializeField] HighlightedElementController highlightedElementController;
[SerializeField] SwipeTutorial swipeTutorial;
[SerializeField] Camera mainCamera;
[SerializeField, Range(0f, 1f)] float cameraShakeStrength = 0.4f;
float currentAngle;
Vector3? inputBeginPos;
bool isAnimating;
float curRotationSpeed;
void OnEnable() {
currentAngle = transform.localEulerAngles.y;
isAnimating = true;
Tween.Custom(this, 0, 5, 2, (target, val) => target.curRotationSpeed = val);
}
void Update() {
if (isAnimating) {
currentAngle += curRotationSpeed * Time.deltaTime;
transform.localEulerAngles = new Vector3(0f, currentAngle);
}
if (highlightedElementController.current == null && Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) {
inputBeginPos = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0)) {
inputBeginPos = null;
}
if (inputBeginPos.HasValue) {
var deltaMove = Input.mousePosition - inputBeginPos.Value;
if (Mathf.Abs(deltaMove.x) / Screen.width > 0.05f) {
isAnimating = false;
inputBeginPos = null;
currentAngle += Mathf.Sign(deltaMove.x) * 45f;
Tween.LocalRotation(transform, new Vector3(0f, currentAngle), 1.5f, Ease.OutCubic);
swipeTutorial.Hide();
}
}
}
public void ShakeCamera() {
Shake();
}
internal Sequence Shake(float startDelay = 0) {
return Tween.ShakeCamera(mainCamera, cameraShakeStrength, startDelay: startDelay);
}
}
}
#endif