-
Notifications
You must be signed in to change notification settings - Fork 7
Toggleable Upgrades
Michael Neises edited this page Oct 24, 2024
·
4 revisions
Toggleable upgrades can be activated by the player. Sonar upgrades are an example.
To implement a Toggleable upgrade, implement the abstract class
VehicleFramework.UpgradeTypes.ToggleableUpgradeThat class implements ModVehicleUpgrade, with one important override:
public override QuickSlotType QuickSlotType => QuickSlotType.Toggleable;Don't change this!
The Toggleable upgrades has only a few new fields over ModVehicleUpgrade:
public virtual float RepeatRate => 0;
public virtual float TimeToFirstActivation => 0;
public virtual float EnergyCostPerActivation => 0;
public virtual void OnRepeat(ToggleActionParams param)
{
Logger.Log("Selecting " + ClassId + " on ModVehicle: " + param.vehicle.subName.name + " in slotID: " + param.slotID.ToString());
}-
RepeatRateis a length of time in seconds. Once the upgrade is activated, it will doOnRepeateveryRepeatRateseconds. -
TimeToFirstActivationis a length of time in seconds. Once the upgrade is activated, it will waitTimeToFirstActivationseconds before it invokesOnRepeat. -
EnergyCostPerActivationis how much energy the vehicle will spend every timeOnRepeathappens. -
OnRepeatis the periodic action the upgrade will take so long as it is toggled.
Here is the definition of the ToggleActionParams struct:
public struct ToggleActionParams
{
public Vehicle vehicle;
public int slotID;
public TechType techType;
public bool active;
}It's a lot like AddActionParams, so look at the ModVehicleUpgrade guide to understand more.
Here is an example from the Sonar Module:
public override void OnRepeat(ToggleActionParams param)
{
SNCameraRoot.main.SonarPing();
FMODUWE.PlayOneShot("event:/sub/seamoth/sonar_loop", param.vehicle.transform.position, 1f);
}