Show / Hide Table of Contents

Class ModBlockBehaviour

Base class for all custom behaviours attached to modded blocks by the mod loader. This includes BlockScripts as well as the behaviour of custom modules.

Inheritance
Object
ModBlockBehaviour
BlockScript
BlockModuleBehaviour<TModule>
Namespace: Modding
Assembly: Assembly-CSharp.dll
Syntax
public class ModBlockBehaviour : MonoBehaviour

Constructors

ModBlockBehaviour()

Declaration
public ModBlockBehaviour()

Properties

BlockBehaviour

The BlockBehaviour object for this block.

Declaration
public BlockBehaviour BlockBehaviour { get; }
Property Value
Type Description
BlockBehaviour

BlockId

The current effective ID of this block.

Declaration
public int BlockId { get; }
Property Value
Type Description
Int32

CanFlip

Whether this block has specified that it can flip.

Declaration
public bool CanFlip { get; }
Property Value
Type Description
Boolean

DirectionArrow

Declaration
public Transform DirectionArrow { get; }
Property Value
Type Description
UnityEngine.Transform

EmulatesAnyKeys

Whether the block itself is capable of emulating keys.

NOT whether it is currently emulating any.

Make sure to override this to return true if you use the EmulateKeys method.

Declaration
public virtual bool EmulatesAnyKeys { get; }
Property Value
Type Description
Boolean

Flipped

Whether the block is currently flipped from its default.

Declaration
public bool Flipped { get; }
Property Value
Type Description
Boolean

HasBurnedOut

Whether this block was on fire and is now burned out.

Declaration
public bool HasBurnedOut { get; }
Property Value
Type Description
Boolean

HasRigidbody

Whether this block has a Rigidbody attached.

Declaration
public bool HasRigidbody { get; }
Property Value
Type Description
Boolean

IsBurning

Whether this block is currently on fire.

Declaration
public bool IsBurning { get; }
Property Value
Type Description
Boolean

IsDestroyed

Whether this block has been destroyed.

Declaration
public bool IsDestroyed { get; }
Property Value
Type Description
Boolean

IsFrozen

Whether this block has been frozen.

Declaration
public bool IsFrozen { get; }
Property Value
Type Description
Boolean

IsSimulating

Whether the block is currently part of the simulation.

Declaration
public bool IsSimulating { get; }
Property Value
Type Description
Boolean

IsStripped

Whether this instance of the block is a stripped version.

Declaration
public bool IsStripped { get; }
Property Value
Type Description
Boolean

Machine

The machine this block is a part of.

Declaration
public PlayerMachine Machine { get; }
Property Value
Type Description
PlayerMachine

MainVis

The object containing the main visuals for this block.

Declaration
public Transform MainVis { get; }
Property Value
Type Description
UnityEngine.Transform

Renderer

Main Renderer of this block.

Declaration
public Renderer Renderer { get; }
Property Value
Type Description
UnityEngine.Renderer

Rigidbody

Rigidbody attached to this block, if any.

Declaration
public Rigidbody Rigidbody { get; }
Property Value
Type Description
UnityEngine.Rigidbody

ShowDebugVisuals

Value of the Debug element of the block in the XML definition.

Declaration
public bool ShowDebugVisuals { get; }
Property Value
Type Description
Boolean

SimPhysics

Whether this instance of the block script should handle simulation physics.

Declaration
public bool SimPhysics { get; }
Property Value
Type Description
Boolean

VisualController

The BlockVisualController handling this block.

Declaration
public BlockVisualController VisualController { get; }
Property Value
Type Description
BlockVisualController

Methods

AddColourSlider(MColourSlider)

Registers a colour slider. Needs to be called in the SafeAwake() method.

This will register this slider for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MColourSlider AddColourSlider(MColourSlider slider)
Parameters
Type Name Description
MColourSlider slider

Slider to register

Returns
Type Description
MColourSlider

The slider registered

AddColourSlider(String, String, Color, Boolean)

