Thursday, May 16, 2013

Coherent UI is now available on Unity3D Asset Store



We’re really happy to announce that Coherent UI for Unity3D is now available on the Asset Store. Buy Basic or Standard version or download a free trial from Coherent Lab’s website.   


All versions of Coherent UI for Unity3D can be used for the creation and implementation of HUDs, menus, dialogs and in-game browsers. Our GUI library currently supports Windows (32 and 64 bit) and Mac OS X and soon we’re going to add Linux as well.


The Basic version covers all the primary needs of game UI developers allowing them to have both HUD and in-game browser at the same time. Standard gives more creative freedom because it allows unlimited number of views, SSL support, on-demand views and control view framerate, features needed for more complex projects.


We encourage Unity3D developers to take a look at our GUI library and to give us their feedback about it. All of your reviews and ratings will help us a lot with the future development of the product. We are always open to discuss ideas for new features and tools that will be of benefit for game UI developers.

For a quick start guide we suggest a look at our previous post Coherent UI in the Unity3D editor - Introduction. For more resources and tutorials follow the Unity3D tag on our blog or @CoherentLabs on Twitter.

Wednesday, May 8, 2013

Using TypeScript with Coherent UI

Previously we announced the automatic binding of .Net methods for Coherent UI. It greatly simplifies exposing the game to the UI, but also has some additional advantages that I want to share. Binding .Net methods allows to expose the game using concrete, separate interfaces. This allows for better structuring of the UI code - think of OOP and separation of concerns. It also allows for taking advantage of  more advanced and modern web programming techniques, tools and languages like TypeScript.

TypeScript is a new language that compiles to pretty human read-able and efficient JavaScript while adding some desirable features:
  • optional static typing - catch errors while making them
  • lots of EcmaScript 6 features - arrow functions, classes with inheritance, modules
  • much better editor support - autocompletion and error highlighting in Visual Studio
Say you have a Player class with inventory consisting of list of items
You need to declare the Player class and the Item struct in order to take advantage of the static type checks.

The /// reference path="coherent.d.ts" includes the declaration of Coherent UI JavaScript API. This allows us to declare that the GetEquipment method returns a promise. Whenever you call the player.GetInventory() method in JavaScript, Coherent UI will call the player.GetInvetory() in the .Net universe and will resolve the promise with the returned list of items. You can download the declaration file of Coherent UI from here. So what is left to take advantage of TypeScript features - here is a screenshot of Visual Studio's Intellisense showing the documentation of the engine.on method:



In its next release TypeScript is going to have two major new features - generics and overloading on constants. They are going to make using Coherent UI with TypeScript even better and so expect more posts about using TypeScript with Coherent UI.

Thursday, April 25, 2013

Announcing our new release - Coherent UI 1.2.1

Coherent UI in Planet Annihilation

First we would like to show some pre-alpha footage of Planetary Annihilation the devs from Uber Entertainment have put online. The footage looks great and it is going to be a terrific game, we can't wait to see more and play it. Oh, and by the way, the user interface is powered by Coherent UI.



New release


We have recently released Coherent UI 1.2.1. It has two major new features - handling of downloads and exporting .Net objects with their methods to JavaScript. Also we have re-designed our internal task scheduling routines and gained up to 30% performance improvement. That helped us to improve the on-demand views, which are now much faster.

Downloads Handling API

Coherent UI supports a full in-game browser and now using the SDK developers can add download file functionality. When the user clicks on a downloadable file the API provides a notification and the developer can handle the download. API also allows developers to make direct file download request, with progress notification and multiple protocols support.

This opens a myriad of new possibilities like using Coherent UI for your game's launcher or updater - achieving both a visually stunning front-end and easy to code download/update functionality, without the need to handle the transfer yourself or to integrate other third-party libraries.

File download also enables developers to integrate seamlessly advanced social features like users sharing photos, videos or other content. Also game asset streaming - downloading resources in run-time becomes a piece of cake to implement. The potential usages of the feature are countless and the combo UI/browser/file downloads makes Coherent UI much more useful set of tools for many more tasks on top of  user interface implementation.

.Net/Unity3D Method binding

Since its very first release Coherent UI already supported binding and executing of arbitrary .Net delegates by JavaScript. However it required explicit registration of each delegate via the View.BindCall and View.RegisterForEvent methods, which made it somewhat time-consuming and prone to typos. So we've added a new feature, that automatically exports .Net object with all of its methods to the browser JavaScript. This means you can call any .Net method on any object writing only a single line of code.

How it works?

You just wrap the object and send it to JavaScript as an argument to an event or as a result of an engine.call handler and that's it - you can call every method of the object from JavaScript.

Here is how we use the Options instance in JavaScript:

Note that for every method of the .Net object that has return value, calling the JavaScript method returns a promise for this result.


This cool feature is available only for .Net and Unity3D for now, but we are going to add it to the C++ API too.

