Revision Release 2025.3714 Keywords CoronaCards, iOS, Unity See also Xcode Project Setup — iOS Native/Lua Communication — iOS
This guide explains how to integrate CoronaCards within a Unity project for iOS.
Please refer to Xcode Project Setup — iOS
Basic integration of CoronaCards within Unity can be achieved by modifying the UnityViewController
that is generated from the Unity project. This UnityViewController
becomes the root controller upon which the CoronaViewController
will overlay.
To add the CoronaViewController
and CoronaView
to the view controller hierarchy, add a member in UnityAppController.h
via the process outlined below. In this example, we’ll add a simple Corona project to the native Xcode Unity project, set to run as an overlay.
UnityAppController
interface:CoronaViewController* _coronaController;
createViewHierarchy
method in UnityAppController.mm
:- (void)createViewHierarchy { //Unity Specific code //... //... //... //CoronaCards code _coronaController = [[[CoronaViewController alloc] init] autorelease]; [_rootController addChildViewController:_coronaController]; CoronaView *coronaView = (CoronaView *)_coronaController.view; //Define the region for CoronaCards - example is 100X100 CGRect rect = CGRectMake(0,0,100,100); coronaView.frame = rect; [_rootView addSubview:coronaView]; // Transparent background coronaView.backgroundColor = [UIColor clearColor]; coronaView.opaque = NO; [coronaView run]; }
UnityAppController.mm
:- (void)repaint { //Added for OpenGL context [EAGLContext setCurrentContext:_mainDisplay->surface.context]; //Unity Specific code //... //... //... }
In iOS, a CoronaView can have transparent backgrounds. To accomplish this, two things are required:
First, instruct iOS to enable transparency in the UIView
itself:
// [Obj-C] coronaView.backgroundColor = [UIColor clearColor]; coronaView.opaque = NO;
Second, tell Corona to utilize an transparent OpenGL surface by setting the alpha
key to 0
:
-- [Lua] display.setDefault( "background", 0, 0, 0, 0 )
Once integrated, a Corona-based view can communicate with the native app and