All Projects → mcpiroman → UnityNativeTool

mcpiroman / UnityNativeTool

Licence: MIT license
Allows to unload native plugins in Unity3d editor

Programming Languages

C#
18002 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to UnityNativeTool

Extosc
extOSC is a tool dedicated to simplify creation of applications in Unity with OSC protocol usage.
Stars: ✭ 69 (-53.06%)
Mutual labels:  unity-editor, unity3d-plugin
UnityRawInput
Windows Raw Input wrapper for Unity game engine
Stars: ✭ 129 (-12.24%)
Mutual labels:  native, unity3d-plugin
Ma textureatlasser
Texture atlas creator for Unity
Stars: ✭ 116 (-21.09%)
Mutual labels:  unity-editor, unity3d-plugin
Ugui Editor
Unity UGUI editor tools,improve the efficiency of ui development.
Stars: ✭ 479 (+225.85%)
Mutual labels:  unity-editor, unity3d-plugin
download.unity.com
Unity Download http://unity3d.com/unity/download/archive
Stars: ✭ 90 (-38.78%)
Mutual labels:  unity-editor, unity3d-plugin
Unity Quicksheet
Unity-QuickSheet enables you to use spreadsheet file data within Unity editor.
Stars: ✭ 742 (+404.76%)
Mutual labels:  unity-editor, unity3d-plugin
Corium
Corium is a modern scripting language which combines simple, safe and efficient programming.
Stars: ✭ 18 (-87.76%)
Mutual labels:  native, runtime
ScriptableObjectMultiSelectDropdown
Multi Select Dropdown for ScriptableObjects
Stars: ✭ 18 (-87.76%)
Mutual labels:  unity-editor, unity3d-plugin
ar-simulation
AR Simulation for Unity • Right in the Editor • Minimally Invasive
Stars: ✭ 101 (-31.29%)
Mutual labels:  unity-editor, unity3d-plugin
Arcgis Appstudio Samples
Collection of samples available in AppStudio for ArcGIS desktop to learn and help build your next app.
Stars: ✭ 78 (-46.94%)
Mutual labels:  native, runtime
Unity Script Collection
A maintained collection of useful & free unity scripts / library's / plugins and extensions
Stars: ✭ 3,640 (+2376.19%)
Mutual labels:  unity-editor, unity3d-plugin
DotNetJS
Consume C# in JavaScript with comfort: single-file UMD library, auto-generated 2-way bindings and type definitions
Stars: ✭ 551 (+274.83%)
Mutual labels:  runtime, interop
UnityDebug
A wrapper script for Unity debug calls to use conditional attributes in order to avoid debug code being compiled into release builds.
Stars: ✭ 29 (-80.27%)
Mutual labels:  unity-editor, unity3d-plugin
Awesome Unity Open Source On Github
A categorized collection of awesome Unity open source on GitHub (800+)
Stars: ✭ 1,124 (+664.63%)
Mutual labels:  unity-editor, unity3d-plugin
CategoryTool
Unity Editor tool to create Categories in the Hierarchy. The Categories work as dividers between GameObjects.
Stars: ✭ 47 (-68.03%)
Mutual labels:  unity-editor, unity3d-plugin
Unity Bitmapfontimporter
An unity editor extension for bitmap font.
Stars: ✭ 139 (-5.44%)
Mutual labels:  unity-editor, unity3d-plugin
t4-templates-unity3d
T4 Text Template Processor for Unity3D
Stars: ✭ 75 (-48.98%)
Mutual labels:  unity-editor, unity3d-plugin
PrefabEditor
You can edit Prefab which could not be edited much unless you place it on Scene.
Stars: ✭ 23 (-84.35%)
Mutual labels:  unity-editor, unity3d-plugin
Dart native
Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.
Stars: ✭ 564 (+283.67%)
Mutual labels:  native, runtime
LMS.Version
Super simple auto build version tool
Stars: ✭ 40 (-72.79%)
Mutual labels:  unity-editor, unity3d-plugin

Tool created mainly to solve the old problem with reloading native plugins without the need to reopen Unity Editor.

