Пример #1
0
 protected virtual void Awake()
 {
     //
     if (s_Instance == null)
     {
         Log.i("ControllerInputManager", "Initialize successfully.");
         s_Instance = this;
     }
     else if (s_Instance != this)
     {
         Log.e("ControllerInputManager", "Only one instance can be run!!!");
     }
     else
     {
         //Log.i("ControllerInputManager","Initialize again.");
         return;
     }
     //
     if (dontDestroyOnLoad)
     {
         transform.SetParent(null, false);
         DontDestroyOnLoad(this);
     }
     //
     SendMessage("OnStart", SendMessageOptions.DontRequireReceiver);
     //
     InitAllControllerInputs();
 }
Пример #2
0
 /// <summary>
 /// Init X-Hawk for different user environments.
 /// </summary>
 public virtual bool InitInternal()
 {
     //
     XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_TrackingOriginInt, (int)VRContext.trackingOrigin);
     XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 0, 0);
     //
     if (true)
     {
         int i = 0, imax = m_Controllers.Length;
         controllers = new TrackedControllerInput[imax];
         //
         ControllerInputManager mgr = ControllerInputManager.instance;
         ControllerInput        ci;
         if (mgr != null)
         {
             for (; i < imax; ++i)
             {
                 ci = mgr.GetControllerInput(m_Controllers[i].key);
                 if (ci is TrackedControllerInput)
                 {
                     controllers[i] = ci as TrackedControllerInput;
                     controllers[i].inputTracking = this;
                     controllers[i].node          = m_Controllers[i].value;
                 }
                 else
                 {
                     controllers[i] = CreateControllerInput(m_Controllers[i].key, this, m_Controllers[i].value);
                     if (controllers[i].handle != -1)
                     {
                         mgr.AddControllerInput(controllers[i].name, controllers[i]);
                     }
                     else
                     {
                         controllers[i] = null;
                     }
                 }
                 //
                 if (i < 2)
                 {
                     m_EmulatedHands[i].Controller = controllers[i];
                     m_EmulatedHands[i].followGaze = ArmModel.GazeBehavior.Always;
                     m_EmulatedHands[i].Start();
                 }
             }
         }
     }
     // VR Context
     m_HmdInput = ControllerInputManager.GetInput(ControllerType.Hmd);
     // VRContext must have a CenterEyeAnchor at least.
     m_IsRequestVR = (VRContext.GetAnchor(VRNode.CenterEye) != null);
     EnsureAnchor();
     //
     Log.i("XHawkInput", "Initialize successfully.");
     //
     return(true);
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 public virtual bool InitInternal()
 {
     if (m_IsInited)
     {
         return(true);
     }
     m_IsInited = true;
     // Plugin context.
     deviceName = "XHawk-0";
     if (m_Handle == -1)
     {
         m_Handle = XDevicePlugin.GetInputDeviceHandle(deviceName);
     }
     XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_TrackingOriginInt, (int)VRContext.trackingOrigin);
     XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 0, 0);
     //
     if (true)
     {
         int i = 0, imax = m_Controllers.Length;
         controllers = new TrackedControllerInput[imax];
         //
         ControllerInputManager mgr = ControllerInputManager.instance;
         ControllerInput        ci;
         if (mgr != null)
         {
             for (; i < imax; ++i)
             {
                 ci = mgr.GetControllerInput(m_Controllers[i].key);
                 if (ci is TrackedControllerInput)
                 {
                     controllers[i] = ci as TrackedControllerInput;
                     controllers[i].inputTracking = this;
                     controllers[i].node          = m_Controllers[i].value;
                 }
                 else
                 {
                     controllers[i] = CreateControllerInput(m_Controllers[i].key, this, m_Controllers[i].value);
                     mgr.AddControllerInput(controllers[i].name, controllers[i]);
                 }
             }
         }
     }
     // VR Context
     m_HmdInput = ControllerInputManager.GetInput(ControllerType.Hmd);
     // VRContext must have a CenterEyeAnchor at least.
     m_IsRequestVR = (VRContext.GetAnchor(VRNode.CenterEye) != null);
     EnsureAnchor();
     //
     Log.i("XHawkInput", "Initialize successfully.");
     //
     return(true);
 }
Пример #4
0
 public virtual int InitInput()
 {
     if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x1000)
     {
         return(-1);
     }
     // Override ControllerInput in ControllerInputManager.
     if (true)
     {
         //
         ControllerInputManager mgr = ControllerInputManager.instance;
         ControllerInput        ci;
         if (mgr != null)
         {
             for (int i = 0, imax = m_Controllers.Length; i < imax; ++i)
             {
                 if (m_Controllers[i].handedness != ControllerType.None)
                 {
                     ci = mgr.GetControllerInput(m_Controllers[i].name);
                     if (ci is TrackedControllerInput)
                     {
                         m_Controllers[i].Controller = ci as TrackedControllerInput;
                         m_Controllers[i].Controller.inputTracking = m_Controllers[i];
                         m_Controllers[i].Controller.node          = -1;
                     }
                     else
                     {
                         m_Controllers[i].Controller = new TrackedControllerInput(m_Controllers[i].name, m_Controllers[i], -1);
                         if (m_Controllers[i].Controller.handle != -1)
                         {
                             mgr.AddControllerInput(m_Controllers[i].name, m_Controllers[i].Controller);
                         }
                         else
                         {
                             m_Controllers[i].Controller = null;
                         }
                     }
                     //
                     m_Controllers[i].Start();
                 }
             }
         }
         else
         {
             return(-1);
         }
     }
     //
     return(0);
 }
 public override void Recenter()
 {
     //
     for (int i = 0, imax = controllers.Length; i < imax; ++i)
     {
         controllers[i].OnVRContextRecenter();
     }
     //
     if ((ControllerInputManager.GetButtonDown(ControllerType.LeftController, (uint)XimmerseButton.Home) && ControllerInputManager.GetButton(ControllerType.RightController, (uint)XimmerseButton.Home)) ||
         (ControllerInputManager.GetButton(ControllerType.LeftController, (uint)XimmerseButton.Home) && ControllerInputManager.GetButtonDown(ControllerType.RightController, (uint)XimmerseButton.Home))
         )
     {
         XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 1, 0);
         UpdateAnchorFromPlugin();
         //
         if (m_PlayAreaHelper != null)
         {
             m_PlayAreaHelper.OnTrackerRecenter();
         }
     }
 }
