Never had a touch with unity before, because now the company needs to do two development in unity code, so I want to be able to call the Unity method, the search on the Internet a lot of methods are not useful, all is a few years ago, I just update others in the original method, write a latest version of the interactive example. I'm using unity5.3 and Xcode7.3.
Create a button to jump directly to the Unity Project method online can be found, I do not describe
Here's just how to call a single method in unity.
Create a unity scene this can be done by
The rain Momo the great God's way to get http://www.xuanyusong.com/archives/517.
My method is based on his updated a bit, mainly his version is very old, not applicable to the current version
After exporting to iOS, I created a class called MyView.
MyView.h file
#import<UIKit/UIKit.h>@interfaceMyview:nsobject+(void) Createbutton:title rect: (cgrect) Rect action: (SEL) Action Controller: (Uiviewcontroller *) controller;+(void) Createtitle: (Uiviewcontroller *) controller;+(void) leftbuttonpressed;+(void) rightbuttonpressed;+(void) upbuttonpressed;+(void) downbuttonpressed;+(void) Init: (Uiviewcontroller *) controller;@end
MYVIEW.MM file
#import "MyView.h"@interfaceMyView ()@end@implementationMyView//Create button+(void) Createbutton:title rect: (cgrect) Rect action: (SEL) Action Controller: (Uiviewcontroller *) controller{UIButton* BTN =[UIButton Buttonwithtype:uibuttontyperoundedrect]; //Set the button rangeBtn.frame =rect; //Set button display content[btn Settitle:title forstate:uicontrolstatenormal]; //set the response method of the button after the binding[btn addtarget:self action:action forcontrolevents:uicontroleventtouchupinside]; //Join the View[Controller.view addsubview:btn];}//Create a label+(void) Createtitle: (Uiviewcontroller *) controller{//Create a label viewUILabel *label = [[UILabel alloc] Initwithframe:cgrectmake (0,0, the, +)]; //Setting display contentLabel.text =@"Rotation Control"; //Set Background colorLabel.backgroundcolor =[Uicolor Bluecolor]; //Set Text colorLabel.textcolor =[Uicolor Whitecolor]; //Center setting display positionLabel.textalignment =Nstextalignmentcenter; //Set Font sizeLabel.font = [Uifont fontwithname:[[uifont familynames] Objectatindex:Ten] Size: -]; [Controller.view Addsubview:label];}//left button+(void) leftbuttonpressed{Unitysendmessage ("Cube","MoveLeft","");}//Right Button+(void) rightbuttonpressed{Unitysendmessage ("Cube","MoveRight","");}//up Button+(void) upbuttonpressed{Unitysendmessage ("Cube","MoveUp","");}//down button+(void) downbuttonpressed{Unitysendmessage ("Cube","MoveDown","");}+(void) Init: (Uiviewcontroller *) controller{[self createtitle:controller]; [Self Createbutton:@"left rotation"Rect:cgrectmake (0, -, -, +) Action: @selector (leftbuttonpressed) Controller:controller]; [Self Createbutton:@"Rotate Right"Rect:cgrectmake (0, -, -, +) Action: @selector (rightbuttonpressed) Controller:controller]; [Self Createbutton:@"on rotation"Rect:cgrectmake (0, Max, -, +) Action: @selector (upbuttonpressed) Controller:controller]; [Self Createbutton:@"Down rotation"Rect:cgrectmake (0, $, -, +) Action: @selector (downbuttonpressed) Controller:controller];}@end
And then into the unityappcontroller.mm.
Import the header file inside the UNITYAPPCONTROLLER.MM
Find this line
Add this code before return YES in this method
And then it runs and there's the interface.
This model rotates when the button is clicked
All right, that's all.
Interaction issues with iOS and unity