Search Unity

Platform Specific Managed DLL

Discussion in 'Immediate Mode GUI (IMGUI)' started by antoine-agthe, Apr 25, 2015.

  1. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    Hey,

    I try to distribute a bunch of "plugins" for Unity 4.x written in C# and some of them are platform specific (one DLL par target system) or have some Editor special behaviours (with UNITY_EDITOR symbol defined).

    I took a close look on the UI System C# Solution and I reproduced the configuration.
    I created a "common" library, then I created some "platform specific" libraries that reference the whole "common" library source code, and defines UNITY_EDITOR/UNITY_ANDROID/UNITY_IOS compilation symbols.

    So I produced some DLL assemblies that I organized as following:

    • Plugins/
      • [MyPlugin]/
        • Android/
          • [MyPlugin].dll <-- with UNITY_ANDROID symbol
        • iOS
          • [MyPlugin].dll <-- with UNITY_IOS symbol
        • Standalone
          • [MyPlugin].dll <-- with UNITY_STANDALONE symbol
        • [MyPlugin].dll <-- with UNITY_EDITOR symbol

    But in Editor the Standalone version of the managed DLL is always loaded.

    It only works if I put everything as an Extension of my Editor (like GUISystem, in the editor installation folder with an ivy.xml file), but it's not an great way to share plugins as users have to have access to the installation folder.

    I there a way to take benefits of Platform Specific deployment with managed DLL ?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    A few things to note:

    1. With Unity 4.x you have to place plugins in a specially named folder. AFAIK, this has to be Plugins/[platform] and not under a root folder MyPlugin like in your example.
    2. Unity 5 (partially) solves this issue by having a "Plugin Inspector" that knows to associate certain file extensions as plugins, and so you can place your plugins in whatever folder structure you like.
    3. Symbols do not have any effect inside of DLLs. I assume you meant that the DLLs under a specific folder were compiled with the relevant symbol?
    I think this should work with the following folder structure:

    Plugins/Android
    Plugins/iOS
    Plugins/Editor
    Plugins/x86 (for standalone)

    See this document for reference (not sure it's up to date: http://wiki.unity3d.com/index.php/Special_Folder_Names_in_your_Assets_Folder)
     
  3. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    So I tried to put my managed DLL under the Plugins folder directly but it still doesn't work.

    Of course ^^

    Let me give you more details.

    My Xamarin solution consists in 5 projects:
    • MyAssembly
      Contains the source code, using Symbols to use platform specific lines of code (UNITY_EDITOR, UNITY_IOS, UNITY_ANDROID, UNITY_STANDALONE).
      This assembly is not compiled at all.
    • MyAssembly-Android
      References the whole code from MyAssembly, and defines UNITY_ANDROID as compilation symbol.
      So the resulting DLL only contains Android specific code and the target DLL is Assets/Plugins/Android/MyAssembly.dll
    • MyAssembly-iOS
      References the whole code from MyAssembly, and defines UNITY_IOS as compilation symbol.
      So the resulting DLL only contains iOS specific code and the target DLL is Assets/Plugins/iOS/MyAssembly.dll
    • MyAssembly-x86_64
      References the whole code from MyAssembly, and defines UNITY_STANDALONE as compilation symbol.
      So the resulting DLL only contains Android specific code and the target DLL is Assets/Plugins/x86_64/MyAssembly.dll
    • MyAssembly-Editor
      References the whole code from MyAssembly, and defines UNITY_EDITOR as compilation symbol.
      So the resulting DLL only contains Editor specific code and the target DLL is Assets/Plugins/MyAssembly.dll (because putting it to an Editor folder seems that it is Editor assembly, but I need Runtime code that runs in editor)
    It appears that Unity completely ignores my strategy and choose to load MyAssembly-x86_64, not because it is for Standalone, but because it is the last it loads: when I remove the x86_64 specific DLL, unity loads the MyAssembly-iOS version, even if my Build Settings defines Android as target platform, and so on when I remove the iOS version.

    I've attached the sample project (Unity project + C# Solution)
     

    Attached Files:

  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Looking at your solution and setup - everything looks fine - The code gets compiled with the correct compilation symbols.

    How are you verifying that "Unity ignores your strategy" ?

    I am on Unity 5, it seems that all DLLs were marked with the correct platform in the inspector, except for the x86_64 one, which i had to manually set to the right platform.
     
  5. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    I'm sure this works better with Unity 5 as we can set the import settings manually.
    But I work with Unity 4.x (4.6.3 exactly)

    Unity ignores the way I organize my DLL files (platform-specific folders) and loads a randomish one.
     
  6. rlyle1179

    rlyle1179

    Joined:
    Oct 3, 2012
    Posts:
    5
    I'm hitting the same issue, have you managed to figure out what's happening with Unity 4.6.X ?
     
  7. antoine-agthe

    antoine-agthe

    Joined:
    Nov 1, 2012
    Posts:
    15
    Sorry to replay so late.
    I am now developing on Unity 5.X so I don't look for a solution for Unity 4.X anymore.
     
  8. BraveSirAndrew

    BraveSirAndrew

    Joined:
    Jan 29, 2013
    Posts:
    2
    Late to this party, but could the problem be that the Plugins folder is reserved for unmanaged i.e. C++, stuff? As far as I can tell, if you put your managed assemblies anywhere else under the Assets folder, they will get referenced properly by Unity . You may have put them in the one place where they won't work:)