Skip to content

Commit

Permalink
Make SoundTrigger fields readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkehrwald committed Dec 14, 2024
1 parent e7c5948 commit 42beab8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 35 deletions.
12 changes: 9 additions & 3 deletions VisualPinball.Unity/VisualPinball.Unity/Sound/SoundTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ namespace VisualPinball.Unity
/// can be linked to a <see cref="SoundAsset"/>. During runtime, they
/// are used to identify which sound to play.
/// </summary>
public struct SoundTrigger
public readonly struct SoundTrigger
{
/// <summary>
/// The ID of the trigger. When you change the ID of a trigger,
/// all already associated triggers will be cleared.
/// </summary>
public string Id;
public readonly string Id;

/// <summary>
/// Name of the trigger, used for display purposes only.
/// </summary>
public string Name;
public readonly string Name;

public SoundTrigger(string id, string name)
{
Id = id;
Name = name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class BumperComponent : MainRenderableComponent<BumperData>,
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundBumperHit, Name = "Bumper Hit" }
new SoundTrigger (id: SoundBumperHit, name: "Bumper Hit")
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void Awake()
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundTargetBankReset, Name = "Sound Target Bank Reset" }
new SoundTrigger (id: SoundTargetBankReset, name: "Sound Target Bank Reset" )
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public class FlipperComponent : MainRenderableComponent<FlipperData>,
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundCoilOn, Name = "Coil On" },
new SoundTrigger { Id = SoundCoilOff, Name = "Coil Off"},
new SoundTrigger { Id = SoundCoilCollision, Name = "Ball Collision" },
new SoundTrigger(id:SoundCoilOn, name: "Coil On" ),
new SoundTrigger(id:SoundCoilOff, name: "Coil Off"),
new SoundTrigger(id:SoundCoilCollision, name: "Ball Collision" ),
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down Expand Up @@ -384,7 +384,7 @@ public override Vector3 GetEditorPosition() => Surface != null

public override ItemDataTransformType EditorScaleType => ItemDataTransformType.None;

#if UNITY_EDITOR
#if UNITY_EDITOR

protected void OnDrawGizmosSelected()
{
Expand All @@ -393,7 +393,7 @@ protected void OnDrawGizmosSelected()
if (poly == null) {
return;
}

Gizmos.matrix = Matrix4x4.identity;
UnityEditor.Handles.matrix = Matrix4x4.identity;

Expand Down Expand Up @@ -423,16 +423,16 @@ protected void OnDrawGizmosSelected()
if (start == end) {
return;
}
var last = IsLeft ? arrow[0] : arrow[arrow.Count-1];
var tmpA = IsLeft ? start + 90F + 3F : end +90F - 3F;
var last = IsLeft ? arrow[0] : arrow[arrow.Count - 1];
var tmpA = IsLeft ? start + 90F + 3F : end + 90F - 3F;
var a = Quaternion.Euler(0, 0, tmpA) * new Vector3(0, -FlipperRadiusMax + 15F, height);
var b = Quaternion.Euler(0, 0, tmpA) * new Vector3(0F, -FlipperRadiusMax + 25F, height);
Gizmos.DrawLine(transform.TransformPoint(last.TranslateToWorld()), transform.TransformPoint(a.TranslateToWorld()));
Gizmos.DrawLine(transform.TransformPoint(last.TranslateToWorld()), transform.TransformPoint(b.TranslateToWorld()));
Gizmos.color = Color.white;
}

#endif
#endif

#endregion

Expand Down Expand Up @@ -562,8 +562,7 @@ internal FlipperState CreateState()

