Mapping and GIS Solutions Community

 View Only
Expand all | Collapse all

Unity 3D and dll library

  • 1.  Unity 3D and dll library

    Posted 12-15-2018 17:30

    Hello there,

     

    I just got Trimble Catalyst device, works well with apps on the store.

     

    I am trying to use SDK on Unity 3D, dll library from Xamarin doesn't seems to work, so I used ikvm to convert jar to dll to be recognized on sdk method.

     

    Do you have any experience or feedback for unity 3D ? I am on 2018.1 version.

     

    Here is the error (not very aqccurate) produce by code bellow.

     

    Thanks you in advance,

     

    Error: An exception was thrown by the type initializer for trimble.jssi.android.catalystfacade.CatalystFacade

     

    code:


            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");
            Debug.Log("start Call");
            try
            {
                _facade = new CatalystFacade(AppGuid, context);
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
            }



  • 2.  Re: Unity 3D and dll library

    Posted 12-19-2018 01:02

    Hello everyone,

     

    To you have any news ? Or know how to use dll function without conversion from Unity without crash ?

     

    Thanks you in advance,

     

    Max.



  • 3.  Re: Unity 3D and dll library

    Posted 12-19-2018 13:32

    Hi Max,

     

    Have you considered using Trimble Mobile Manager (TMM) to feed the DA1 positions into Location Services and then have your Unity App use the standard location API???

     

    Afraid I can't claim to be a Unity Expert (or even developer) but here's some general advice...

    - carefully match .NET versions.

    - ensure all your 3rd party DLLs are in the Asset folder structure.

    - consider going the long way around and load JARs rather than converting.

     

    Thanks for sharing the code snippet, but for future reference you left out the key bit of info... the specific exception that was occurring.

     

     

    Denis



  • 4.  Re: Unity 3D and dll library

    Posted 01-06-2019 17:14

    Hi, Max.

     

    I am not sure how you set up it and I haven't had any experiences with the SDK. 

     

    First, if you put the DLL files with the correct .net version in the correct location in the Unity project.

    Unity would load the DLL automatically. If not, it is .net version problem. 

     

            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");

     

    There are a variety of ways to connect the java plugin. I cannot answer it with this simple code. 

    How did you build the java plugin? And what exception does the code throw?

     

    Han.



  • 5.  Re: Unity 3D and dll library

    Posted 01-19-2019 09:45

    Hello Denis and Hyungon,

     

    At first, best wishes for the new year 2019 !

     

    Thanks you very much for your response.

     

    To be fast on our problems, we didn't succeed to cast "AndroidJavaObject" to "Context" for DriverManager.

     

    Denis, we successfully configure Unity with .NET 4.X version. DLL import works perfectly (from Xamarin SDK), and we can use assembly class on using. We copy Catalyst.Droid abstract class from sample and no error on compilation

     

    Otherwise, Hyungon, even is the .NET version seems OK, we have a problem to use DriverManager object. For now, we need to use this part of code:

     

    public CatalystFacade(string appGuid, Context context)
    {
    _appGuid = appGuid;
    _driverManager = new DriverManager(_appGuid, context);
    _context = context;
    }

     

    And we want to instantiate CatalaystFacade like this:


    AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");
    _facade = new CatalystFacade.Droid.CatalystFacade(AppGuid, context);

     

    But last line, type is not the good one: AndroidJavaObject can not be Context type. We have tried to cast, or to use trick:

    Context context = activity.Call<Context>("getApplicationContext");

    we have an error from java lib:

    JNI: Unkown signature for Type 'Android.Content.Context' (obj = Android.Content.Context) equal

     

    We are stuck on this type: DriverManager want a Context type (recognized on visual code editor, with Mono.Android.dll imported), but we have only a AndroidJavaObject on Unity.

     

    We are open to any advices !

     

    Thanks you for your help,

     

    Max.

     

    PS: Some useful details:

     

     

     



  • 6.  Re: Unity 3D and dll library

    Posted 01-20-2019 19:27

    Hi, Max.

    I think you are showing the project explorer in Unity.

    If you open the visual studio or Mono, you can find the references under the project name.

    Your dlls must be shown in the references. If not, they are not proper dlls for Unity. 



  • 7.  Re: Unity 3D and dll library

    Posted 02-13-2019 11:07

    Thanks you Kim. It's to complex to use Unity with driver, we used java SDK in android app.

    Thanks for all.