Famic Unity User Manual
Famic Unity User Manual
Famic Unity User Manual
User’s Guide
Famic Technologies Inc. All rights reserved.©
REPRODUCTION
1 Introduction....................................................................................................................
2 Unity Configuration.......................................................................................................
2.1 Installation..............................................................................................................
3.1 Installation............................................................................................................
3.2.4 Variables.................................................................................................
4 Troubleshooting............................................................................................................
4.1.3 Errors......................................................................................................
4.2.2 Variables.................................................................................................
4.2.3 Connectivity............................................................................................
A Glossary..............................................................................................................................
B Index....................................................................................................................................
1 Introduction......................................................................................................................
2 Unity Configuration..........................................................................................................
2.1 Installation..............................................................................................................
3.1 Installation............................................................................................................
3.2.4 Variables.................................................................................................
4 Troubleshooting..............................................................................................................
4.1.3 Errors......................................................................................................
4.2.2 Variables.................................................................................................
4.2.3 Connectivity............................................................................................
A Glossary...............................................................................................................................
B Index....................................................................................................................................
1 Introduction......................................................................................................................
2 Unity Configuration..........................................................................................................
2.1 Installation..............................................................................................................
iv
Table of Contents
3.1 Installation............................................................................................................
3.2.4 Variables.................................................................................................
4 Troubleshooting..............................................................................................................
4.1.3 Errors......................................................................................................
4.2.2 Variables.................................................................................................
4.2.3 Connectivity............................................................................................
A Glossary...............................................................................................................................
B Index....................................................................................................................................
vi
1 Introduction
This guide is intended for users with a basic knowledge of Unity.
This guide presents the means of communication between Unity and Automation Studio™. We
present concrete examples of how to use both the URC and URS dynamic link libraries.
The acronym URC stands for UnityRemoteClient and the acronym URS stands for
UnityRemoteServer. The Automation Studio™ project acts as the client and the Unity project
acts as the server.
The URC – URS allow the exchange of information between Automation Studio™ and Unity and
form a connection between local Variables using External Variables in a JSON file.
Each External Variable essentially connects a Variable on the client side to a Variable on the
server side. Each External Variable is given a Role of either Import or Export that defines
whether their values are managed by the Client or Server.
Figure 1-1: Overview of the architecture between Unity and Automation Studio™
2.1 Installation
Make sure the Newtonsoft.Json.dll can be found is added toin the directory: C:\
ProgramData\Famic Technologies\Automation Studiodd-ons P6.X\Scriptsbin\(x64 or
x32)
Navigate into the “Unity Build” folder to find the ‘SampleProject’. This is the built
sample Unity project that must be placed into the Apps folder found at : C:\
ProgramData\Famic Technologies\3D Systems\Apps
The Sample.prx can be run from anywhere. Once the project is loaded, navigate to the
‘3D Link’ tab at the top and select ‘Show’. This will open the Unity build associated
with this project.
Press ‘Start’ in the 3D Link tab to begin the simulation and create the connection
between AS and Unity. The connection indicator in the Unity build should turn green at
this point to show that the connection was successful.
The server used for communication between Automation Studio™ and Unity is an asynchronous
TCP socket server that requires an IP address and a Port to create a connection.
If Automation Studio and the corresponding Unity build are being run on the same machine, the
IP address should remain the default ‘127.0.0.1’. If separate machines are being used, the target
ip address and port can be configured in the extcom.config file found at C:\ProgramData\Famic
Technologies\3D Systems\Apps on both machines.
Create a folder called “Prefabs” in the Assets folder of the Unity project. Import the “Menu
Canvas.prefab” file and drag it into your scene. Add the proper scripts to the game objects in the
prefab (see project example). The prefab contains a game object for the AsyncTCPSocketServer
which holds two InputField type variables whose values are used as the IP address and Port for
the TCP connection.
The server must be launched from the Unity project before the client, Automation Studio™, can
connect to it. This is achieved by calling the LaunchServer() method from the
ASyncTCPSocketServer script. This is handled automatically when a build is started or the Unity
Window is opened from within Automation Studio.
For manual control of server launch, To do this attach the LaunchServer() method to the
LaunchServerButton’s OnClick event, found within the Menu Canvas prefab.
Once the server is launched, it begins listening for an incoming connection. The server safely
quits and closes the TCP connection on application close.
Each Game Object within Unity that includes at least one Variable to be controlled by a
corresponding Variable in Automation Studio™ must include a script, which inherits from the
Item script in the dll. The script can be from anywhere in the inheritance hierarchy under Item
and does not need to be an immediate child.
Figure 2-4: Script inclusion to Unity Game Object with Item script inheritance
4
Troubleshooting
The Item script inherits from UnityEngine.MonoBehaviour, which exposes the methods Awake,
Start and Update to be overridden.
Awake() is called before Start() and after all game objects have been initialized. It is
called exactly once in the lifetime of the script. Its requirements for this module are as
follows:
[3.] Each External Variable must be added to the inherited list of External Variables
from the Item script called variables. (see Figure 23-43)
[4.] The variable Model inherited from the Item script should be set to the Game
Object that the current script is attached to. (see Figure 3-3)
Figure 2-5: Example Awake method withand required contents for communication
Start() is called on the frame when a script is enabled and right before any of the
Update() methods are called for the first time. It is called exactly once in the lifetime of
the script. It has no specific requirements related to the communication between Unity
and Automation Studio™.
Update() is called once per frame once the game has started. The requirements for this
method are as follows:
Role.Export: Variables with the Role “Export” are updated locally every frame
and shared with Automation Studio™.
Role.Import: Variables with the Role “Import” are updated every frame with
the changes made by Automation Studio™.
6
Troubleshooting
2. Right click on the “Assets” folder in the Project tab, select “Import New Asset…” and
import the “AS.API.UnityRemoteServer.dll”.
3. Create a new folder called “Prefabs” and import the asset “Menu Canvas.prefab”.
4. Create a new folder called “Scripts” and import the script “ButtonManager.cs”.
5. Drag the new prefab into the Hierarchy tab. It should now look like the image below:
6. Navigate to the AsyncTCPSocketServer game object, press the button to the right of the
missing script, and select “AsyncTCPSocketServer”.
7. Use the buttons to the right of each InputField to select the proper references as seen
below.
8. Navigate to the VariableBinder game object and replace one of the missing scripts with
the “VariableBinder” script. Change the “Server” field to the “AsyncTCPSocketServer”
game object.
8
Troubleshooting
9. Replace the second missing script with the “ButtonManager” script. Set the fields as seen
below.
[11.] In the Inspector tab find the Button script and change the “On Click” details as seen
below.
11.[13.] Make sure an EventSystem game object exists somewhere in the hierarchy so the
slider will be interactable.
[14.] Navigate to the FeedbackSliderAA inside the Feedback Panel, attach the newly imported
script as a component, and configure it as seen below.
[15.] Navigate to the Feedback Slider child object of FeedbackSliderAA. In the Inspector,
change the On Value Changed event in the Slider (Script) to call
FeedbackSlider.UpdateSliderValue.
12.[16.] Right click in the Hierarchy tab and create a new sphere from the 3D Objects section.
13.[17.] Make sure the new sphere object can be seen by the main camera by setting its
position in the Transform section of the Inspector tab to (0,0,0).
14.[18.] In the “Scripts” folder, import the “MovementController” script and attach it as a new
component to the sphere.
15.[19.] Set both the Model and Model Transform fields to the Sphere object and Sphere
(Transform) respectively.
16.[20.] In the Movement Axis field, you can select the axis or axes you want the sphere to
move on. The scale of movement can be altered by the values given to each axis.
17.[21.] Min and Max values are used as limits to the movement of the object. The value that
is actually transferred between Automation Studio™ is the Clamped Value, which has a
range of 0 to 1. At a Clamped Value of 0, the object will be at the MinValue and at a
value of 1 it will reach the MaxValue.
10
Troubleshooting
[22.] The Old Coords and Target Coords will be managed by the external variable and do not
need to be manipulated.
2.5[3.1] Installation
If using the installer, everything will be placed in the correct paths needed for the Unity
module to work. Unity builds must be placed in: C:\ProgramData\Famic Technologies\
3D Systems\Apps
o The built Unity project should be added into the UnityApps directory as its own
folder. This folder must include the “_Data” folder, “Mono” folder, the project
executable file (.exe), the CrashHandler, the “UnityPlayer.dll” and the
“WinPixEventRuntime.dll”.
The path to the built Unity executable file (.exe) must be set as a user-defined variablecan be
found in the project properties as a user-derfined variable “Unity_Path”. To create this variable:
The syntax is as follows:
Navigate to the “Project Properties” from the “View” tab, find the “Information” section, and
select the “Add variable” button.
12
Troubleshooting
Set the name and alias of the new variable to “Unity_Path”. Set the type to “STRING”, and leave
the measurement type as “Without Unit”.
Find the new variable in the “User-Defined” category and change its value to: “.\\
Path_to_Unity_build_folder_in_UnityAPPApps\\Name_of_Unity_project.exe”
Automation Studio™ uses a ribbon accessible from the main toolbar to expose the functionality
required for Unity connection.
To add this ribbon to the Automation Studio™ project, open the “Project Properties” from the
“View” tab and navigate to the “Parameters” section. Find the “Startup Script” parameter, and set
its value to: “METHOD:AS.API.UnityRemoteClientV2::ApplicationClientApi::InitFullRibbon”.
Note: The Automation Studio™ project will need to be saved, closed and reopened for the ribbon
to be displayed.
From the new “3D Link” ribbon, the Unity window can be opened by selecting the “Show”
button. The Unity window will run the executable from the “Unity_Path” variable.
The server must be running and listening for a connection before the client can connect to it.
From the Unity window, select the button that calls the LaunchServer() method. This process is
done automatically in AS 6.4 and later versions.
2.6.4[3.2.4] Variables
“Component Variables” in Automation Studio™ to be shared with the Unity project must be
associated to the appropriate “Compatible Simulation Variables”. This association is managed
from the “Component Properties” in the “Variable Assignment” section.
Variables with the type “FLOAT” on the Unity side should have a corresponding
simulation variable with type “REAL” and a component variable with type “LREAL”.
Variables with the type “BOOL” on the Unity side should have a corresponding
simulation variable type “BOOL” and a component variable with type “BOOL”.
14
Troubleshooting
When the project is run, the list of External Variables is parsed and if any External Variables do
not have a corresponding Component Variable, they are generated automatically. The simulation
will need to be run for the first time before the variable associations can be made.
Associations can be made between Simulation variables and Component variables from the
Component properties as seen below.
Figure 3-22: Association made between Component Variable and Simulation Variable
Feedback variables represent values that are managed by Unity and sent to Automation Studio™.
These variables are added to the External Variables JSON with the Role enumeration set to
“Export”. If they are not present in Automation Studio™, they will be generated automatically.
Feedback variable values may be observed from the “Variable Manager” in Automation
Studio™.
To add the developer ribbon to the Automation Studio™ project, open the “Project Properties”
from the “View” tab and navigate to the “Parameters” section. Find the “Startup Script”
parameter, and set its value to:
“METHOD:AS.API.UnityRemoteClient::ApplicationClientApi::InitFullRibbonWithDev”.
The developer ribbon provides buttons to perform each of the steps taken in creating the
connection between Automation Studio™ and Unity.
Inspector: A console attached to the current project where useful information can be
found about the connection status. Note: Quick Edit Mode will be disabled in the
console when using the Inspector.
Show Unity Window: Displays the Unity Window and runs the Unity project
executable inside it. By default, the server is set to launch on startup. External variables
created by the Unity project (server) will be written to an external JSON file when it is
launched.
Bind External Variables: Imports the external variables from the external JSON file,
creates a new variable in Automation Studio™ if it does not exist and adds them all to
the list of bindings.
Initialize Bindings: Deserializes the bindings from JSON format and initializes each of
the variables in Automation Studio™. Read the connection configs from the
extcom.configs file.
Connect to Server: Launches the client using the Ip address and port from the
connection configs and then starts the Automation Studio™ simulation.
Disconnect: Stops the simulation and closes the connection between Automation
Studio™ and Unity. The server will need to be relaunched before the client can connect
to it again.
16
Troubleshooting
3[4] Troubleshooting
Make sure an EventSystem game object has been added to the scene.
The EventSystem does not need to be altered in any way.
Make sure the Transform component of the object has the position
fields set to a spot that can be seen by the main camera. If the camera
was not altered, setting the objects position to (0,0,0) will bring it into
view.
Ensure at least one axis of the Movement Axis field is set above 0 in
the MovementController script.
Check that the Min Value and/or Max Value fields in the
MovementController script are set to something other than 0.
Ensure that the name used for the External Variable created by the
MovementController script is the one bound to the correct variable in
Automation Studio™.
The object is moving more or faster than expected: The clamped value
by default is given a range between 0 and 1, the output of certain
components in Automation Studio™ have the range -10 to 10.
Matching these ranges, either in the MovementController script or the
component itself may fix the issue.
3.1.3[4.1.3] Errors
The project needs to be closed and reopened after setting the startup
script of the project for the first time.
3.2.2[4.2.2] Variables
The server needs to be launched and the simulation started one time
before the variables are created.
The inspector console is not showing all External Variables when the bindings
are initialized:
Ensure that the Awake method of each attached script ends by calling
“VariableBinder.SendItemToBinder(this);”.
18
Troubleshooting
3.2.3[4.2.3] Connectivity
The server must be launched before the client can connect to it. The
server is launched automatically when the Unity window is opened but
must be relaunched manually using the Launch button in the Unity
window for subsequent connections.
Acronym for dynamic link library. A library that contains data and code to be used by multiple
programs at a time. It may be modularized into separate components and encapsulates its contents
while exposing the necessary functionality for its use.
External Variable
An External Variable is an object representing a value shared between Automation Studio™ and
Unity.
JSON
JSON is a standard text file format that uses a name - value format that is highly human readable.
Script
A script is an asset comparable to a C# class. It makes its connection with the internal workings
of Unity by implementing a class, which is derived from the class MonoBehaviour.
URC
Acronym for UnityRemoteClient, the name of the dynamic link library (dll) supporting
communication between Automation Studio™ and Unity through a TCP connection. This dll
manages the TCP connection from the client side (Automation Studio™).
URS
Acronym for UnityRemoteServer, the name of the dynamic link library (dll) supporting
communication between Automation Studio™ and Unity through a TCP connection. This dll
creates and manages the TCP connection from the server side (Unity).
Variable
B Index
Add Variable in Automation Studio™ 3-12 OnClick LaunchServer 2-3