Skip to content

Commit 291f475

Browse files
committed
Lock cinemachine camera position
1 parent 1af2741 commit 291f475

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

Runtime/Cinemachine/Impulse/CinemachineContinuousImpulse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Juce.CoreUnity.Cinemachine.Impulse
1111
{
12-
public class CinemachineContinuousImpulse : MonoBehaviour
12+
public sealed class CinemachineContinuousImpulse : MonoBehaviour
1313
{
1414
[CinemachineImpulseDefinitionProperty]
1515
[SerializeField] private CinemachineImpulseDefinition impulseDefinition = new CinemachineImpulseDefinition();

Runtime/Cinemachine/Locking.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#if JUCE_CINEMACHINE_EXTENSIONS
2+
3+
using UnityEngine;
4+
using Cinemachine;
5+
6+
namespace Juce.CoreUnity.Cinemachine.Locking
7+
{
8+
[ExecuteInEditMode]
9+
[SaveDuringPlay]
10+
[AddComponentMenu("")] // Hide in menu
11+
public sealed class CinemachineLockPosition : CinemachineExtension
12+
{
13+
[Header("X Lock")]
14+
public bool XLockEnabled = false;
15+
public float XLockPosition = 0;
16+
17+
[Header("Y Lock")]
18+
public bool YLockEnabled = false;
19+
public float YLockPosition = 0;
20+
21+
[Header("Z Lock")]
22+
public bool ZLockEnabled = false;
23+
public float ZLockPosition = 0;
24+
25+
protected override void PostPipelineStageCallback(
26+
CinemachineVirtualCameraBase vcam,
27+
CinemachineCore.Stage stage,
28+
ref CameraState state,
29+
float deltaTime
30+
)
31+
{
32+
if(stage != CinemachineCore.Stage.Body)
33+
{
34+
return;
35+
}
36+
37+
Vector3 position = state.RawPosition;
38+
39+
if (XLockEnabled)
40+
{
41+
position.x = XLockPosition;
42+
}
43+
44+
if (YLockEnabled)
45+
{
46+
position.y = YLockPosition;
47+
}
48+
49+
if (ZLockEnabled)
50+
{
51+
position.z = ZLockPosition;
52+
}
53+
54+
state.RawPosition = position;
55+
}
56+
}
57+
}
58+
59+
#endif

Runtime/Cinemachine/Locking/CinemachineLockPosition.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)