Fixed
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public struct ShockwaveZone
|
||||
{
|
||||
[Min(0.1f)] public float Radius;
|
||||
[Min(0f)] public float PlayerImpulse;
|
||||
[Min(0f)] public float RigidbodyImpulse;
|
||||
[Range(0f, 1f)] public float UpwardBias;
|
||||
[Min(0f)] public float CameraShakeAmplitude;
|
||||
[Min(0f)] public float CameraShakeDuration;
|
||||
[Min(0.1f)] public float CameraShakeFrequency;
|
||||
}
|
||||
|
||||
[CreateAssetMenu(
|
||||
fileName = "ShockwaveProfile",
|
||||
menuName = "FORT-BO/Effects/Shockwave Profile")]
|
||||
public sealed class ShockwaveProfile : ScriptableObject
|
||||
{
|
||||
[Tooltip("Zones are evaluated from the smallest radius to the largest.")]
|
||||
[SerializeField] private ShockwaveZone[] zones = Array.Empty<ShockwaveZone>();
|
||||
|
||||
public float MaximumRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
float maximum = 0f;
|
||||
foreach (ShockwaveZone zone in zones)
|
||||
maximum = Mathf.Max(maximum, zone.Radius);
|
||||
return maximum;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryEvaluate(float distance, out ShockwaveZone result)
|
||||
{
|
||||
result = default;
|
||||
float bestRadius = float.PositiveInfinity;
|
||||
bool found = false;
|
||||
|
||||
foreach (ShockwaveZone zone in zones)
|
||||
{
|
||||
if (distance > zone.Radius || zone.Radius >= bestRadius)
|
||||
continue;
|
||||
|
||||
result = zone;
|
||||
bestRadius = zone.Radius;
|
||||
found = true;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
for (int index = 0; index < zones.Length; index++)
|
||||
{
|
||||
ShockwaveZone zone = zones[index];
|
||||
zone.Radius = Mathf.Max(0.1f, zone.Radius);
|
||||
zone.PlayerImpulse = Mathf.Max(0f, zone.PlayerImpulse);
|
||||
zone.RigidbodyImpulse = Mathf.Max(0f, zone.RigidbodyImpulse);
|
||||
zone.CameraShakeAmplitude = Mathf.Max(0f, zone.CameraShakeAmplitude);
|
||||
zone.CameraShakeDuration = Mathf.Max(0f, zone.CameraShakeDuration);
|
||||
zone.CameraShakeFrequency = Mathf.Max(0.1f, zone.CameraShakeFrequency);
|
||||
zones[index] = zone;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user