Machines Simulator Object (MS) Reference
MS System & Display Methods
void MS.ShowText(string/bool/int/float/double txt)
- Description: Shows the text variable value in the status tool bar, useful for debug purposes.
void MS.Message(string text)
- Description: Shows a text message in the upper side of the screen.
void MS.Message(string text, Color background, Color textcolor)
- Description: Shows a text message in the upper side, with background and text colors passed as parameters.
void MS.EndMessage()
- Description: Removes the current message.
void MS.Message(string text, int seconds, Color background, Color textcolor)
- Description: Shows a text message in the upper side, visible during the amount of seconds passed as a parameter.
float MS.Range(float n1, float n2)
- Description: Returns a random float within
n1..n2(range is inclusive).
int MS.ParseToInt(string value) / float MS.ParseToFloat(string value)
- Description: Converts a string value to an
intor afloat.
Camera Control
Methods to manage the simulation cameras and their behavior:
void MS.ChangeFlyCam(): Changes camera to fly mode.void MS.ChangeFirstPersonCam(): Changes camera to first person.void MS.ChangeTripCam(): Changes camera to travel mode.void MS.DisableCameraMovement(): Disables system camera movement. Useful to program special behaviors.void MS.EnableCameraMovement(): The system takes back control of the camera.void MS.EnableCameraTraveling(bool v): Enables or disables camera traveling (numeric keys 1-9).Transform MS.SystemCamera: Returns the transform object reference (position, rotation, scale) of the camera.void MS.SystemCameraPosition(Vector3 pos): Places the camera in the passedVector3position (x, y, z).void MS.SystemCameraRotation(Vector3 angles): Rotates the camera to the passedVector3angles.void MS.SystemCameraPosition(int pos, float timeToArrive): Places the camera in a predefined position number and sets travel time.
Environment & Lighting
float MS.MainLightIntensity: Gets/Sets the main light intensity.bool MS.Fog: Gets/Sets whether the environment has fog.float MS.FogDensity: Gets/Sets the environment fog density.Color MS.FogColor: Gets/Sets the environment fog color.void MS.SetPlayerSize(float rad, float height): Sets the size of the player capsule.void MS.ShowFloor(bool value): Shows or hides the factory floor. Iffalse, collision is disabled.void MS.HideFactory(): Hides the factory building (Factory 1 only).void MS.SetLimits(Vector2 x, Vector2 y, Vector3 z): Sets movement limits for Factory 1 and 3.void MS.OpenGates(int gate, bool open): Opens or closes each of the 8 doors (1 to 8) in Factory 3.
WorkParts & Collisions
WorkPartLogic MS.WPList
- Description: List that contains all the current WorkPart objects created in the machine.
- Example:
EditorUtils.ShowText(MS.WPList.Count.ToString());
// Set wpt variable to the WorkPart type of the 4th workpart:
int wpt = MS.WPList[3].WorkPartType;
void MS.CreateWP(int id, Vector3 pos, Vector3 rot)
- Description: Creates a WorkPart of type
id(previously created in the editor) at the given position/rotation.
void MS.DestroyWP(WorkPartLogic wp)
- Description: Destroys the passed WorkPart object.
ComponentBase MS.Create(string compo, Vector3 pos, [Vector3 rot])
- Description: Creates the passed component name and places it in the scene.
bool MS.RayCollision(Vector3 origin, Vector3 direction, float distance)
- Description: Returns
trueif any component collides with the ray.
:::tip Tip
Overloads exist to return detection distance (out float dectDist), the collided WorkPartLogic, or the ComponentBase object.
:::
void MS.DisableCollision(Collider c1, Collider c2, bool v)
- Description: Disables or enables collisions between the two passed colliders.
User Interface (UI) Methods
Methods to create and manage dynamic UI elements:
PanelValue MS.PanelDisplay(string desc, CustomWindow cw = null)PanelButton MS.PanelButton(string text, CustomWindow cw = null)InputValue MS.InputDisplay(string desc, CustomWindow cw = null)PanelSlider MS.PanelSlider(string desc, float min, float max, float def, int anInp, CustomWindow cw = null)TextBoxArea MS.TextAreaDisplay(CustomWindow cw = null)LabelUI MS.LabelUI(string desc, CustomWindow cw = null)ImageArea MS.ImageArea(string path, CustomWindow cw = null)CustomWindow MS.CustomWindow(string desc)Label3D MS.Label3D(string text)QuadCreator MS.DynamicPlane()
UDC (User Defined Component) Values
Methods to read/write properties from Graphic Code or other components:
string GetPCVal(string udc, string id)int GetPCVal_Int(string udc, string id)float GetPCVal_Dec(string udc, string id)List<string> GetPCVal_L(string id)void SetPCVal(string id, string/int/float/bool v)
System Events
MS.PauseEvent
- Description: Fires when Pause mode is toggled.
- Example:
bool Pause = false;
public void Init() {
MS.PauseEvent += PauseEvent;
}
public void Finish() {
MS.PauseEvent -= PauseEvent;
}
private void PauseEvent(bool pause) {
Pause = pause;
}
MS.DriverEvent
- Description: Fires when the I/O communication Driver is activated or deactivated.
- Example:
bool runD = false;
public void Init() {
MS.DriverEvent += DriverEvent;
}
public void Finish() {
MS.DriverEvent -= DriverEvent;
}
private void DriverEvent(bool running) {
runD = running;
if(running)
MS.Message("Driver Connected", 10, Color.black, Color.red);
else
MS.Message("Driver Disconnected", 10, Color.yellow, Color.black);
}