This article is about integrating your 3D Unity applications into WinCC Open Architecture SCADA HMI Web screens and exchanging property values. It only works with the WinCC Ultralight Web Client. Because the native Ui does not support WebGL in the WebView Widget. Update: It should also work in the native Ui, you just have to set the environment variable: QTWEBENGINE_CHROMIUM_FLAGS=–enable-gpu
With this free Unity Asset you can create a Unity application with an interface to the SCADA system in an easy way. Don’t be confused about the name of the Asset “WinCC Unified Custom Web Control”. This is because initially it was build to create Custom Web Controls for WinCC Unified only. But there is now also an option to create a build of your Unity application for WinCC Open Architecture.
First create and build your Unity Application as described in the documentation of the Asset. You may also watch this video.
Just at the end execute the menu item to create a WinCC Open Architecture application, instead of WinCC Unified.
Create and load the WebView
Then copy the ZIP file to your WinCC OA project into the folder “data\html” and unzip the ZIP (for example C:\WinCC_OA_Proj\Test\data\html\UnityCustomControl).
In this tutorial our application is named “UnityCustomControl”. You have to replace this with the name of your Unity application.
Then you must insert a WebView into your screen.
And then you must load the generated Unity application in the Initialize script of the widget.
main()
{
this.loadSnippet("/data/html/UnityCustomControl/index.html");
}
In the Property Editor at the Extended tab be sure to set the “ulcClientSideWidget” to TRUE.
Set and receive property values
To send values from your WinCC Open Architecture to the Unity application you must use execJsFunction of the Webview and call the “setPropertyInUnity” function with the property and the value which you want to set. See the following example.
UnityCustomControl.execJsFunction("setPropertyInUnity", "target_shoulder_link", 10);
“UnityCustomControl” is the name of our Webview Widget! It’s up to you how you name it.
At the WebView there is an event “messageReceived”. There you will get all the messages which are sent from Unity to WinCC Open Architecture. See the example for the structure of the parameter. It is always a JSON document which contains the Name and the Value of the property which has been sent.
Receiving Property Values:
WCCOAui2:["messageReceived"][mapping 3 items
WCCOAui2: "uuid" : 2
WCCOAui2: "command" : "msgToCtrl"
WCCOAui2: "params" : mapping 2 items
WCCOAui2: "Name" : "test_property"
WCCOAui2: "Value" : "Hello World 1"
WCCOAui2:]
The very first message does not have any “params”, this message comes when the initialization of Unity is done.
First Message:
WCCOAui2:["messageReceived"][mapping 2 items
WCCOAui2: "uuid" : 1
WCCOAui2: "command" : "msgToCtrl"
WCCOAui2:]
Start Ultralight Web Client
Start a Control Manager with the “webclient_http.ctl” script.
Then you can open the application in the browser with “https://localhost/data/ulc/start.html”.