To give Coherent UI 1.2.1 a try download it from our website.

Tuesday, April 16, 2013

Objective-C++ ARC gotchas

Lately I had to mix C++ and Objective-C pretty heavily (it's called Objective-C++ apparently). What I usually need is having Obj-C objects inside C++ ones, which with "Automatic Reference Counting"(ARC) should work out-of-the-box. It actually does - except when it doesn't!

In essence what the compiler probably does is just add 'retain' & 'release' calls in the proper places (constructors, destructors etc.). It is smart enough to recognize pointers to ARC objects and treat them as non-POD.

This is actually very cool and simplifies the interaction a lot. Alas there are some problems when you try to do some more 'exotic' stuff.

A pretty standard C++ way to use your own memory management routines is to allocate some memory with your custom allocator and then use placement new to construct an object in the fresh memory. Destruction goes the other way around - call the destructor explicitly and deallocate your memory.

In the following code, as you might expect, 'dealloc' is called as soon as the C++ object is destroyed - so no leak happens:

However if you uncomment the 'virtual' keyword and hence make the hierarchy virtual the 'dealloc' method will not be called. The compiler in this case does not create the non-trivial destructor required! If you substitute the manual memory management with the delete operator then the destructor is synthesized and 'dealloc' gets called. The behavior is also prevented if your class is non-POD in C++ terms.

Not having a virtual destructor in a virtual hierarchy is arguably very bad, however breaking the ARC promise is even worse. I admit that stumbling upon this issue is not very easy because it requires a lot of things to happen but still the leaking references it introduces are serious enough to prompt me to write about it.

I haven't looked at clang's source about this issue and I can't find a rationale behind it in the docs so I think it's an oversight and can only speculate why it happens. The version of the compiler that I currently work and saw the problem is: "Apple clang version 4.1 (tags/Apple/clang-421.11.66)".

All that said, if you follow the basic C++ guidelines of having virtual destructors in your polymorphic hierarchies you should be fine when you try to mix C++ and Objective-C.

Thursday, March 28, 2013

Unity3D - compositing multiple Coherent UI Views (tutorial)

In this tutorial we'll show how to compose multiple Coherent UI views simultaneously on the main player camera.

Some example scenarios when you would like to achieve such an effect are:

1) Having both the HUD and a browser simultaneously active on the player screen - both camera-aligned
2) In a strategy game all the unit's portraits could be in one view (using the on-demand view feature for perfect gameplay synchronization) and all other HUD details (unit construction, menus, etc.) in another view
3) If you want to keep some sort of logic separate between views - for instance having the HUD and the menus in different views

These are only a handful of use cases, I'm sure many more can be invented. Keep in mind that most of the the time you could use just one view and separate the content with divs or iframes. For all the cases when this is not possible - here is a quick tutorial.

As it turns out achieving the composition is super easy in Unity3D and requires no code at all.

We'll use as a base the "MenuAndHud" sample available in the Coherent UI package.
In essence we'll render the two views on two render textures and then compose them on the Main camera via "GUI Textures".

1) Create an empty project
2) Import the Coherent UI package
3) Run Assets->Coherent UI->Install Coherent UI
4) Now navigate and open the scene we'll modify - Assets/CoherentUI/Samples/Scenes/Sample03_MenuAndHUD/Game/game.scene
5) First remove the Coherent UI View component that is currently on one of the faces of the cube


6) Remove the  Coherent UI View component from the "Main Camera" (under "First Person Controller")
7) Add a Camera Game Object and set it's position to (0, 0, 100) or any other position where it won't be able to 'see' any of the scene or just use the culling mask of the camera


8) Add a Coherent UI View component to this new camera


9) IMPORTANT: Remove the 'GUI layer' component from the newly created camera.
10) Create a Render texture to hold our rendered view


11) Rename the texture to 'browser' and set it to 1024x512 pixels


12) Set the 'browser' texture as Render target for the new camera
13) Repeat steps 6-11 - create again a new camera, remove the GUI Layer component, create a new render texture but this time name it 'hudTex'. Set the Coherent UI View component on the second camera to be 1024x570 pixels and set it's 'Page' to 'coui://UIResources/MenuAndHUD/hud/hud.html'. Make sure the view has also "Is Transparent" and "Support Click Through" set to true.


14) Create a "GUI Texture" Game Object


 15) Rename it to 'HudGui', set it's texture to our 'hudTex', it's position to (-512, -256) and it's size to 1024x570


16) Create another "GUI Texture" Game Object
17) Rename it to Browser, set it's texture to our 'browser', it's position to (-512, -256) and it's size to 1024x512. Note that the result will also be tinted by the GUI Texture 'Color' property. This could be used to achieve some neat effects.


18) Play!


That's it! With this technique you can compose as many views as you like anywhere on the screen. Try Coherent UI now!