Пример #6
0
 public override void Recenter()
 {
     //
     if (useAutoRecenter)
     {
         AlignHmd();
         return;
     }
     // Legacy method.
     RecenterAllControllers(0.0f);
     //
     if ((ControllerInputManager.GetButtonDown(ControllerType.LeftController, (uint)XimmerseButton.Home) && ControllerInputManager.GetButton(ControllerType.RightController, (uint)XimmerseButton.Home)) ||
         (ControllerInputManager.GetButton(ControllerType.LeftController, (uint)XimmerseButton.Home) && ControllerInputManager.GetButtonDown(ControllerType.RightController, (uint)XimmerseButton.Home))
         )
     {
         XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 1, 0);
         UpdateAnchorFromPlugin();
         //
         if (m_PlayAreaHelper != null)
         {
             m_PlayAreaHelper.OnTrackerRecenter();
         }
     }
 }
Пример #7
0
        /// <summary>
        /// This function will be called by ControllerInputManager or Start().
        /// XCobra controller's position will be overwritten by this class.
        /// </summary>
        public virtual void Launch(bool checkOthers)
        {
            if (m_IsLaunched)
            {
                return;
            }
            m_IsLaunched = true;
            //
            deviceName = "XHawk-0";
            if (checkOthers)
            {
                XHawkInput other = FindAll(deviceName).Find((x) => (x != this)) as XHawkInput;
                if (other != null)
                {
                    // This will be not found by TrackingInput.Find(string).
                    gameObject.SetActive(false);
                    other.Launch(false);
                    //Log.i("XHawkInput","Use the default TrackingInput in scene.");
                    return;
                }
            }
            //
            XDevicePlugin.Init();
            if (m_Handle == -1)
            {
                m_Handle = XDevicePlugin.GetInputDeviceHandle(deviceName);
            }
            m_HmdHandle = XDevicePlugin.GetInputDeviceHandle("VRDevice");
            XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_TrackingOrigin, (int)VRContext.trackingOrigin);
            // Set values to the plugin
            if (overridePlugin)             //&&m_Handle>0) {
            {
                if ((XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0x4000) & 0xF000) == 0x4000)
                {
                    Vector3 trackerPos = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].position", new Vector3(0.0f, 1.675f, 1.5f));
                    Vector3 trackerRot = PlayerPrefsEx.GetVector3("XimmerseTracker[Outside-in].rotation", new Vector3(15.0f, 180.0f, 0.0f));
                    XDevicePlugin.SetTrackerPose(m_Handle, trackerPos.y, trackerPos.z, -trackerRot.x);
                }
            }
            // TODO :
            XDevicePlugin.SendMessage(m_Handle, XDevicePlugin.kMessage_RecenterSensor, 0, 0);
            //
#if XDEVICE_RELEASE
            //if((XDevicePlugin.GetInt(-1,XDevicePlugin.kField_CtxDeviceVersion,0x4000)&0xF000)!=0x4000)
#endif
            {
                int i = 0, imax = controllers.Length;
                inputs = new XCobraInput[imax];
                //
                ControllerInputManager mgr = ControllerInputManager.instance;
                ControllerInput        ci;
                if (mgr != null)
                {
                    for (; i < imax; ++i)
                    {
                        ci = mgr.GetControllerInput(controllers[i].key);
                        if (ci is XCobraInput)
                        {
                            inputs[i] = ci as XCobraInput;
                        }
                        else
                        {
                            inputs[i] = new XCobraInput(this, controllers[i].key, controllers[i].value);
                            mgr.AddControllerInput(inputs[i].name, inputs[i]);
                        }
                        //
                    }
                }
            }
            m_HmdInput = ControllerInputManager.GetInput(ControllerType.Hmd);
            // VRContext must have a CenterEyeAnchor at least.
            m_IsRequestVR = (VRContext.GetAnchor(VRNode.CenterEye) != null);
            EnsureAnchor();
            //
            if (XDevicePlugin.GetInt(-1, XDevicePlugin.kField_CtxDeviceVersion, 0) == 0x1010)
            {
                XDevicePlugin.SetInt(m_Handle, XDevicePlugin.kField_ConnectionState, (int)DeviceConnectionState.Connected);
                m_AsDaydreamEmulator = true;
                LoadHandConfigs();
            }
            //
            Log.i("XHawkInput", "Initialize successfully.");
        }