Registers a colour slider. Needs to be called in the SafeAwake() method.

This will register this slider for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MColourSlider AddColourSlider(string displayName, string key, Color defaultValue, bool snapColors)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

UnityEngine.Color defaultValue

Default value

Boolean snapColors

Whether to automatically snap to the closest predefined colour.

Returns
Type Description
MColourSlider

The slider registered

AddCustom<T>(MCustom<T>)

Registers a custom mapper type. Needs to be called in the SafeAwake() method.

This will register this mapper type for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MCustom<T> AddCustom<T>(MCustom<T> custom)
Parameters
Type Name Description
MCustom<T> custom

Mapper type to register

Returns
Type Description
MCustom<T>

The mapper type registered

Type Parameters
Name Description
T

AddEmulatorKey(String, String, KeyCode)

Registers an emulation key. Needs to be called in the SafeAwake() method.

This will register this key for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MKey AddEmulatorKey(string displayName, string key, KeyCode defaultKey)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

UnityEngine.KeyCode defaultKey

Default key code

Returns
Type Description
MKey

The key registered

AddKey(MKey)

Registers a key. Needs to be called in the SafeAwake() method.

This will register this key for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MKey AddKey(MKey key)
Parameters
Type Name Description
MKey key

Key to register

Returns
Type Description
MKey

The key registered

AddKey(String, String, KeyCode)

Registers a key. Needs to be called in the SafeAwake() method.

This will register this key for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MKey AddKey(string displayName, string key, KeyCode defaultKey)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

UnityEngine.KeyCode defaultKey

Default key code

Returns
Type Description
MKey

The key registered

AddLimits(MLimits)

Registers a limit. Needs to be called in the SafeAwake() method.

This will register this limit for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MLimits AddLimits(MLimits limits)
Parameters
Type Name Description
MLimits limits

Limits to register

Returns
Type Description
MLimits

The limits registered

AddLimits(String, String, Single, Single, Single, FauxTransform)

Registers a limit. Needs to be called in the SafeAwake() method.

This will register this limit for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MLimits AddLimits(string displayName, string key, float defaultMin, float defaultMax, float highestAngle, FauxTransform iconInfo)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Single defaultMin

Default min angle

Single defaultMax

Default max angle

Single highestAngle

The highest angle allowed

FauxTransform iconInfo

The orientation and position of the icon

Returns
Type Description
MLimits

The limits registered

AddLimits(String, String, Single, Single, Single, FauxTransform, ILimitsDisplay)

Registers a limit. Needs to be called in the SafeAwake() method.

This will register this limit for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MLimits AddLimits(string displayName, string key, float defaultMin, float defaultMax, float highestAngle, FauxTransform iconInfo, ILimitsDisplay limitsDisplay)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Single defaultMin

Default min angle

Single defaultMax

Default max angle

Single highestAngle

The highest angle allowed

FauxTransform iconInfo

The orientation and position of the icon

ILimitsDisplay limitsDisplay

Custom ILimitsDisplay handler to use instead of the default one

Returns
Type Description
MLimits

The limits registered

AddMenu(MMenu)

Registers a menu. Needs to be called in the SafeAwake() method.

This will register this menu for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MMenu AddMenu(MMenu menu)
Parameters
Type Name Description
MMenu menu

Menu to register

Returns
Type Description
MMenu

The menu registered

AddMenu(String, Int32, List<String>, Boolean)

Registers a menu. Needs to be called in the SafeAwake() method.

This will register this menu for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MMenu AddMenu(string key, int defaultIndex, List<string> items, bool footerMenu = false)
Parameters
Type Name Description
String key

Key used for saving. Changing this breaks existing save files

Int32 defaultIndex

Default selection

List<String> items

Available options

Boolean footerMenu

Whether to display this menu at the bottom

Returns
Type Description
MMenu

The menu registered

AddSlider(MSlider)

Registers a slider. Needs to be called in the SafeAwake() method.

