Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardwire bumpers by default #494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BumperInspector : MainInspector<BumperData, BumperComponent>
private SerializedProperty _heightScaleProperty;
private SerializedProperty _orientationProperty;
private SerializedProperty _surfaceProperty;
private SerializedProperty _isHardwiredProperty;

protected override void OnEnable()
{
Expand All @@ -39,6 +40,7 @@ protected override void OnEnable()
_heightScaleProperty = serializedObject.FindProperty(nameof(BumperComponent.HeightScale));
_orientationProperty = serializedObject.FindProperty(nameof(BumperComponent.Orientation));
_surfaceProperty = serializedObject.FindProperty(nameof(BumperComponent._surface));
_isHardwiredProperty = serializedObject.FindProperty(nameof(BumperComponent.IsHardwired));
}

public override void OnInspectorGUI()
Expand All @@ -56,6 +58,7 @@ public override void OnInspectorGUI()
PropertyField(_heightScaleProperty, updateTransforms: true);
PropertyField(_orientationProperty, updateTransforms: true);
PropertyField(_surfaceProperty, updateTransforms: true);
PropertyField(_isHardwiredProperty, updateTransforms: false);

base.OnInspectorGUI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;
using UnityEngine;
using VisualPinball.Engine.Game.Engines;
Expand Down Expand Up @@ -53,6 +54,9 @@ public class BumperComponent : MainRenderableComponent<BumperData>,
[Tooltip("Orientation angle. Updates z rotation.")]
public float Orientation;

[Tooltip("Should the bumper coil always activate when touched by a ball? Disable to give game logic engine full control")]
public bool IsHardwired = true;

public ISurfaceComponent Surface { get => _surface as ISurfaceComponent; set => _surface = value as MonoBehaviour; }

[SerializeField]
Expand Down Expand Up @@ -100,6 +104,23 @@ private void Awake()
}
}

private void Start()
{
if (IsHardwired) {
WireMapping wireMapping = new() {
Description = $"Hardwired bumper '{name}'",
Source = SwitchSource.Playfield,
SourceDevice = this,
SourceDeviceItem = AvailableSwitches.FirstOrDefault().Id,
DestinationDevice = this,
DestinationDeviceItem = AvailableCoils.FirstOrDefault().Id,
IsDynamic = false,
};
WireDestConfig wireDestConfig = new(wireMapping.WithId());
BumperApi.AddWireDest(wireDestConfig);
}
}

#endregion

#region Wiring
Expand Down