So here we go!
As far as the OCX not loading the *.unity3d file goes, it seems as though the src property will not load through code as Chrisk discovered. I haven’t tried to load the src with code yet, but I just typed the path to the *.unity3d file into the src property on the property page. So just drag the ocx onto your form and set the path of the src property.
The communication between the Unity and Visual Studio winForm is next. At the time I tested I used VB 2008. Don’t know why , just did. Still have to work with the parameters to send data yet. This was just to get started and will work with the object base class members later.
The OCX has an event called OnExternalCall(,) for receiving Application.ExternalCall(,) from Unity JS.
I just filled with the Application.ExternalCall(,) with(“a”,“b”) so it would compile for now. As you can see the event in VB just incremented Label1.Text. Was getting around 100 responses a second. I’d say it was around 12 milliseconds for each response.
Also the OCX has a SendMessage(,) to call a function Name(,) within a Unity GameObject. Here you can see that when I click on Button1 it calls a function within the GameObject Spotlight. So in the Unity GameObject the Spotlight points to GameObject Cube1. Of course clicking Button2 points the Spotlight on Cube2. Also here again I just placed 0 in the object parameter of the SendMessage just to compile for now.
There is a lot more to the OCX yet to be discovered. Any help with the OCX documentation would make things easier. Someone knows about this component out there somewhere. Unity???
So there you go! Wasn’t to bad so far. I’ll give more as I go, and if anyone else wants to dive into this it would be greatly appreciated.
Also I want to thank Unity. With it free I’ll have good hands-on time before going pro. You guys rock!
Thank you,
********************************************* Visual Studio VB code *******************************************
Public Class Form1
Public responses As Double
Private Sub AxUnityWebPlayer1_OnExternalCall(ByVal sender As Object, ByVal e As AxUnityWebPlayerAXLib._DUnityWebPlayerAXEvents_OnExternalCallEvent) Handles AxUnityWebPlayer1.OnExternalCall
responses = responses + 1
Label1.Text = responses
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxUnityWebPlayer1.SendMessage(“Spotlight”, “WindowsCommand1”, 0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
AxUnityWebPlayer1.SendMessage(“Spotlight”, “WindowsCommand2”, 0)
End Sub
End Class
*************************************************** JavaScript in Unity *******************************************
function Update () {
Application.ExternalCall( “a”, “b”);
}
function WindowsCommand1 () {
var newTarget = GameObject.Find(“Cube1”).transform;
GetComponent(Follow).target = newTarget;
}
function WindowsCommand2 () {
var newTarget = GameObject.Find(“Cube2”).transform;
GetComponent(Follow).target = newTarget;
}