This will register this slider for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MSlider AddSlider(MSlider slider)
Parameters
Type Name Description
MSlider slider

Slider to register

Returns
Type Description
MSlider

The slider registered

AddSlider(String, String, Single, Single, Single)

Registers a slider. Needs to be called in the SafeAwake() method.

This will register this slider for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MSlider AddSlider(string displayName, string key, float defaultValue, float min, float max)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Single defaultValue

Default value

Single min

Minimum value

Single max

Maximum value

Returns
Type Description
MSlider

The slider registered

AddSliderUnclamped(String, String, Single, Single, Single)

Registers an unclamped slider. Needs to be called in the SafeAwake() method.

The slider's range will be determined by the min and max arguments but, unlike with AddSlider, it is possible to type in numbers outside that range.

This will register this slider for automatically saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MSlider AddSliderUnclamped(string displayName, string key, float defaultValue, float min, float max)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Single defaultValue

Default value

Single min

Minimum slider value

Single max

Maximum slider value

Returns
Type Description
MSlider

The slider registered

AddTeam(MTeam)

Registers a team picker. Needs to be called in the SafeAwake() method.

This will register this team picker for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MTeam AddTeam(MTeam team)
Parameters
Type Name Description
MTeam team

Team picker to register

Returns
Type Description
MTeam

The team picker registered

AddTeam(String, String, MPTeam)

Registers a team picker. Needs to be called in the SafeAwake() method.

This will register this team picker for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MTeam AddTeam(string displayName, string key, MPTeam defaultTeam)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

MPTeam defaultTeam

Default team

Returns
Type Description
MTeam

The team picker registered

AddText(MText)

Registers a text setting. Needs to be called in the SafeAwake() method.

This will register this text setting for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MText AddText(MText text)
Parameters
Type Name Description
MText text

Text setting to register

Returns
Type Description
MText

The text setting registered

AddText(String, String, String)

Registers a text setting. Needs to be called in the SafeAwake() method.

This will register this text setting for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MText AddText(string displayName, string key, string defaultText)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

String defaultText

Default text

Returns
Type Description
MText

The text setting registered

AddToggle(MToggle)

Registers a toggle. Needs to be called in the SafeAwake() method.

This will register this toggle for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MToggle AddToggle(MToggle toggle)
Parameters
Type Name Description
MToggle toggle

Toggle to register

Returns
Type Description
MToggle

The toggle registered

AddToggle(String, String, Boolean)

Registers a toggle. Needs to be called in the SafeAwake() method.

This will register this toggle for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MToggle AddToggle(string displayName, string key, bool defaultValue)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Boolean defaultValue

Default value

Returns
Type Description
MToggle

The toggle registered

AddToggle(String, String, String, Boolean)

Registers a toggle. Needs to be called in the SafeAwake() method.

This will register this toggle for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MToggle AddToggle(string displayName, string key, string tooltipText, bool defaultValue)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

String tooltipText

Text to appear in tooltip when hovering over the toggle

Boolean defaultValue

Default value

Returns
Type Description
MToggle

The toggle registered

AddValue(MValue)

Registers a float value holder. Needs to be called in the SafeAwake() method.

This will register this value holder for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MValue AddValue(MValue valueHolder)
Parameters
Type Name Description
MValue valueHolder

Value holder to register

Returns
Type Description
MValue

The value holder registered

AddValue(String, String, Single)

Registers a float value holder. Needs to be called in the SafeAwake() method.

This will register this value holder for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MValue AddValue(string displayName, string key, float defaultValue)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Single defaultValue

Default value

Returns
Type Description
MValue

The value holder registered

AddValue(String, String, Single, Single, Single)

Registers a float value holder. Needs to be called in the SafeAwake() method.

This will register this value holder for automatic saving and loading in the LoadMapperValues and SaveMapperValues methods.

Declaration
public MValue AddValue(string displayName, string key, float defaultValue, float min, float max)
Parameters
Type Name Description
String displayName

