/// <summary>
        /// Disconnect current output device and connect a new one of given type and (optional) ID.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        public void GetNewOutputDevice(OutputDeviceType type, uint id = 0)
        {
            DisconnectOutputDevice();
            switch (type)
            {
            case OutputDeviceType.Keyboard:
                Keyboard.Connect();
                OutputDevice = Keyboard;
                break;

            case OutputDeviceType.vJoy:
                VJoy.Connect(id);
                OutputDevice = VJoy;
                break;

            case OutputDeviceType.vXbox:
                VXbox.Connect();
                OutputDevice = VXbox;
                break;

            case OutputDeviceType.OpenVRInject:
                Inject.Connect();
                OutputDevice = Inject;
                break;

            default:
                break;
            }
        }
    private void Awake()
    {
        if (instance != null)
        {
            Destroy(this);
            return;
        }

        if (!CriAtomPlugin.IsLibraryInitialized())
        {
            Debug.LogError("[CRIWARE] Atom library is not initialized. Cannot setup CriAtomExOutputDeviceObserver.");
            Destroy(this);
            return;
        }

        instance = this;

#if CRIWAREPLUGIN_SUPPORT_OUTPUTDEVICE_OBSERVER
#if !UNITY_EDITOR && UNITY_IOS
        bool isStarted = UnsafeNativeMethods.criAtomUnity_StartOutputDeviceObserver_IOS();
        if (!isStarted)
        {
            Debug.LogError("[CRIWARE] CriAtomOutputDeviceObserver cannot start while Atom library is not initialized.");
        }
#elif !UNITY_EDITOR && UNITY_ANDROID
        UnityEngine.AndroidJavaClass  jc       = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer");
        UnityEngine.AndroidJavaObject activity = jc.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity");

        if (checker == null)
        {
            checker = new UnityEngine.AndroidJavaObject("com.crimw.crijavaclasses.CriOutputDeviceObserver", activity, this.gameObject.name, "CallbackFromObserver_ANDROID");
        }
        if (checker == null)
        {
            Debug.LogError("[CRIWARE] Cannot load CriOutputDeviceObserver class in library.");
        }
        checker.Call("Start", activity);
        CheckOutputDevice_ANDROID();
#endif
        isConnected = lastIsConnected = IsDeviceConnected;
        deviceType  = lastDeviceType = DeviceType;
        if (_onDeviceConnectionChanged != null)
        {
            _onDeviceConnectionChanged(isConnected, deviceType);
        }
#elif !UNITY_EDITOR
        Debug.Log("[CRIWARE] CriAtomOutputDeviceObserver is not supported on this platform.");
#endif
        if (this.dontDestroyOnLoad)
        {
            GameObject.DontDestroyOnLoad(this.gameObject);
        }
    }
    private void CheckOutputDevice_ANDROID()
    {
        if (checker == null)
        {
            return;
        }

        UnityEngine.AndroidJavaClass  jc       = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer");
        UnityEngine.AndroidJavaObject activity = jc.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity");
        int device = checker.Call <int>("CheckOutputDeviceType", activity);

        deviceType  = (OutputDeviceType)device;
        isConnected = (deviceType != OutputDeviceType.BuiltinSpeaker);
    }
    public override void CriInternalUpdate()
    {
        isConnected = IsDeviceConnected;
        deviceType  = DeviceType;

        if ((isConnected != lastIsConnected ||
             deviceType != lastDeviceType) &&
            _onDeviceConnectionChanged != null)
        {
            _onDeviceConnectionChanged(isConnected, deviceType);
        }
        lastIsConnected = isConnected;
        lastDeviceType  = deviceType;
    }
Ejemplo n.º 5
0
        public static Writer Create(OutputDeviceType device)
        {
            switch (device)
            {
            case OutputDeviceType.Console:
                return(new ConsoleWriter());

            case OutputDeviceType.Database:
                return(new DatabaseWriter());

            case OutputDeviceType.Mobile:
                return(new MobileWriter());

            default:
                throw new NotImplementedException(string.Format("Output device type of {0} is not supported.", device));
            }
        }