Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions BopVisualEffects/Effects/CameraShake/CameraShakeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public MixtapeEventTemplate CreateTemplate(string pluginGuid)
properties = new Dictionary<string, object>
{
["amplitude"] = 0.1f,
["frequency"] = 18.0f
["frequency"] = 18.0f,
["persist_camera"] = false
}
};
}
Expand All @@ -44,6 +45,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
var durationBeats = Mathf.Max(0.01f, entity.length);
var amplitude = entity.GetFloat("amplitude");
var frequency = entity.GetFloat("frequency");
var persist = entity.GetBool("persist_camera", false);
var startBeat = entity.beat;
var endBeat = startBeat + durationBeats;

Expand All @@ -54,7 +56,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
void SpawnAction()
{
EffectRuntimeController.Instance.SpawnRunner<CameraShakeRunner>(runner =>
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, amplitude, frequency));
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, amplitude, frequency, persist));
}
}

Expand All @@ -69,18 +71,20 @@ private sealed class CameraShakeRunner : MonoBehaviour
private JukeboxScript? _jukebox;
private Transform? _targetTransform;
private Vector3 _initialLocalPosition;
private bool _persistCamera;

/// <summary>
/// Initializes this runner with effect parameters.
/// </summary>
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, float amplitude, float frequency)
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, float amplitude, float frequency, bool persistCamera)
{
_loader = loader;
_jukebox = jukebox;
_startBeat = startBeat;
_endBeat = endBeat;
_amplitude = Mathf.Max(0f, amplitude);
_frequency = Mathf.Max(0.1f, frequency);
_persistCamera = persistCamera;
InitializeTargetCamera();
}

Expand Down Expand Up @@ -108,6 +112,9 @@ private void LateUpdate()
return;
}

if (_persistCamera)
RebindCameraIfNeeded();

var currentBeat = _jukebox.CurrentBeat;
if (currentBeat >= _endBeat)
{
Expand Down Expand Up @@ -150,6 +157,17 @@ private void InitializeTargetCamera()
_initialized = true;
}

private void RebindCameraIfNeeded()
{
Camera? camera = EffectRuntimeController.ResolveEffectCamera(_loader);
if (camera is null || _targetTransform == camera.transform)
return;

ResetCameraTransform();
_targetTransform = camera.transform;
_initialLocalPosition = _targetTransform.localPosition;
}

private void ResetCameraTransform()
{
if (_targetTransform is null)
Expand Down
24 changes: 21 additions & 3 deletions BopVisualEffects/Effects/CameraTilt/CameraTiltEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public MixtapeEventTemplate CreateTemplate(string pluginGuid)
resizable = true,
properties = new Dictionary<string, object>
{
["angle"] = 5.0f
["angle"] = 5.0f,
["persist_camera"] = false
}
};
}
Expand All @@ -42,6 +43,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
var log = ClassLogger.GetForClass<CameraTiltEffect>();
var durationBeats = Mathf.Max(0.01f, entity.length);
var angle = entity.GetFloat("angle");
var persist = entity.GetBool("persist_camera", false);
var startBeat = entity.beat;
var endBeat = startBeat + durationBeats;

Expand All @@ -52,7 +54,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
void SpawnAction()
{
EffectRuntimeController.Instance.SpawnRunner<CameraTiltRunner>(runner =>
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, angle));
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, angle, persist));
}
}

Expand All @@ -66,17 +68,19 @@ private sealed class CameraTiltRunner : MonoBehaviour
private JukeboxScript? _jukebox;
private Transform? _targetTransform;
private Quaternion _initialLocalRotation;
private bool _persistCamera;

/// <summary>
/// Initializes this runner with effect parameters.
/// </summary>
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, float angle)
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, float angle, bool persistCamera)
{
_loader = loader;
_jukebox = jukebox;
_startBeat = startBeat;
_endBeat = endBeat;
_angle = angle;
_persistCamera = persistCamera;
InitializeTargetCamera();
}

Expand Down Expand Up @@ -104,6 +108,9 @@ private void LateUpdate()
return;
}

if (_persistCamera)
RebindCameraIfNeeded();

var currentBeat = _jukebox.CurrentBeat;
if (currentBeat >= _endBeat)
{
Expand Down Expand Up @@ -134,6 +141,17 @@ private void InitializeTargetCamera()
_initialized = true;
}

private void RebindCameraIfNeeded()
{
Camera? camera = EffectRuntimeController.ResolveEffectCamera(_loader);
if (camera is null || _targetTransform == camera.transform)
return;

ResetCameraTransform();
_targetTransform = camera.transform;
_initialLocalRotation = _targetTransform.localRotation;
}

private void ResetCameraTransform()
{
if (_targetTransform is null)
Expand Down
26 changes: 24 additions & 2 deletions BopVisualEffects/Effects/ColorTint/ColorTintEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public MixtapeEventTemplate CreateTemplate(string pluginGuid)
properties = new Dictionary<string, object>
{
["color"] = new MixtapeEventTemplates.ColorField(new Color(1.0f, 0.0f, 0.0f, 0.25f)),
["persist_camera"] = false,
["ease_in"] = true,
["ease_out"] = true
}
Expand All @@ -45,6 +46,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
var log = ClassLogger.GetForClass<ColorTintEffect>();
var durationBeats = Mathf.Max(0.01f, entity.length);
var color = entity.GetColor("color");
var persist = entity.GetBool("persist_camera", false);
var easeIn = entity.GetBool("ease_in", true);
var easeOut = entity.GetBool("ease_out", true);
var startBeat = entity.beat;
Expand All @@ -57,7 +59,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
void SpawnAction()
{
EffectRuntimeController.Instance.SpawnRunner<ColorTintRunner>(runner =>
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, color, easeIn, easeOut));
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, color, persist, easeIn, easeOut));
}
}