Name displayed in block mapper

String key

Key used for saving. Changing this breaks existing save files

Single defaultValue

Default value

Single min

Minimum value

Single max

Maximum value

Returns
Type Description
MValue

The value holder registered

BuildingFixedUpdate()

Like BuildingUpdate but called every FixedUpdate.

Declaration
public virtual void BuildingFixedUpdate()

BuildingLateUpdate()

Like BuildingUpdate but called every LateUpdate.

Declaration
public virtual void BuildingLateUpdate()

BuildingUpdate()

Called every frame while in build mode.

MP: Called on the server and all clients, on each block that is part of a machine in build mode.

Declaration
public virtual void BuildingUpdate()

EmulateKeys(MKey[], MKey, Boolean)

Starts or stops key emulation of an MKey.

You need to override EmulatesAnyKeys to return true to use this.

To stop problematic behaviour with block activating themselves we reference the keys the block activates with itself to the emulation code so it doesn't emulate itself. Hereby avoiding infinite loops.

Additionally this shouldn't be called every frame, simply it should be called once when emulation starts and when it stops. Make sure emulation is stopped when the block is disabled.

Declaration
public void EmulateKeys(MKey[] activationKeys, MKey emulateKey, bool emulate)
Parameters
Type Name Description
MKey[] activationKeys

They MKeys this block potentially uses for activation

MKey emulateKey

The MKey to emulate (i.e. what key to emulate)

Boolean emulate

Set to true to start and false to stop

KeyEmulationUpdate()

Handle emulated key input here. Called on a FixedUpdate, but not necessarily every fixed update.

Called on every instance. Not called if no blocks (or other code) emulating any keys are present.

See the Handling Key Emulation section in the block creation modding documentation for details.

Declaration
public virtual void KeyEmulationUpdate()

OnBlockPlaced()

Called when a block is placed, on that block's instance.

MP: Called on the server and all clients.

Declaration
public virtual void OnBlockPlaced()

OnLoad(XDataHolder)

Declaration
public virtual void OnLoad(XDataHolder data)
Parameters
Type Name Description
XDataHolder data

OnPrefabCreation()

Called on the prefab once it's been created and fully initialized. This happens when the first level that is not a menu is loaded.

This is also called on the stripped block prefab, right after the call on the normal one.

Use this to modify the prefab if you can't achieve what you want using the options exposed via the XML file.

Declaration
public virtual void OnPrefabCreation()

OnReloadAmmo(ref Int32, AmmoType, Boolean, Boolean)

Override to make it possible to reload the block using the logic system.

The parameters correspond directly to the options for the reload event in the UI.

Declaration
public virtual void OnReloadAmmo(ref int units, AmmoType type, bool setAmmo, bool eachBlock)
Parameters
Type Name Description
Int32 units

Number entered in the UI. Should be the number of shots where applicable. The amount of ammo "used up" by this block should be subtracted from this.

AmmoType type

Ammunition type, set with the icon in the UI.

Boolean setAmmo

True if the equal sign is selected, false if the addition sign is selected.

Boolean eachBlock

True if "each weapon" is selected, false if "machine" is selected.

OnSave(XDataHolder)

Declaration
public virtual void OnSave(XDataHolder data)
Parameters
Type Name Description
XDataHolder data

OnSimulateCollisionEnter(Collision)

Simulation-only wrapper around OnCollisionEnter.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateCollisionEnter(Collision collision)
Parameters
Type Name Description
UnityEngine.Collision collision

OnSimulateCollisionExit(Collision)

Simulation-only wrapper around OnCollisionExit.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateCollisionExit(Collision collision)
Parameters
Type Name Description
UnityEngine.Collision collision

OnSimulateCollisionStay(Collision)

Simulation-only wrapper around OnCollisionStay.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateCollisionStay(Collision collision)
Parameters
Type Name Description
UnityEngine.Collision collision

