You can programm your own logics in C# or you can use with Unity2021 Visual Scripting (which we will officially support soon). But in quite a lot of cases writing your own Script and even Visual Scripting is not needed or to complicated. You can use the very simple LogicStep visual programming included in Game4Automation Professional)
With Logicsteps you can easily create a sequence of production steps without connected PLC’s or just to simulate your process. Included functions are the control of drives, sensors and Boolean signals.
There are several predefined logics that can be used. It is also possible to define user-defined logics. The following chapter describes the available logics and the way to define your own logic.
To use the logic steps, add an empty object. The steps are then attached to this object as a component. The order of the attached components determines the order in which the steps are executed. You can use drag and drop to change the sequence.
The sequence of Logic steps start automatically when simulation starts. To block a logic step sequence you can insert at the first position a blocking logic step, e.g. for waiting for a signal. If the last step in a sequence is reached automatically the first step is started again.
If you parallel running logics you must define multiple logic steps on separated game objects. You can start another step by setting signals in waiting on this signals in the parallel logic step sequence.
For each step it is optional to define a unique descriptive name. This is helpful for orientation within the sequence. For the Logic Step JumpOnSignal it is necessary to have this names.
Logic steps can be blocking and non blocking. Blocking means, that the step is waiting until a condition is reached, e.g. a Sensor is occupied or a Drive reached a certain position. Non blocking steps are done in 0 time (in the same fixed update cycle) and the next step is directly started.
When one logic step is attached to a game object the scene menu provides a quick access to all logic steps. Another possibility to select a logic step is available under the menu item game4automation/AddComponent/Logicstep or to use add component in the inspector. The name of all logic steps begins with LogicStep.
Here you can set a specific delay in seconds. The step provides also a progress bar which is updated during simulation.
In this step you let a drive move to a certain position. The value is specified in mm. If you select relative, the defined movement is added to the current position of the drive. The progress is visualized within the element. The step is blocking until the drives reaches the destination.
SetSignalBool (non blocking)
A specific bool signal is set to true or false.
StartDriveSpeed (non blocking)
In this step, the speed of a drive is set. This allows you to start a drive. If the speed is set to 0, the drive stops. With a positive value, the drive moves forward. A negative speed leads to a backward movement.
StartDriveTo (non blocking)
In this step you let a drive move to a certain position. The value is specified in mm. If you select relative, the defined movement is added to the current position of the drive. If you want to wait in a certain step on this drive, you can use WaitForDrivesAtTarget. You can use this for example to start a parallel movement of two drives.
Stop each action until the specified drives have reached their destination.
This step is used to wait for a specific sensor. Use the “Wait for occupied” check box to define which sensor state triggers the step.
JumpOnSignal (non blocking)
Depending on the defined signal, you can jump to the selected logic step.
If the currently available logic steps do not provide a function you need, you can implement your own logic step.
To do this, create a new script file in the logicsteps folder. Your user class must be of type LogicStep.
Here is an example of an LogicStep:
public class LogicStep_WaitForSensor: LogicStep
If you develop your own LogicStep you need to inherit from the base class LogicStep.
You need to implement the following methods in you own custom LogicStep:
protected new bool NonBlocking
returns a true if a LogicStep is non blocking. This will hide the progress bar.
protected override void OnStarted
You implement your logic in this method. This method is called automatically as soon as the step before is finished. If you LogicStep is non blocking your Method needs to finish by calling NextStep()
If your method is non blocking you need to implement additionally an FixedUpdate(). In your fixed update you check your conditions and as soon as your custom Step is finished you call NextStep() in fixed update.
You can check with the variable StepActive if the Step is currently active (Started). This variable is automatically managed by the base class.
If you need to implement your own Start() method, you must call base.Start() in your new Start method.
Displaying the State (Progress bar)
There is a public variable of type float State which is the setting the progress bar display. You can use values between 0 and 100. You should set this variable in blocking logic steps.