Exemplo n.º 1
0
    private void Dispose(bool disposing)
    {
        // Prevent multiple calls to Dispose
        if (this.disposed)
        {
            return;
        }

        // Was dispose called explicitly by the user?
        if (disposing)
        {
            // Dispose managed resources (those that implement IDisposable)
        }

        // Clean up unmanaged resources
        if (!VLUnitySdk.RemoveLogListener(dispatchLogCallbackDelegate,
                                          GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to remove log listener");
        }

        // Release the handle to the current object
        this.gcHandle.Free();

        this.disposed = true;
    }
Exemplo n.º 2
0
 public void SetLogBufferSize(int maxEntries)
 {
     if (maxEntries < 0)
     {
         Debug.LogWarning("[vlUnitySDK] LogBufferSize must be zero or larger");
         return;
     }
     VLUnitySdk.SetLogBufferSize(Convert.ToUInt32(maxEntries));
 }
Exemplo n.º 3
0
    public VLLogger()
    {
        this.gcHandle = GCHandle.Alloc(this);

        if (!VLUnitySdk.AddLogListener(dispatchLogCallbackDelegate,
                                       GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to add log listener");
        }
    }
    private void UpdateScreenOrientation()
    {
        ScreenOrientation currentOrientation = GetScreenOrientation();

        // Orientation not changed?
        if (currentOrientation == this.orientation)
        {
            return;
        }

        // The screen orientation should never be 'AutoRotation'
        if (currentOrientation == ScreenOrientation.AutoRotation)
        {
            Debug.LogWarning("[vlUnitySDK] Cannot derive correct screen orientation");
            return;
        }

        // Tell the native code about the new screen orientation
        if (currentOrientation == ScreenOrientation.Portrait)
        {
            VLUnitySdk.SetScreenOrientation(0);
        }
        else if (currentOrientation == ScreenOrientation.PortraitUpsideDown)
        {
            VLUnitySdk.SetScreenOrientation(1);
        }
        else if (currentOrientation == ScreenOrientation.LandscapeLeft)
        {
            VLUnitySdk.SetScreenOrientation(2);
        }
        else if (currentOrientation == ScreenOrientation.LandscapeRight)
        {
            VLUnitySdk.SetScreenOrientation(3);
        }
        else
        {
            // Unity returns an undocumented value for the screen
            // orientation on iOS for the first few update iterations.
            //Debug.LogWarning("[vlUnitySDK] Unsupported ScreenOrientation: " +
            //    currentOrientation);
            return;
        }

        this.orientation = currentOrientation;

        // Emit change event
        if (OnOrientationChange != null)
        {
            OnOrientationChange(this.orientation);
        }
    }
Exemplo n.º 5
0
 /// <summary>
 /// Writes this WorkSpace.Configuration into the specified file.
 /// </summary>
 /// <param name="fileName">Path of the file to write the data in.</param>
 /// <remarks>
 ///  <para>
 ///   It's possible to use vlSDK file schemes (e.g. local_storage_dir) here.
 ///  </para>
 /// </remarks>
 public void WriteToFile(string fileName)
 {
     VLUnitySdk.Set(fileName, VLJsonUtility.ToJson(this), "");
 }
Exemplo n.º 6
0
 public bool Log(string message, VLUnitySdk.LogLevel level)
 {
     return(VLUnitySdk.Log(message, level));
 }
Exemplo n.º 7
0
 public bool SetLogLevel(VLUnitySdk.LogLevel level)
 {
     return(VLUnitySdk.SetLogLevel(level));
 }
Exemplo n.º 8
0
 public VLUnitySdk.LogLevel GetLogLevel()
 {
     return(VLUnitySdk.GetLogLevel());
 }
Exemplo n.º 9
0
 public bool FlushLogBuffer()
 {
     return(VLUnitySdk.FlushLogBuffer());
 }
Exemplo n.º 10
0
 public void DisableLogBuffer()
 {
     VLUnitySdk.DisableLogBuffer();
 }
Exemplo n.º 11
0
 public void EnableLogBuffer()
 {
     VLUnitySdk.EnableLogBuffer();
 }
Exemplo n.º 12
0
    private void Awake()
    {
        // Get a handle to the current object and make sure, that the object
        // doesn't get deleted by the garbage collector. We then use this
        // handle as client data for the native callbacks. This allows us to
        // retrieve the current address of the actual object during the
        // callback execution. GCHandleType.Pinned is not necessary, because we
        // are accessing the address only through the handle object, which gets
        // stored in a global handle table.
        this.gcHandle = GCHandle.Alloc(this);

        // Print the version of the vlUnitySDK. If this works, then we can be
        // quite certain, that other things also work.

        string version;
        string versionTimestamp;
        string versionHash;

        if (VLUnitySdk.GetVersionString(out version) &&
            VLUnitySdk.GetVersionTimestampString(out versionTimestamp) &&
            VLUnitySdk.GetVersionHashString(out versionHash))
        {
            Debug.Log("[vlUnitySDK] v" + version + " (" +
                      versionTimestamp + ", " + versionHash + ")");
        }
        else
        {
            Debug.LogWarning("[vlUnitySDK] Failed to get version strings");
        }

        // Construct the path to the directory with the tracking configurations,
        // if it wasn't specified explicitly
        if (String.IsNullOrEmpty(this.baseDir))
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            this.baseDir = "file:///android_asset/VisionLib";
#else
            this.baseDir = Path.Combine(
                Application.streamingAssetsPath, "VisionLib");
#endif
        }

        // Construct the path to the Resources folder (the Resource folder is
        // only used by certain platforms)
#if UNITY_ANDROID && !UNITY_EDITOR
        this.resourceDir = "file:///android_asset/VisionLib/Resources";
#else
        this.resourceDir = Path.Combine(
            Application.streamingAssetsPath, "VisionLib/Resources");
#endif

        // Create an AbstractApplication, which will manage the ActionPipe and
        // DataSet

        this.aap = new VLAbstractApplicationWrapper();

        this.deviceInfo = this.aap.GetDeviceInfo();

// Set the path to the license file
#if UNITY_ANDROID && !UNITY_EDITOR
        string absoluteLicenseFilePath = Path.Combine(
            "file:///android_asset/", this.licenseFile.path);
#else
        string absoluteLicenseFilePath = Path.Combine(
            Application.streamingAssetsPath, this.licenseFile.path);
#endif

        this.aap.SetLicenseFilePath(absoluteLicenseFilePath);

        // Add a log listener, which will write all VisionLib logs to the
        // Unity console

        this.logger = new VLLogger();
#if UNITY_2017_1_OR_NEWER
        // Unity 2017 with Mono .NET 4.6 as scripting runtime version can't
        // properly handle callbacks from external threads. Until this is
        // fixed, we need to buffer the log messages and fetch them from the
        // main thread inside the update function.
        this.logger.EnableLogBuffer();
#else
        this.logger.DisableLogBuffer();
#endif
        this.logger.SetLogLevel(this.logLevel);

        // Print the host ID. This ID is needed for generating a license file.

        string hostID;
        if (this.aap.GetHostID(out hostID))
        {
            Debug.Log("[vlUnitySDK] HostID=" + hostID);
        }
        else
        {
            Debug.LogWarning("[vlUnitySDK] Failed to get host ID");
        }

        // Many VisionLib features are implemented as plugins, which we need
        // to load first

        string pluginPath = Application.dataPath +
                            Path.DirectorySeparatorChar + "Plugins";

        // The plugins are in architecture specific sub-directories before the
        // deployment
#if UNITY_EDITOR
        pluginPath += Path.DirectorySeparatorChar + VLUnitySdk.subDir;
#endif
        this.aap.AutoLoadPlugins(pluginPath);

        // Create worker instance and register listeners for it

        this.worker = new VLWorker(this.aap);

        if (!this.worker.AddImageListener(
                dispatchImageCallbackDelegate,
                GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to add image listener");
        }
        if (!this.worker.AddExtrinsicDataListener(
                dispatchExtrinsicDataCallbackDelegate,
                GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to add extrinsic data listener");
        }
        if (!this.worker.AddIntrinsicDataListener(
                dispatchIntrinsicDataCallbackDelegate,
                GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to add intrinsic data listener");
        }
        if (!this.worker.AddTrackingStateListener(
                dispatchTrackingStateCallbackDelegate,
                GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to add tracking state listener");
        }
        if (!this.worker.AddPerformanceInfoListener(
                dispatchPerformanceInfoCallbackDelegate,
                GCHandle.ToIntPtr(this.gcHandle)))
        {
            Debug.LogWarning("[vlUnitySDK] Failed to add performance info listener");
        }
    }