Giter Club home page Giter Club logo

unitypluginxcodetemplate's Introduction

Unity Native Plugin Example for iOS & macOS using Swift

Unity supports native plugin, which are libraries of native code written in Swift.
Native plugin make possible for code written in C# to call functions from these libraries.
Check this document for detailed Native Plugin creation instructions.

Build Swift Libraries

Check Makefile for command details.

Build Framework for iOS

$ make framework

This should result in SwiftPmPlugin.framework being generated in Build.
Copy the built framework into your Unity project's Assets/Plugins/iOS.
Enable Add To Embedded Binaries in the Unity Inspector of SwiftPmPlugin.framework.

unity_inspector_embed

Build Bundle for macOS

$ make bundle

This should result in SwiftPmPlugin.bundle being generated in Build.
Copy the built bundle into your Unity project's Assets/Plugins/macOS.
Need to restart unity to load the new bundle.

Swift Interface Example for Unity

Check UnityInterface.swift for details.

@_cdecl("swiftPmPlugin_toNumber")
public func swiftPmPlugin_toNumber(_ stringPtr: UnsafePointer<CChar>?) -> Int64 {
    let str = String(cString: stringPtr!)
    return Int64(Int(str) ?? 0)
}

Call Swift Function in C#

Check SwiftPmPlugin.cs for details.

[DllImport(libName)]
private static extern long swiftPmPlugin_toNumber(string stringNumber);

public static long ToNumber(string stringNumber)
{
    return swiftPmPlugin_toNumber(stringNumber);
}

unitypluginxcodetemplate's People

Contributors

fuziki 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

unitypluginxcodetemplate's Issues

.bundle not working with latest xcode 15.3 and Unity 2023.2

After updating to Xcode 15.3 and Unity 2023.2, I encountered an issue where the build process completes successfully, but Unity is unable to locate the entry point from the bundle and DLL, if i create bundle using the make, or Xcode build.

Steps to Reproduce

  1. Update Xcode to version 15.3.
  2. Update Unity to version 2023.2.
  3. run make bundle and make framework
  4. Launch the project in Unity.

Additional Information

  • Unity Version: 2023.2
  • Xcode Version: 15.3
  • Operating System: [Specify your operating system version]
  • Other relevant software versions or configurations: [Include any other relevant information about your setup]

Possible Solutions Explored

I have attempted to troubleshoot the issue by restarting unity trying different versions of unity

Screenshots or Code Samples

image

Any assistance or insights into resolving this issue would be greatly appreciated. Thank you!

example dont work

i build unity example from UnityPluginXcodeTemplate/Examples/UnityExample/
then i open in Xcode and build and run
and got that:

image

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.