Expand All @@ -70,19 +72,22 @@ private sealed class ColorTintRunner : MonoBehaviour
private MixtapeLoaderCustom? _loader;
private JukeboxScript? _jukebox;
private ColorTintOverlay? _overlay;
private Camera? _camera;
private bool _persistCamera;
private bool _easeIn;
private bool _easeOut;

/// <summary>
/// Initializes this runner with effect parameters.
/// </summary>
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, Color color, bool easeIn, bool easeOut)
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, Color color, bool persistCamera, bool easeIn, bool easeOut)
{
_loader = loader;
_jukebox = jukebox;
_startBeat = startBeat;
_endBeat = endBeat;
_color = new Color(Mathf.Clamp01(color.r), Mathf.Clamp01(color.g), Mathf.Clamp01(color.b), Mathf.Clamp01(color.a));
_persistCamera = persistCamera;
_easeIn = easeIn;
_easeOut = easeOut;
InitializeOverlay();
Expand Down Expand Up @@ -112,6 +117,9 @@ private void LateUpdate()
return;
}

if (_persistCamera)
RebindOverlayIfNeeded();

var currentBeat = _jukebox.CurrentBeat;
if (currentBeat >= _endBeat)
{
Expand Down Expand Up @@ -139,6 +147,7 @@ private void InitializeOverlay()
return;

_overlay = camera.gameObject.AddComponent<ColorTintOverlay>();
_camera = camera;
_overlay.SetColor(_color);
_initialized = true;
}
Expand All @@ -151,6 +160,19 @@ private void RemoveOverlay()
}

_overlay = null;
_camera = null;
}

private void RebindOverlayIfNeeded()
{
Camera? camera = EffectRuntimeController.ResolveEffectCamera(_loader);
if (camera is null || _camera == camera)
return;

RemoveOverlay();
_overlay = camera.gameObject.AddComponent<ColorTintOverlay>();
_camera = camera;
_overlay.SetColor(_color);
}
}

Expand Down
26 changes: 24 additions & 2 deletions BopVisualEffects/Effects/Fog/FogEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public MixtapeEventTemplate CreateTemplate(string pluginGuid)
{
["color"] = new MixtapeEventTemplates.ColorField(new Color(0.8f, 0.8f, 0.9f, 0.6f)),
["height"] = 0.5f,
["persist_camera"] = false,
["ease_in"] = true,
["ease_out"] = true
}
Expand All @@ -47,6 +48,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
var durationBeats = Mathf.Max(0.01f, entity.length);
var color = entity.GetColor("color");
var height = entity.GetFloat("height");
var persist = entity.GetBool("persist_camera", false);
var easeIn = entity.GetBool("ease_in", true);
var easeOut = entity.GetBool("ease_out", true);
var startBeat = entity.beat;
Expand All @@ -59,7 +61,7 @@ public bool TrySchedule(Entity entity, MixtapeLoaderCustom loader)
void SpawnAction()
{
EffectRuntimeController.Instance.SpawnRunner<FogRunner>(runner =>
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, color, height, easeIn, easeOut));
runner.Initialize(loader, loader.jukebox, startBeat, endBeat, color, height, persist, easeIn, easeOut));
}
}

Expand All @@ -73,20 +75,23 @@ private sealed class FogRunner : MonoBehaviour
private MixtapeLoaderCustom? _loader;
private JukeboxScript? _jukebox;
private FogOverlay? _overlay;
private Camera? _camera;
private bool _persistCamera;
private bool _easeIn;
private bool _easeOut;

/// <summary>
/// Initializes this runner with effect parameters.
/// </summary>
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, Color color, float height, bool easeIn, bool easeOut)
public void Initialize(MixtapeLoaderCustom loader, JukeboxScript? jukebox, float startBeat, float endBeat, Color color, float height, bool persistCamera, bool easeIn, bool easeOut)
{
_loader = loader;
_jukebox = jukebox;
_startBeat = startBeat;
_endBeat = endBeat;
_color = new Color(Mathf.Clamp01(color.r), Mathf.Clamp01(color.g), Mathf.Clamp01(color.b), Mathf.Clamp01(color.a));
_height = Mathf.Clamp01(height);
_persistCamera = persistCamera;
_easeIn = easeIn;
_easeOut = easeOut;
InitializeOverlay();
Expand Down Expand Up @@ -116,6 +121,9 @@ private void LateUpdate()
return;
}

if (_persistCamera)
RebindOverlayIfNeeded();

var currentBeat = _jukebox.CurrentBeat;
if (currentBeat >= _endBeat)
{
Expand Down Expand Up @@ -143,6 +151,7 @@ private void InitializeOverlay()
return;

_overlay = camera.gameObject.AddComponent<FogOverlay>();
_camera = camera;
_overlay.SetParams(_color, _height);
_initialized = true;
}
Expand All @@ -155,6 +164,19 @@ private void RemoveOverlay()
}

_overlay = null;
_camera = null;
}

private void RebindOverlayIfNeeded()
{
Camera? camera = EffectRuntimeController.ResolveEffectCamera(_loader);
if (camera is null || _camera == camera)
return;

RemoveOverlay();
_overlay = camera.gameObject.AddComponent<FogOverlay>();
_camera = camera;
_overlay.SetParams(_color, _height);
}
}

Expand Down
Loading
Loading