OnSimulateParticleCollision(GameObject)

Simulation-only wrapper around OnParticleCollision.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateParticleCollision(GameObject other)
Parameters
Type Name Description
UnityEngine.GameObject other

OnSimulateStart()

Called on the simulation clone of the block when the simulation was started.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateStart()

OnSimulateStop()

Called on the simulation clone of the block when the simulation is stopped.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateStop()

OnSimulateTriggerEnter(Collider)

Simulation-only wrapper around OnTriggerEnter.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateTriggerEnter(Collider collision)
Parameters
Type Name Description
UnityEngine.Collider collision

OnSimulateTriggerExit(Collider)

Simulation-only wrapper around OnTriggerExit.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateTriggerExit(Collider collision)
Parameters
Type Name Description
UnityEngine.Collider collision

OnSimulateTriggerStay(Collider)

Simulation-only wrapper around OnTriggerStay.

MP: Called on the server and all clients.

Declaration
public virtual void OnSimulateTriggerStay(Collider collision)
Parameters
Type Name Description
UnityEngine.Collider collision

OnStartBurning()

Called when the block is set on fire.

MP: Called on the server and all clients.

Declaration
public virtual void OnStartBurning()

OnStopBurning(Boolean)

Called when the block stops burning.

MP: Called on the server and all clients.

Declaration
public virtual void OnStopBurning(bool doused)
Parameters
Type Name Description
Boolean doused

true if the block stopped burning because it was extinguished, false it if stopped because it burned out.

SafeAwake()

Called every time a new instance of the script is initialized, after some necessary initialization by the game was done.

Use this instead of the normal Unity Awake() method.

Declaration
public virtual void SafeAwake()

SendKeyEmulationUpdateHost()

Use this method to trigger key emulation, i.e. call EmulateKeys. Called on the same cycle as KeyEmulationUpdate, but called on all blocks before KeyEmulationUpdate and FixedUpdate are called on any blocks.

Called only on the host / the instance simulating physics.

Remember to set EmulatesAnyKeys if you want to emulate keys in a block.

See the Handling Key Emulation section in the block creation modding documentation for details.

Declaration
public virtual void SendKeyEmulationUpdateHost()

SimulateFixedUpdateAlways()

Like SimulateUpdateAlways but called every FixedUpdate.

Declaration
public virtual void SimulateFixedUpdateAlways()

SimulateFixedUpdateClient()

Like SimulateUpdateClient but called every FixedUpdate.

Declaration
public virtual void SimulateFixedUpdateClient()

SimulateFixedUpdateHost()

Like SimulateUpdateHost but called every FixedUpdate.

Declaration
public virtual void SimulateFixedUpdateHost()

SimulateLateUpdateAlways()

Like SimulateUpdateAlways but called every LateUpdate.

Declaration
public virtual void SimulateLateUpdateAlways()

SimulateLateUpdateClient()

Like SimulateUpdateClient but called every LateUpdate.

Declaration
public virtual void SimulateLateUpdateClient()

SimulateLateUpdateHost()

Like SimulateUpdateHost but called every LateUpdate.

Declaration
public virtual void SimulateLateUpdateHost()

SimulateUpdateAlways()

Called every frame while in simulation mode.

MP: Called on each instance connected (including the host).

Declaration
public virtual void SimulateUpdateAlways()

SimulateUpdateClient()

Called every frame while in simulation mode.

Not called in singleplayer.

MP: Called on every game instance receiving the simulation state from another instance, i.e. on the instances that should not simulate physics for this block. This means connected clients for each machine in global sim, as well as the server and clients for each machine in local sim on another instance.

Declaration
public virtual void SimulateUpdateClient()

SimulateUpdateHost()

Called every frame while in simulation mode.

MP: Called on the game instance that is handling physics for this block. This is the host for machines in global sim, or a client when simulating their own machine locally.

Declaration
public virtual void SimulateUpdateHost()
Back to top Generated by DocFX