Giter Site home page Giter Site logo

unity-swiftui-example's Introduction

unity-swiftui-example's People

Contributors

davidpeicho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

unity-swiftui-example's Issues

Does this example work with XCode Preview?

One of the greatest features of SwiftUI is to receive almost immediate response to changes via XCode Preview.
Does the combination of Unity with SwiftUI work in XCode Preview?

Add a project license

Hi @DavidPeicho, I can't find a license in this repository.

Could you clarify what license this code is distributed under?
Before I potentially use it as a starting point for a commercial project.

If it is based on the example published by Unity, does it inherit the Unity Companion License?
Or is your work only based conceptually on (i.e. does not include code from) Unity's example?
In which case I believe you would select your own license.

Thanks for your work on this, and the blog posts explaining your methods!

Solution for Unity doesn't render

From the README

Between the moment you create the UnityFramework instance, and the moment you can display it, it seems like there is an issue. Some people try to add a delay, but this is definitely a hack.

The problem is a race condition. In public func show(controller: UIViewController) we add Unity's rootView as a subview of our own custom view controller, but when we start running Unity it will automatically add it as a subview of its own internal view controller. One overrides the other, so whoever runs last wins. Maybe you can find some way to wait for Unity to complete this step, ensuring your addSubview call always occurs last.

For me, I've had to edit Unity's source code for a number of unrelated reasons, so the most natural thing was to just go directly to the line that assigns the view and comment it out. In the build output of project made with Unity version 2021.3.18f1, go to Classes/UI/UnityAppController+ViewHandling and replace the willStartWithViewController method with this.

- (void)willStartWithViewController:(UIViewController*)controller
{
    _unityView.contentScaleFactor   = UnityScreenScaleFactor([UIScreen mainScreen]);
    _unityView.autoresizingMask     = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    // original - our own superview could get replaced if set before this line runs
    // _rootController.view = _rootView = _unityView;
    
    // custom
    _rootView = _unityView;
}

I would make a PR for you but the Unity iOS build output is not included in this repo.

Following tutorial missing a step

I followed your tutorial and always got errors from xCode not being able to find TestDelegate and other NativeCallProxy types. I spent days trying to figure this out. The missing step was to edit the UnityFramework file and add #include "NativeCallProxy.h". Either there is some a in your unity project that I don't get by default before building, or this step should be part of the procedure. Otherwise great tutorial!

Not working in Unity 20.3.24

Hello!

Thank you for your great example on how to integrate Unity into Swift!

I have a project running in Unity 20.3.18 and it works perfect however it does not do well in 20.3.24.
The problem is, that the Smash Screen is shown and causes a timing error I think. Would be great if you take a look at it as I am dependent on this solution and not able to fix it by myself as I am quite new to Swift.

Thank you
Jakob

libmanomotion.framework

I am a student and my project is to make an AR experience with a ring try on.
I am using manomotion for the AR part and it is a plugin added to unity.
I want to integrate it in a swift app and as a simple unity project is working well when I want to run my AR unity,
Xcode doesn't find my manomotion framework.
So, I read your work about plugin for gameobject and I don't know how to do for my specificity.
I though I had just to write a bridge for the plugin but it seems more complex...
unity.pdf

Linking error for FrameworkLibAPI

The code just works fine for displaying Unity in a SwiftUI app, but has problem with your message API.
If this line is added:

FrameworkLibAPI.registerAPIforNativeCalls(...)

the linking process will fail, with error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FrameworkLibAPI", referenced from:
      objc-class-ref in UnityBridge.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Are there any settings that I omitted or you forgot to mention?

Note: I'm trying to run it on simulator, so I chose "Simulator SDK" in Unity's project settings. Anything to do with that?

Cannot hide/remove Unity from screen

Hi @DavidPeicho , I'm trying to switch between native views and Unity back and force with API calls. The problem is that I cannot hide Unity after it was first shown. Any new native controller is hidden behind Unity. I've tried dismissing it, removing from parent, but Unity is always on top. Even unloading it with your method only freezes the view without possibility to remove it.
I would appreciate any suggestions.

How to mark NavigationView as Passthrough

Hello!
If I add a NavigationView the touch Event does not get forwarded to Unity. Do you know a way how to solve this?

ZStack {
NavigationView {
}
Text("Hello World").onAppear {
let api = UnityBridge.getInstance()
api.show()
}
}

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.