Skip to content

Commit a0ec780

Browse files
committed
slings: Make coil arm primitive-independent.
1 parent cdb618c commit a0ec780

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

VisualPinball.Unity/VisualPinball.Unity.Editor/VPT/Surface/SlingshotInspector.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class SlingshotInspector : ItemInspector
3030
private SerializedProperty _animationDurationProperty;
3131
private SerializedProperty _animationCurveProperty;
3232
private SerializedProperty _coilArmProperty;
33-
private SerializedProperty _coilArmAngleProperty;
33+
private SerializedProperty _coilArmEndAngleProperty;
34+
private SerializedProperty _coilArmStartAngleProperty;
35+
private SerializedProperty _coilArmRotationAxis;
3436

3537
protected override MonoBehaviour UndoTarget => target as MonoBehaviour;
3638

@@ -44,7 +46,9 @@ protected override void OnEnable()
4446
_rubberOffProperty = serializedObject.FindProperty(nameof(SlingshotComponent.RubberOff));
4547
_rubberOnProperty = serializedObject.FindProperty(nameof(SlingshotComponent.RubberOn));
4648
_coilArmProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArm));
47-
_coilArmAngleProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmAngle));
49+
_coilArmStartAngleProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmStartAngle));
50+
_coilArmEndAngleProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmEndAngle));
51+
_coilArmRotationAxis = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmRotationAxis));
4852
_animationDurationProperty = serializedObject.FindProperty(nameof(SlingshotComponent.AnimationDuration));
4953
_animationCurveProperty = serializedObject.FindProperty(nameof(SlingshotComponent.AnimationCurve));
5054
}
@@ -66,7 +70,9 @@ public override void OnInspectorGUI()
6670

6771
EditorGUILayout.Space(10f);
6872
PropertyField(_coilArmProperty, "Coil Arm");
69-
PropertyField(_coilArmAngleProperty, "Arm Angle");
73+
PropertyField(_coilArmStartAngleProperty, "Start Angle");
74+
PropertyField(_coilArmEndAngleProperty, "End Angle");
75+
PropertyField(_coilArmRotationAxis, "Rotation Axis");
7076

7177
EditorGUILayout.Space(10f);
7278
PropertyField(_animationDurationProperty, "Animation Duration");

VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Rock.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ private static void SetupLeftSlingshot(GameObject go)
152152
ss.SlingshotSurface = go.GetComponent<SurfaceColliderComponent>();
153153
ss.RubberOff = playfieldGo.transform.Find("Rubbers/LeftSling1").GetComponent<RubberComponent>();
154154
ss.RubberOn = playfieldGo.transform.Find("Rubbers/LeftSling4").GetComponent<RubberComponent>();
155-
ss.CoilArm = playfieldGo.transform.Find("Primitives/Lemk").GetComponent<PrimitiveComponent>();
156-
ss.CoilArmAngle = 22f;
155+
ss.CoilArm = playfieldGo.transform.Find("Primitives/Lemk").gameObject;
156+
ss.CoilArmEndAngle = 22f;
157157

158158
EditorUtility.SetDirty(ssGo);
159159
PrefabUtility.RecordPrefabInstancePropertyModifications(ss);
@@ -173,8 +173,8 @@ private static void SetupRightSlingshot(GameObject go)
173173
ss.SlingshotSurface = go.GetComponent<SurfaceColliderComponent>();
174174
ss.RubberOff = playfieldGo.transform.Find("Rubbers/RightSling1").GetComponent<RubberComponent>();
175175
ss.RubberOn = playfieldGo.transform.Find("Rubbers/RightSling3").GetComponent<RubberComponent>();
176-
ss.CoilArm = playfieldGo.transform.Find("Primitives/Remk").GetComponent<PrimitiveComponent>();
177-
ss.CoilArmAngle = 22f;
176+
ss.CoilArm = playfieldGo.transform.Find("Primitives/Remk").gameObject;
177+
ss.CoilArmEndAngle = 22f;
178178

179179
EditorUtility.SetDirty(ssGo);
180180
PrefabUtility.RecordPrefabInstancePropertyModifications(ss);

VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SlingshotComponent.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
using Unity.Entities;
2323
using Unity.Mathematics;
2424
using UnityEngine;
25+
using UnityEngine.Serialization;
2526
using VisualPinball.Engine.Math;
2627
using VisualPinball.Engine.VPT.Rubber;
2728
using VisualPinball.Engine.Game.Engines;
2829

2930
namespace VisualPinball.Unity
3031
{
32+
public enum Axis
33+
{
34+
X, Y, Z
35+
}
36+
3137
[AddComponentMenu("Visual Pinball/Game Item/Slingshot")]
3238
public class SlingshotComponent : MonoBehaviour, IMeshComponent, IMainRenderableComponent, IRubberData, ISwitchDeviceComponent
3339
{
@@ -41,11 +47,19 @@ public class SlingshotComponent : MonoBehaviour, IMeshComponent, IMainRenderable
4147
public RubberComponent RubberOff;
4248

4349
[Tooltip("Reference to the arm attached to the coil. Rotates around X.")]
44-
public PrimitiveComponent CoilArm;
50+
public GameObject CoilArm;
4551

52+
[Range(-180f, 180f)]
53+
[Tooltip("Angle of the coil arm when off.")]
54+
public float CoilArmStartAngle;
55+
56+
[FormerlySerializedAs("CoilArmAngle")]
4657
[Range(-180f, 180f)]
4758
[Tooltip("Angle of the coil arm when on.")]
48-
public float CoilArmAngle;
59+
public float CoilArmEndAngle;
60+
61+
[Tooltip("Which axis to rotate.")]
62+
public Axis CoilArmRotationAxis;
4963

5064
[Min(0f)]
5165
[Tooltip("Total duration of the animation in milliseconds.")]
@@ -174,8 +188,18 @@ public void RebuildMeshes()
174188
}
175189

176190
if (CoilArm) {
177-
CoilArm.Rotation.x = CoilArmAngle * Position;
178-
CoilArm.UpdateTransforms();
191+
var currentRot = CoilArm.transform.rotation.eulerAngles;
192+
switch (CoilArmRotationAxis) {
193+
case Axis.X:
194+
CoilArm.transform.rotation = Quaternion.Euler(CoilArmStartAngle + CoilArmEndAngle * Position, currentRot.y, currentRot.z);
195+
break;
196+
case Axis.Y:
197+
CoilArm.transform.rotation = Quaternion.Euler(currentRot.x, CoilArmStartAngle + CoilArmEndAngle * Position, currentRot.z);
198+
break;
199+
case Axis.Z:
200+
CoilArm.transform.rotation = Quaternion.Euler(currentRot.x, currentRot.y, CoilArmStartAngle + CoilArmEndAngle * Position);
201+
break;
202+
}
179203
}
180204
}
181205

0 commit comments

Comments
 (0)