void OnEnable()
    {
        Debug.Log("ServoUnityController.OnEnable()");

        servo_unity_plugin = new ServoUnityPlugin();

        Application.runInBackground = true;

        // Register the log callback.
        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:     // Unity Editor on OS X.
        case RuntimePlatform.OSXPlayer:     // Unity Player on OS X.
        case RuntimePlatform.WindowsEditor: // Unity Editor on Windows.
        case RuntimePlatform.WindowsPlayer: // Unity Player on Windows.
        case RuntimePlatform.LinuxEditor:
        case RuntimePlatform.LinuxPlayer:
        case RuntimePlatform.WSAPlayerX86: // Unity Player on Windows Store X86.
        case RuntimePlatform.WSAPlayerX64: // Unity Player on Windows Store X64.
        case RuntimePlatform.WSAPlayerARM: // Unity Player on Windows Store ARM.
        case RuntimePlatform.Android:      // Unity Player on Android.
        case RuntimePlatform.IPhonePlayer: // Unity Player on iOS.
            servo_unity_plugin.ServoUnityRegisterLogCallback(Log);
            servo_unity_plugin.ServoUnitySetLogLevel((int)currentLogLevel);
            break;

        default:
            break;
        }

        // Give the plugin a place to look for resources.

        string resourcesPath = Application.streamingAssetsPath;

        servo_unity_plugin.ServoUnitySetResourcesPath(resourcesPath);

        // Set any launch-time parameters.
        if (DontCloseNativeWindowOnClose)
        {
            servo_unity_plugin.ServoUnitySetParamBool(ServoUnityPlugin.ServoUnityParam.b_CloseNativeWindowOnClose, false);
        }
        if (!String.IsNullOrEmpty(Homepage))
        {
            servo_unity_plugin.ServoUnitySetParamString(ServoUnityPlugin.ServoUnityParam.s_Homepage, Homepage);
        }

        // Set the reference to the plugin in any other objects in the scene that need it.
        ServoUnityWindow[] servoUnityWindows = FindObjectsOfType <ServoUnityWindow>();
        foreach (ServoUnityWindow w in servoUnityWindows)
        {
            w.servo_unity_plugin = servo_unity_plugin;
        }
    }
    void OnDisable()
    {
        Debug.Log("ServoUnityController.OnDisable()");

        // Clear the references to the plugin in any other objects in the scene that have it.
        ServoUnityWindow[] servoUnityWindows = FindObjectsOfType <ServoUnityWindow>();
        foreach (ServoUnityWindow w in servoUnityWindows)
        {
            w.servo_unity_plugin = null;
        }

        servo_unity_plugin.ServoUnitySetResourcesPath(null);

        // Since we might be going away, tell users of our Log function
        // to stop calling it.
        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.OSXPlayer:
        case RuntimePlatform.WindowsEditor:
        case RuntimePlatform.WindowsPlayer:
        case RuntimePlatform.LinuxEditor:
        case RuntimePlatform.LinuxPlayer:
        case RuntimePlatform.WSAPlayerX86:
        case RuntimePlatform.WSAPlayerX64:
        case RuntimePlatform.WSAPlayerARM:
        case RuntimePlatform.Android:
        case RuntimePlatform.IPhonePlayer:
            servo_unity_plugin.ServoUnityRegisterLogCallback(null);
            break;

        default:
            break;
        }

        servo_unity_plugin = null;
    }