Toggleable Upgrades - NeisesMike/VehicleFramework GitHub Wiki

Toggleable upgrades can be activated by the player. Sonar upgrades are an example.

Overview

To implement a Toggleable upgrade, implement the abstract class

VehicleFramework.UpgradeTypes.ToggleableUpgrade

That class implements ModVehicleUpgrade, with one important override:

public override QuickSlotType QuickSlotType => QuickSlotType.Toggleable;

Don't change this!

Virtual Fields

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());
}
  • RepeatRate is a length of time in seconds. Once the upgrade is activated, it will do OnRepeat every RepeatRate seconds.
  • TimeToFirstActivation is a length of time in seconds. Once the upgrade is activated, it will wait TimeToFirstActivation seconds before it invokes OnRepeat.
  • EnergyCostPerActivation is how much energy the vehicle will spend every time OnRepeat happens.
  • OnRepeat is 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);
}