Git Product home page Git Product logo

nativeiosapp's Introduction

Native iOS App

1. Download this project
2. Get xCode project exported from Unity
Since iOS project exported from Unity contains large files it can't be uploaded to github. You can download xCode project exported from Unity from here, or get Unity project from github and make export yourself.
3. Setup Xcode workspace
Xcode workspace allows to work on multiple projects simultaneously and combine their products

  • open NativeiOSApp.xcodeproj from Xcode
  • create workspace and save it at UaaLExample/both.xcworkspace. (File / New / Workspace)
  • close NativeiOSApp.xcodeproj project all Next steps are done from just created Workspace project
  • add NativeiOSApp.xcodeproj and generated Unity-iPhone.xcodeproj from step #2 to workspace on a same level ( File / Add Files to β€œboth” )

4. Add UnityFramework.framework
With this step we add Unity player in the form of a framework to NativeiOSApp, it does not change the behavior of NativeiOSApp yet

  • select NativeiOSApp target from NativeiOSApp project
  • in "General / Frameworks, Libraries, and Embedded Content" press +
  • select Unity-iPhone/UnityFramework.framework
  • in "Build Phases" tab, expand "Link Binary With Libraries"
  • remove UnityFramework.framework from the list (select it and press - )

5. Expose NativeCallProxy.h
Native application implements NativeCallsProtocol defined in following file:

  • find and select Unity-iPhone / Libraries / Plugins / iOS / NativeCallProxy.h
  • enable UnityFramework in Target Membership and set Public header visibility (small dropdown on right side to UnityFramework)

6. Make Data folder to be part of the UnityFramework
By default Data folder is part of Unity-iPhone target, we change that to make everything encapsulated in one single framework file.

  • change Target Membership for Data folder to UnityFramework
  • (optional) If you want to use Unity-iPhone sheme you need to point UnityFramework to a new place where Data is located by calling from Unity-iPhone/MainApp/main.mm:
    [ufw setDataBundleId: "com.unity3d.framework"];
    // On Demand Resources are not supported in this case. To make them work instead of the calls above 
    // you need to copy Data folder to your native application (With script at Build Phases) and 
    // skip a calls above since by default Data folder expected to be in mainBundle.
    

Workspace is ready

Everything is ready to build, run and debug for both projects: Unity-iPhone and NativeiOSApp (select NativeiOSApp scheme to run Native App with integrated Unity or Unity-iPhone to run just Unity App part) If all went successfully at this point you should be able to run NativeiOSApp:

Notes

Loading Unity player is controlled with UnityFramework object. To get it you call UnityFrameworkLoad (it loads UnityFramework.framework if it wasn't, and returns singleton instance to UnityFramework class observe Unity-iPhone/UnityFramework/UnityFramework.h for its API ). Observe UnityFrameworkLoad in: NativeiOSApp/NativeiOSApp/MainViewController.mm or in Unity-iPhone/MainApp/main.mm

#include <UnityFramework/UnityFramework.h>

UnityFramework* UnityFrameworkLoad()
{
    NSString* bundlePath = nil;
    bundlePath = [[NSBundle mainBundle] bundlePath];
    bundlePath = [bundlePath stringByAppendingString: @"/Frameworks/UnityFramework.framework"];

    NSBundle* bundle = [NSBundle bundleWithPath: bundlePath];
    if ([bundle isLoaded] == false) [bundle load];

    UnityFramework* ufw = [bundle.principalClass getInstance];
    if (![ufw appController])
    {
        // Initialize Unity for a first time
        [ufw setExecuteHeader: &_mh_execute_header];       

        // Keep in sync with Data folder Target Membership setting
        [ufw setDataBundleId: "com.unity3d.framework"]; 
       
    }
    return ufw;
}

nativeiosapp's People

Contributors

obywan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.