Overview

  • Automatically unloads native plugins after stopping the game and loads them when needed.
  • You can unload/reload them manually, even when the game is running.
  • No code change is required - use usual [DllImport].
  • Low level interface callbacks UnityPluginLoad and UnityPluginUnload do fire - to enable them see this section.
  • Works on Windows, Linux and Mac, but only on x86/x86_64 processors.
  • Ability to log native calls to file in order to diagnose crashes caused by them.

Installation

  1. Either download and add unity package from releases, or clone this repo into the assets of your project.

    • Clone it into the <Project Root>/Packages folder to use it as a local embedded package with upm.
  2. In project settings, set Api Compatibility Level to .NET 4.x or above. Edit > Project Settings > Player > Other Settings > Api Compatibility Level

  3. Check Allow 'unsafe' code. Edit > Project Settings > Player > Other Settings > Allow 'unsafe' code

  4. One of the gameobjects in the scene needs to have DllManipulatorScript on it. (This script calls DontDestroayOnLoad(gameObject) and deletes itself when a duplicate is found in order to behave nicely when switching scenes).

Usage

  • Your plugin files must be at path specified in options. By default, just add __ (two underscores) at the beginning of your dll files in the Assets/Plugins folder (e.g. on Windows, plugin named FastCalcs should be at path Assets\Plugins\__FastCalcs.dll).
  • By default, all extern methods in the main scripts assembly will be mocked (i.e. handled by this tool instead of Unity, allowing them to be unloaded). You can change this in options and use provided attributes to specify that yourself (they are in UnityNativeTool namespace, file Attributes.cs).
  • Options are accessible via DllManipulatorScript editor or window.
  • You can also unload and load all DLLs via shortcut, Alt+D and Alt+Shfit+D respectively. Editable in the Shortcut Manager for 2019.1+
  • You can get callbacks in your C# code when the load state of a DLL has changed with attributes like [NativeDllLoadedTrigger]. See Attributes.cs.
  • Although this tool presumably works in the built game, it's intended to be used only during development.
  • If something doesn't work, first check out available options (and read their descriptions), then report an issue.

Low level interface callbacks support

For that, you'll need a StubLluiPlugin DLL. I only embed it into .unitypackage for x64 Windows platform, so for other cases you'll need to compile it manually.

This is, compile the file ./stubLluiPlugin.c into the dynamic library (name it StubLluiPlugin, no underscores) and put into Unity like you would do with other plugins.

Limitations

  • Native callbacks UnityRenderingExtEvent and UnityRenderingExtQuery do not fire.
  • Only some basic attributes on parameters of extern methods (such as [MarshalAs] or [In]) are supported.
  • Properties MarshalCookie, MarshalType, MarshalTypeRef and SafeArrayUserDefinedSubType on [MarshalAs] attribute are not supported (due to Mono bug).
  • Explicitly specifying UnmanagedType.LPArray in [MarshalAs] is not supported (due to another Mono bug). Note that this should be the default for array types, so in trivial situations you don't need to use it anyway.
  • Properties ExactSpelling and PreserveSig of [DllImport] attribute are not supported.
  • Calling native functions from static constructors generally won't work. Although the rules are more relaxed, you usually shouldn't even attempt to do that in the first place. Note that in C# static constructors don't fire on their own.
  • Additional threads that execute past OnApplicationQuit event are not-very-well handled (usually not something to worry about).

Troubleshooting & advanced usage

  • The path in the DLL path pattern option cannot be simply set to {assets}/Plugins/{name}.dll as it would interfere with Unity's plugin loading - hence the underscores.
  • In version 2019.3.x Unity changed behaviour of building. If you want to use this tool in the built game (although preferably just for development) you should store your plugins in architecture-specific subfolders and update the DLL path pattern option accordingly, e.g. {assets}/Plugins/x86_64/__{name}.dll.
  • The UnityNativeTool.DllManipulatorScript script by default has an execution order of -10000 to make it run first. If you have a script that has even lower execution order and that scripts calls a DLL, then you should make sure that UnityNativeTool.DllManipulatorScript runs before it, e.g. by further lowering its execution order.

Performance

Configuration Relative call time
Vanilla Unity 100%
Preloaded mode ~150%
Lazy mode ~190%
With thread safety ~430%

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].