Skip to main content

Script Programming Reference

Note

A reference for all functions available is listed below. The Script Code must be programmed using the C# language.

EditorUtils Object Methods

The EditorUtils Object provides some tools in order to customize your Code.

void ShowText(string txt);

  • Description: Shows text in the status tool bar, useful for debug purposes.
  • Example:
EditorUtils.ShowText("Example text");

void PlayLoopSound(string clip, float volume);

  • Description: Plays the clip from the media library, with volume float (0 to 1), and repeats in loop mode.
  • Example:
EditorUtils.PlayLoopSound("Alarm", 0.6f);

void PlaySingleSound(string clip, float volume);

  • Description: Plays the clip from the sound library, with volume float (0 to 1).
  • Example:
EditorUtils.PlaySingleSound("PneumaticCyl", 1f);

void StopSound();

  • Description: Stops the current playing clip.
  • Example:
EditorUtils.StopSound();

float CollisionDistance(Vector3 position, Vector3 target, float distance);

  • Description: Returns the collision distance between any component and the point position pointing in a target direction.
  • Example:
float dist = EditorUtils.CollisionDistance(Vector3.one, Vector3.down * 2);

void SetCursor(int cursorType);

  • Description: Displays different mouse pointer cursor (useful to indicate actions over components).
    • 0: Default
    • 1: Red Cross
    • 2: Blue Cross
    • 3: Open Hand
    • 4: Closed Hand
    • 5: Finger Hand
    • 6: Selected
  • Example:
EditorUtils.SetCursor(1);

Constants

int Screen.width

  • Description: Returns the current screen width.
  • Example:
int screenWidth = Screen.width;

int Screen.height

  • Description: Returns the current screen height.
  • Example:
int screenHeight = Screen.height;

string Application.dataPath();

  • Description: Returns the path where Machines Simulator Editor is installed.
  • Example:
string path = Application.dataPath();

Time Functions

Some useful functions to help in your machine program:

float Time.deltaTime

  • Description: Returns a compensation factor in order to obtain the same rate regardless of the system.
Warning

This function must be called inside the Main() method. It provides the time between the current and previous frame.

  • Example:
float movement = 5.0f * Time.deltaTime;

float Time.fixedDeltaTime

  • Description: Returns a compensation factor in order to obtain the same rate regardless of the system.
Important

This function must be called inside the Physics() method because it takes into account at which physics fixed frame rate updates the logic.

  • Example:
float movement = speed * Time.fixedDeltaTime;