// Copyright (c) 2024 Augie R. Maddox, Guavaman Enterprises. All rights reserved.
namespace Rewired.Demos.CustomPlatform {
///
/// A controller extension for this custom platform.
/// This allows supporting special features such as vibration and other custom functionality.
/// Implementing Rewired.Interfaces.IControllerVibrator allows Rewired's Controller and Player vibration function calls to work.
///
public sealed class MyPlatformControllerExtension : ControllerExtensions.CustomControllerExtension, Rewired.Interfaces.IControllerVibrator {
///
/// Constructor.
///
/// Source joystick.
public MyPlatformControllerExtension(MyPlatformInputSource.Joystick sourceJoystick) : base(new Source(sourceJoystick)) {
}
///
/// Copy constructor.
///
/// Object to copy
private MyPlatformControllerExtension(MyPlatformControllerExtension other) : base(other) {
}
///
/// Makes a shallow copy of the object.
///
/// Shallow copy of the object.
public override Controller.Extension ShallowCopy() {
return new MyPlatformControllerExtension(this);
}
// Implement IControllerVibrator interface so Rewired vibration works
public int vibrationMotorCount {
get {
return 2;
}
}
public void SetVibration(int motorIndex, float motorLevel) {
((Source)GetSource()).sourceJoystick.SetVibration(motorIndex, motorLevel);
}
public void SetVibration(int motorIndex, float motorLevel, float duration) {
((Source)GetSource()).sourceJoystick.SetVibration(motorIndex, motorLevel, duration);
}
public void SetVibration(int motorIndex, float motorLevel, bool stopOtherMotors) {
((Source)GetSource()).sourceJoystick.SetVibration(motorIndex, motorLevel, stopOtherMotors);
}
public void SetVibration(int motorIndex, float motorLevel, float duration, bool stopOtherMotors) {
((Source)GetSource()).sourceJoystick.SetVibration(motorIndex, motorLevel, duration, stopOtherMotors);
}
public float GetVibration(int motorIndex) {
return ((Source)GetSource()).sourceJoystick.GetVibration(motorIndex);
}
public void StopVibration() {
((Source)GetSource()).sourceJoystick.StopVibration();
}
class Source : Rewired.Interfaces.IControllerExtensionSource {
public readonly MyPlatformInputSource.Joystick sourceJoystick;
public Source(MyPlatformInputSource.Joystick sourceJoystick) {
this.sourceJoystick = sourceJoystick;
}
}
}
}