internal FlipperTricksData GetFlipperTricksData(FlipperColliderComponent colliderComponent, FlipperStaticData staticData)
{
return new FlipperTricksData
{
return new FlipperTricksData {
UseFlipperTricksPhysics = colliderComponent.useFlipperTricksPhysics,
SOSRampUp = colliderComponent.SOSRampUp,
SOSEM = colliderComponent.SOSEM,
Expand All @@ -586,8 +585,8 @@ internal FlipperTricksData GetFlipperTricksData(FlipperColliderComponent collide
LiveCatchInaccurateBounceSpeedMultiplier = colliderComponent.LiveCatchInaccurateBounceSpeedMultiplier,
LiveCatchMinimalBounceSpeedMultiplier = colliderComponent.LiveCatchMinmalBounceSpeedMultiplier,

//initialize
OriginalAngleEnd = staticData.AngleEnd,
//initialize
OriginalAngleEnd = staticData.AngleEnd,
OriginalRampUpSpeed = staticData.RampUpSpeed,
OriginalTorqueDamping = staticData.TorqueDamping,
OriginalTorqueDampingAngle = staticData.TorqueDampingAngle
Expand Down Expand Up @@ -616,7 +615,7 @@ internal FlipperStaticData GetMaterialData(FlipperColliderComponent colliderComp
}

// model inertia of flipper as that of rod of length flipper around its end
var inertia = (float) (1.0 / 3.0) * colliderComponent.Mass * (flipperRadius * flipperRadius);
var inertia = (float)(1.0 / 3.0) * colliderComponent.Mass * (flipperRadius * flipperRadius);
var localPos = transform.localPosition;

return new FlipperStaticData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ internal DropTargetState CreateState()
#region ISoundEmitter

public override SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundTargetHit, Name = "Target Drop" },
new SoundTrigger { Id = SoundTargetReset, Name = "Target Reset" },
new SoundTrigger (id: SoundTargetReset, name: "Target Reset"),
new SoundTrigger (id: SoundTargetHit, name: "Target Drop"),
};

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ public override IEnumerable<MonoBehaviour> SetData(HitTargetData data)
Size = data.Size.ToUnityVector3();

_targetType = data.TargetType;
#if UNITY_EDITOR
#if UNITY_EDITOR
var mf = GetComponent<MeshFilter>();
if (mf) {
_meshName = Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(mf.sharedMesh));
}
#endif
#endif

return updatedComponents;
}
Expand Down Expand Up @@ -199,7 +199,7 @@ public override void CopyFromObject(GameObject go)
#region ISoundEmitter

public virtual SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundTargetHit, Name = "Target Hit" },
new SoundTrigger (id: SoundTargetHit, name: "Target Hit"),
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public class KickerComponent : MainRenderableComponent<KickerData>,
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundKickerDrain, Name = "Ball Drain" },
new SoundTrigger { Id = SoundKickerBallRelease, Name = "Ball Release" },
new SoundTrigger (id: SoundKickerDrain, name: "Ball Drain"),
new SoundTrigger (id: SoundKickerBallRelease, name: "Ball Release"),
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ private float ResetScore(float score)
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundScoreMotorStart, Name = "Sound Score Motor Start" },
new SoundTrigger { Id = SoundScoreMotorStop, Name = "Sound Score Motor Stop" },
new SoundTrigger { Id = SoundScoreMotorStep, Name = "Sound Score Motor Step" }
new SoundTrigger (id: SoundScoreMotorStart, name: "Sound Score Motor Start"),
new SoundTrigger (id: SoundScoreMotorStop, name: "Sound Score Motor Stop"),
new SoundTrigger (id: SoundScoreMotorStep, name: "Sound Score Motor Step"),
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public class PlungerComponent : MainRenderableComponent<PlungerData>,
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundPlungerPull, Name = "Plunger Pull" },
new SoundTrigger { Id = SoundPlungerRelease, Name = "Plunger Release"}
new SoundTrigger (id: SoundPlungerPull, name: "Plunger Pull"),
new SoundTrigger (id: SoundPlungerRelease, name: "Plunger Release"),
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down Expand Up @@ -129,13 +129,13 @@ private void Awake()
public override void OnPlayfieldHeightUpdated() => RebuildMeshes();

public float PositionZ => SurfaceHeight(Surface, Position);

public override void UpdateTransforms()
{
base.UpdateTransforms();
transform.localScale = Physics.ScaleToWorld(1, 1, 1);
transform.localRotation = Quaternion.Euler(Physics.RotateToWorld(0f, 0f, 0f));

GetComponent<PlungerRodMeshComponent>()?.CalculateBoundingBox();
GetComponent<PlungerSpringMeshComponent>()?.CalculateBoundingBox();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public override void SetEditorPosition(Vector3 pos)
Position = ((float3)pos).xy;
}

public override ItemDataTransformType EditorRotationType{
public override ItemDataTransformType EditorRotationType {
get {
var meshComp = GetComponent<TriggerMeshComponent>();
return !meshComp || !meshComp.IsCircle ? ItemDataTransformType.None : ItemDataTransformType.OneD;
Expand All @@ -330,8 +330,8 @@ public override ItemDataTransformType EditorRotationType{
#region ISoundEmitter

public SoundTrigger[] AvailableTriggers => new[] {
new SoundTrigger { Id = SoundTriggerHit, Name = "Sound Trigger Hit" },
new SoundTrigger { Id = SoundTriggerUnhit, Name = "Sound Trigger Unhit" }
new SoundTrigger (id: SoundTriggerHit, name: "Sound Trigger Hit"),
new SoundTrigger (id: SoundTriggerUnhit, name: "Sound Trigger Unhit"),
};

public event EventHandler<SoundEventArgs> OnSound;
Expand Down

0 comments on commit 42beab8

Please sign in to comment.