Coherent UI developed by Coherent Labs is a fully featured GUI system for any Unity (or .NET) game that utilizes the power of HTML, CSS, and Javascript. Use any bleeding edge HTML5, CSS3 features that run on WebKit and any JavaScript libraries you need. It is literally as easy as making a web page on Chrome. It also utilizes the WebKit debugger (just like Chrome) so it is easy find the root cause of any problem.
The video explains the whole process but this blog post contains some nice references (see video description for timestamps).
Plugin
which means it is written in native code (C, C++, Objective-C, etc). Plugin
s are only supported by Unity Pro. See this documentation. Also note that Plugin
s do not work in the web player.CoherentUIView
Script onto your Camera (Standard Assets -> Scripts -> CoherentUI -> CoherentUIView)CoherentUIView
, enable Is Transparent
so that we can see the game.Enable Binding Attribute
so we can talk between JavaScript and Unity. In Coherent 1.6+, this is now called Enable [CoherentMethodAttribute]
under the Scripting
section on the CoherentUIView
.couiView.ReceivesInput = true;
in code to have input forwarded on desktop.using UnityEngine;
using System.Collections;
using Coherent.UI.Binding;
public class HUD : MonoBehaviour {
private CoherentUIView m_View;
void Start () {
m_View = GetComponent<CoherentUIView>();
}
}
In Unity (C#):
m_View.View.TriggerEvent("jsEventExample", arg1, arg2, arg3);
Part of your GUI JavaScript (JS):
function BoundFunctionInJavaScript() {
console.log(arguments[0] + arguments[1] + arguments[2]);
}
$(document).ready(function () {
// Bind event “jsEventExample” to a js function
engine.on('jsEventExample', BoundFunctionInJavaScript, this);
});
In Unity (C#):
[Coherent.UI.CoherentMethod("FunctionInUnity")]
public string FunctionInUnity(float arg1, float arg2, float arg3)
{
// Returns sum of arguments supplied
return arg1 + arg2 + arg3;
}
Part of your GUI JavaScript (JS):
// Calls a function in Unity called “functionInUnity” with 3 arguments
// Get return data via arguments[0]
engine.call('FunctionInUnity', arg1, arg2, arg3).then(function () {
console.log(arguments[0]);
});