diff --git a/CameraRoll/CameraRoll.csproj b/CameraRoll/CameraRoll.csproj
index 59baea5..02fbc4c 100644
--- a/CameraRoll/CameraRoll.csproj
+++ b/CameraRoll/CameraRoll.csproj
@@ -32,5 +32,8 @@
$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicLog.dll
+
+ $(LogicWorldGameLocation)\Logic_World_Data\Managed\UnityEngine.CoreModule.dll
+
diff --git a/CameraRoll/CameraRoll/manifest.jecs b/CameraRoll/CameraRoll/manifest.jecs
index 83569fa..d86374a 100755
--- a/CameraRoll/CameraRoll/manifest.jecs
+++ b/CameraRoll/CameraRoll/manifest.jecs
@@ -1,7 +1,7 @@
ID: D4VID_CameraRoll
Name: CameraRoll
Author: D4VID
-Version: 0.0.1
+Version: 0.1.0
Priority: 0
ClientOnly: true
Dependencies:
diff --git a/CameraRoll/CameraRoll/src/client/CameraRollGameState.cs b/CameraRoll/CameraRoll/src/client/CameraRollGameState.cs
index 811a9ed..2329d2d 100755
--- a/CameraRoll/CameraRoll/src/client/CameraRollGameState.cs
+++ b/CameraRoll/CameraRoll/src/client/CameraRollGameState.cs
@@ -12,10 +12,15 @@ namespace CameraRoll.Client {
public override string TextID => Id;
///
- /// Locked mouse means you look around when you move it.
- /// False would display the cursor to be able to click on UI elements.
+ /// True locks mouse so you look around when you move it.
+ /// False displays the cursor to be able to click on UI elements.
///
- public override bool MouseLocked => true;
+ public override bool MouseLocked => false;
+
+ ///
+ /// Don't display the hotbar with components as the user cannot place them
+ ///
+ public override bool ShowHotbarWhileStateActive => false;
///
/// This list gets printed on the game's top left UI panel which displays the currently available keybindings
@@ -33,6 +38,7 @@ namespace CameraRoll.Client {
///
public override void OnEnter() {
CameraRollClientMod.Logger.Info("CameraRollGameState enter");
+ CameraRollTool.OnEnter();
}
///
@@ -50,6 +56,8 @@ namespace CameraRoll.Client {
} else if (CustomInput.DownThisFrame(CameraRollTrigger.Clear)) {
CameraRollTool.Clear();
}
+
+ CameraRollTool.Update();
}
///
diff --git a/CameraRoll/CameraRoll/src/client/tool/CameraRollTool.cs b/CameraRoll/CameraRoll/src/client/tool/CameraRollTool.cs
index 2c47e9d..0820205 100755
--- a/CameraRoll/CameraRoll/src/client/tool/CameraRollTool.cs
+++ b/CameraRoll/CameraRoll/src/client/tool/CameraRollTool.cs
@@ -1,28 +1,130 @@
+using System.Collections.Generic;
using LogicLog;
+using UnityEngine;
namespace CameraRoll.Client.Tool {
-
public class CameraRollTool {
private static ILogicLogger _logger = null!;
+ private static Camera _cam;
+
+ ///
+ /// How fast does it interpolate between points
+ /// TODO: Make this editable per point
+ ///
+ private const float InterpolationSpeed = 0.005f;
+
+ ///
+ /// If the track is playing/animating/moving the camera
+ ///
+ private static bool _playing;
+
+ // Backup of the original (local) position and rotation of the camera
+ private static Vector3 _originalPosition;
+ private static Quaternion _originalRotation;
+
+ ///
+ /// Which point the camera is currently heading towards
+ ///
+ private static int _pointIndex;
+
+ ///
+ /// Progress of the linear interpolation (0.0f - 1.0f)
+ ///
+ private static float _interpolationState;
+
+ private static readonly List PathPoints = new List();
public static void Init(ILogicLogger logger) {
_logger = logger;
+ PathPoints.Clear();
+ _playing = false;
+ }
+
+ public static void OnEnter() {
+ _cam = Camera.main;
}
public static void PlacePoint() {
_logger.Info("PlacePoint");
+ GameObject point = new GameObject($"PathPoint #{PathPoints.Count}") {
+ transform = {
+ position = _cam.transform.position,
+ rotation = _cam.transform.rotation
+ }
+ };
+ point.AddComponent();
+ PathPoints.Add(point);
}
public static void Play() {
- _logger.Info("Play");
+ if (_playing) return;
+
+ _originalPosition = _cam.transform.localPosition;
+ _originalRotation = _cam.transform.localRotation;
+
+ _pointIndex = 0;
+ _interpolationState = 0.0f;
+
+ _playing = true;
}
public static void Stop() {
- _logger.Info("Stop");
+ if (!_playing) return;
+ _playing = false;
+
+ _cam.transform.localPosition = _originalPosition;
+ _cam.transform.localRotation = _originalRotation;
}
public static void Clear() {
- _logger.Info("Clear");
+ foreach (GameObject point in PathPoints) {
+ Object.Destroy(point);
+ }
+
+ PathPoints.Clear();
+ }
+
+ public static void Update() {
+ if (_playing) {
+ if (_pointIndex >= PathPoints.Count) {
+ // Reached the end
+ _logger.Info("Reached the end of track");
+ Stop();
+ return;
+ }
+
+ if (_pointIndex == 0) {
+ // Snap to the first defined point
+ _cam.transform.position = PathPoints[0].transform.position;
+ _pointIndex++;
+ _interpolationState = 0.0f;
+ return;
+ }
+
+ _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
+
+ if (_interpolationState >= 1.0f) {
+ _pointIndex++;
+ _interpolationState = 0.0f;
+ }
+ }
+ }
+
+ private static Vector3 GetPos(int index) => PathPoints[index].transform.position;
+ private static Vector3 GetRot(int index) => PathPoints[index].transform.eulerAngles;
+
+ public static void OnExit() {
+ Clear();
+ _playing = false;
}
}
}
\ No newline at end of file
diff --git a/CameraRoll/CameraRoll/src/client/tool/PathPoint.cs b/CameraRoll/CameraRoll/src/client/tool/PathPoint.cs
new file mode 100644
index 0000000..ac69006
--- /dev/null
+++ b/CameraRoll/CameraRoll/src/client/tool/PathPoint.cs
@@ -0,0 +1,27 @@
+using UnityEngine;
+
+namespace CameraRoll.Client.Tool {
+ public class PathPoint : MonoBehaviour {
+ private const float AxisLength = 0.1f;
+
+ void Start() {
+ CreateAxis(Vector3.right, Color.red);
+ CreateAxis(Vector3.up, Color.green);
+ CreateAxis(Vector3.forward, Color.blue);
+ }
+
+ void CreateAxis(Vector3 dir, Color color) {
+ GameObject line = new GameObject("Axis");
+ line.transform.SetParent(transform, false);
+ LineRenderer lr = line.AddComponent();
+ lr.useWorldSpace = false;
+ lr.positionCount = 2;
+ lr.SetPosition(0, dir.normalized * -AxisLength);
+ lr.SetPosition(1, dir.normalized * AxisLength);
+ lr.material = new Material(Shader.Find("Unlit/Color"));
+ lr.material.color = color;
+ lr.startWidth = 0.01f;
+ lr.endWidth = 0.01f;
+ }
+ }
+}
\ No newline at end of file