|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using EccsLogicWorldAPI.Shared.AccessHelper;
|
|
|
|
|
using LogicLog;
|
|
|
|
|
using LogicWorld;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace CameraRoll.Client.Tool {
|
|
|
|
|
public class CameraRollTool {
|
|
|
|
|
private static ILogicLogger _logger = null!;
|
|
|
|
|
private static Camera _cam;
|
|
|
|
|
private static PropertyInfo _showBuildingUI;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// How fast does it interpolate between points
|
|
|
|
@ -17,7 +21,7 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
/// If the track is playing/animating/moving the camera
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static bool _playing;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Backup of the original (local) position and rotation of the camera
|
|
|
|
|
private static Vector3 _originalPosition;
|
|
|
|
|
private static Quaternion _originalRotation;
|
|
|
|
@ -38,6 +42,7 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
_logger = logger;
|
|
|
|
|
PathPoints.Clear();
|
|
|
|
|
_playing = false;
|
|
|
|
|
_showBuildingUI = Properties.getPrivateStatic(typeof(FirstPersonInteraction), "ShowBuildingUI");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OnEnter() {
|
|
|
|
@ -54,8 +59,19 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
};
|
|
|
|
|
point.AddComponent<PathPoint>();
|
|
|
|
|
PathPoints.Add(point);
|
|
|
|
|
|
|
|
|
|
if (PathPoints.Count > 1) {
|
|
|
|
|
point.GetComponent<PathPoint>().LinkPreviousPoint(PathPoints[^2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetPointsVisible(bool visible) {
|
|
|
|
|
foreach (GameObject point in PathPoints) {
|
|
|
|
|
point.SetActive(visible);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void Play() {
|
|
|
|
|
if (_playing) return;
|
|
|
|
|
|
|
|
|
@ -64,7 +80,10 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
|
|
|
|
|
_pointIndex = 0;
|
|
|
|
|
_interpolationState = 0.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetPointsVisible(false);
|
|
|
|
|
_showBuildingUI.SetValue(null, false); // Hide UI
|
|
|
|
|
|
|
|
|
|
_playing = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -74,6 +93,9 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
|
|
|
|
|
_cam.transform.localPosition = _originalPosition;
|
|
|
|
|
_cam.transform.localRotation = _originalRotation;
|
|
|
|
|
|
|
|
|
|
SetPointsVisible(true);
|
|
|
|
|
_showBuildingUI.SetValue(null, true); // Show UI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Clear() {
|
|
|
|
@ -102,16 +124,15 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_interpolationState += InterpolationSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 prevPos = GetPos(_pointIndex - 1);
|
|
|
|
|
Vector3 posDiff = GetPos(_pointIndex) - prevPos;
|
|
|
|
|
_cam.transform.position = prevPos + posDiff * _interpolationState;
|
|
|
|
|
|
|
|
|
|
Vector3 prevRot = GetRot(_pointIndex - 1);
|
|
|
|
|
Vector3 rotDiff = GetRot(_pointIndex) - prevRot;
|
|
|
|
|
_cam.transform.eulerAngles = prevRot + rotDiff * _interpolationState;
|
|
|
|
|
// TODO: interpolate across the shorter direction of rotation
|
|
|
|
|
|
|
|
|
|
Vector3 newPos = GetPos(_pointIndex);
|
|
|
|
|
_cam.transform.position = Vector3.Lerp(prevPos, newPos, _interpolationState);
|
|
|
|
|
|
|
|
|
|
Quaternion prevRot = GetRot(_pointIndex - 1);
|
|
|
|
|
Quaternion newRot = GetRot(_pointIndex);
|
|
|
|
|
_cam.transform.rotation = Quaternion.Slerp(prevRot, newRot, _interpolationState);
|
|
|
|
|
|
|
|
|
|
if (_interpolationState >= 1.0f) {
|
|
|
|
|
_pointIndex++;
|
|
|
|
|
_interpolationState = 0.0f;
|
|
|
|
@ -120,7 +141,7 @@ namespace CameraRoll.Client.Tool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Vector3 GetPos(int index) => PathPoints[index].transform.position;
|
|
|
|
|
private static Vector3 GetRot(int index) => PathPoints[index].transform.eulerAngles;
|
|
|
|
|
private static Quaternion GetRot(int index) => PathPoints[index].transform.rotation;
|
|
|
|
|
|
|
|
|
|
public static void OnExit() {
|
|
|
|
|
Clear();
|
|
|
|
|