Using HTML to edit the Unity Web Player

Let me set up a little description of my problem here. I work for a company who does Building Information Modeling (BIM for short). That’s basically a fancy way of saying I create databases for buildings and all the assets inside. I then take a 3D model of the building and set up a viewpoint for every asset (often thousands of these). This way, someone can locate any asset in the building very quickly.

I currently have one of my client’s building set up in unity, and have a basic first-person character placed in it. It works great and I can navigate the model in Unity. What I would like to be able to do, is imbed the web player in a website, and then have the character controller move to a specific viewpoint in the unity file; depending on what web page the unity web player was open from.

For example, my client uses a Computerized Maintenance Management System (CMMS), to keep track of all his assets. Lets say he gets on his CMMS and looks up Air handler unit 1 (AHU-1). I want him to have the option of clicking on the unity web player on that same page, and when it opens the Unity Web Player, for it to jump to the viewpoint of AHU-1.

If I read correctly, this is possible through the HTML right? I have been researching this for a few days now and can’t come up with a solution. Any assistance y’all can provide would be really appreciated; even if it’s pointing out a function that may be useful. My html and java knowledge is pretty limited.

There are multiple ways how to get information from the hosting website into the webplayer. First of all the most straight forward are additional URL parameters to the unity3d file inside the embed code. Since you have to specify and URL which unity3d file the player should load you can simply add a query string

    "/.../webplayer.unity3d?someParameter=somevalue&anotherParameter=anotherValue"

However this method only allows to pass information when the page loads. So it has to be part of the HTML when the page arrives at the user. When you use php or asp on the server the information can be put together there.

In Unity you can use Application.absoluteURL or Application.srcValue to get the passed information.

Another way is to read the parameters of the actual webpage with this script i wrote. This allows you to decide what to do based on the website the player is embedded into.

If you need to pass information to the player while it’s running you can use SendMessage from some javascript inside the webpage. You can also talk back to the website with Application.ExternalCall or Application.ExternalEval.

Attempted SendMessage as suggested with no success. Our attempt is seen below.

Here is the script we have in unity applied to the gameObject “MyObject”

#pragma strict

function moveit (move : float) {
	transform.position = Vector3.up * (move);
}

Here is the part of the html that we added to engage the web player and move “MyObject”.

<script type="text/javascript" language="javascript">
		<!--
		//initializing the WebPlayer
		var u = new UnityObject2();
		u.initPlugin(jQuery("#unityPlayer")[0], "Simple Cube.unity3d");
		function movem() {
			u.getUnityObject().SendMessage("MyObject", "moveit", 25.0);
			}
		-->
		</script>

As of now, this doesn’t work. and we see no movement in the Unity Web Player “MyObject” when run. We assumed that the HTML wasn’t waiting on the web player to load so we added the following code to call the HTML function after web player loaded but it didn’t work either.

#pragma strict

function Start () {
		Application.ExternalCall("movem");
}