Visual Studio winForm <---> Unity WebPlayer OCX Works

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;
}

Hey, that’s pretty cool!

Hi Hannebaum
you really help me with this code!
do you know how to extract the parameter from the gameObject in unity?

i need to send data from C#
thanks
Aaron

Aaroncb,

Sorry for the late response, but I have decided to use the webbrowser control on my Visual Studio form. This is because you can point to the unity file in use and it provides better method of communication to unity. The src property was an issue when using as ocx in the form, and the code was not able to set the property. This seemed like a long term issue when your customer installed your software and the application could not point to the unity file, because they installed it on another drive or location other than C:\Program Fles.

So you need to have you application communicate through webbrowser control to and from Unity. It’s not to bad and seems to run fast. I don’t have the time to give you the details at this time, but lookup in your Visual Studio online search for webbrowser to windows form communication. Here is some real good information at http://www.codeproject.com/KB/vb/vb_jscript_communication.aspx

Then use the unity documention in the manual under the topic Unity Web Player and browser communication at
http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html

You should be able to put it together. Have Unity call functions in the browser and have Visual Studio call functions in the browser to pass values of variables back and forth.

The ocx does have some promise, but the documentation on it is lacking. Wish Unity would provide a solution to this.

I will provided you more information and an example as soon as I can. Just real busy with my job at this time. Maybe by the end of next weekend I will post them to you.

I have been working on this method and it is key to my application working with Unity also.

Let me know how your doing along the way, I’ll check in more frequently.

Good Luck Buddy,
Scott Hannebaum