Пример #1
0
    private void updateCalibratableDevices()
    {
        List <string> dropDownChoices = new List <string>();

        string currentSelection = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Dropdown - Calibration Devices").GetComponent <UIPopupList>().selection;

        //dropDownChoices.Add ("Select device(s)");
        if (inputManager.enableKinect)
        {
            dropDownChoices.Add("Kinect 1 floor data");
        }
        if (inputManager.enableKinect2)
        {
            dropDownChoices.Add("Kinect 2 floor data");
        }

        // NOTE: The dropDownChoices determine the device pair to be calibrated, and they must follow the format "Device A - Device B".
        //       The string must correspond the options in the Awake() method of RUISCoordinateCalibration script
        if (inputManager.enableKinect && inputManager.enableKinect2)
        {
            dropDownChoices.Add("Kinect 1 - Kinect2");
        }
        if (inputManager.enableKinect && inputManager.enablePSMove)
        {
            dropDownChoices.Add("Kinect 1 - PSMove");
        }
        if (inputManager.enableKinect2 && inputManager.enablePSMove)
        {
            dropDownChoices.Add("Kinect 2 - PSMove");
        }
        if (RUISDisplayManager.IsOpenVrAccessible() && inputManager.enableKinect2)
        {
            dropDownChoices.Add("Kinect 2 - OpenVR (controller)");
        }
        if (RUISDisplayManager.IsHmdPresent() && inputManager.enableKinect2)
        {
            dropDownChoices.Add("Kinect 2 - OpenVR (HMD)");
        }
        if (RUISDisplayManager.IsHmdPresent() && inputManager.enablePSMove)
        {
            dropDownChoices.Add("PSMove - OpenVR (HMD)");
        }
        if (RUISDisplayManager.IsHmdPresent() && inputManager.enableKinect)
        {
            dropDownChoices.Add("Kinect 1 - OpenVR (HMD)");
        }


        if (dropDownChoices.Count == 0)
        {
            dropDownChoices.Add("Select device(s)");
        }

        this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Dropdown - Calibration Devices").GetComponent <UIPopupList>().items = dropDownChoices;
        if (!dropDownChoices.Contains(currentSelection))
        {
            this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Dropdown - Calibration Devices").GetComponent <UIPopupList>().selection = dropDownChoices[0];
        }
    }
Пример #2
0
    public static string GetHmdModel()
    {
        if (!RUISDisplayManager.IsHmdPresent())
        {
            return("no_HMD");
        }

        string hmdModel = UnityEngine.VR.VRDevice.model;

        // Lets ask OpenVR if Unity does not recognice the HMD name
        if (hmdModel == null || hmdModel == "")
        {
            /*
             #if UNITY_EDITOR
             *          //if(SteamVR.instance != null)
             *          //	return SteamVR.instance.hmd_ModelNumber;
             #else
             *          if(isSteamVrAccessible)
             *          {
             *                  if(SteamVR.instance != null)
             *                          return SteamVR.instance.hmd_ModelNumber;
             *          }
             *          else
             *          {
             *                  if(!failedToAccessSteamVr)
             *                  {
             *                          try
             *                          {
             *                                  if(SteamVR.instance != null)
             *                                          hmdModel = SteamVR.instance.hmd_ModelNumber;
             *                                  isSteamVrAccessible = true;
             *                          }
             *                          catch
             *                          {
             *                                  failedToAccessSteamVr = true;
             *                          }
             *                  }
             *          }
             #endif
             */
        }
        else
        {
            return(hmdModel);
        }

        if (hmdModel == null || hmdModel == "")
        {
            return("unknown HMD");
        }

        return(hmdModel);
    }
Пример #3
0
    // *** HACK TODO need to check if the found HMD is really position tracked
    public static bool IsHmdPositionTrackable()
    {
        //		if(OVRManager.capiHmd != null)
        //		{
        //			Ovr.HmdType ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type; //06to08
        //
        //			if(    (OVRManager.capiHmd.GetTrackingState().StatusFlags & (uint)StatusBits.HmdConnected) != 0 // !isplay.isPresent
        //				&& (ovrHmdVersion == HmdType.DK2 || ovrHmdVersion == HmdType.Other)) // Rift is DK2+     //06to08
        //				return true;
        //		}
        //		return false;

        return(RUISDisplayManager.IsHmdPresent());
    }
Пример #4
0
    public void Awake()
    {
        aspectRatio = resolutionX / resolutionY;

        if (linkedCamera)
        {
            LinkToCamera(linkedCamera);
        }

        if (isHmdDisplay && !RUISDisplayManager.IsHmdPresent())
        {
            isHmdDisplay = false;
        }
    }
Пример #5
0
    public bool HasNonHmdDisplay()
    {
        if (!UnityEngine.VR.VRSettings.enabled || !RUISDisplayManager.IsHmdPresent())
        {
            return(true);
        }

        foreach (RUISDisplay display in displays)
        {
            if (display.linkedCamera)
            {
                if (display.linkedCamera.isStereo || (display.linkedCamera.centerCamera && display.linkedCamera.centerCamera.stereoTargetEye == StereoTargetEyeMask.None))
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Пример #6
0
    void Update()
    {
//				if(RUISOVRManager.ovrHmd != null) //06to08

        if (RUISDisplayManager.IsHmdPresent())
        {
            Vector3 tempSample = Vector3.zero;

//			Ovr.Posef headpose = RUISOVRManager.ovrHmd.GetTrackingState().HeadPose.ThePose;
//			float px =  headpose.Position.x;
//			float py =  headpose.Position.y;
//			float pz = -headpose.Position.z; // This needs to be negated TODO: might change with future OVR version
//
//			tempSample = new Vector3(px, py, pz);
//
//			tempSample = coordinateSystem.ConvertRawOculusDK2Location(tempSample);

            // HACK TODO if this doesn't work for major HMDs, add wrapper (also for rotation)
            // HACK TODO tempSample components might need negation or other hackery
            tempSample = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.Head);             //06to08

            Vector3 convertedLocation = coordinateSystem.ConvertLocation(tempSample, RUISDevice.OpenVR);
            this.transform.localPosition = convertedLocation;
            this.transform.localRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.Head);             // HACK TODO check that this works

//			if(OVRManager.capiHmd != null)
//			{
//				try
//				{
//					this.transform.localRotation = OVRManager.capiHmd.GetTrackingState().HeadPose.ThePose.Orientation.ToQuaternion();
//				}
//				catch(System.Exception e)
//				{
//					Debug.LogError(e.Message);
//				}
//			}
        }
    }
Пример #7
0
    void Awake()
    {
        string[] names = System.Enum.GetNames(typeof(RUISDevice));
        foreach (string device in names)
        {
            RUISDevice device1Enum = (RUISDevice)System.Enum.Parse(typeof(RUISDevice), device, true);
            RUISCalibrationResultsFloorPitchRotation[device1Enum] = Quaternion.identity;
            RUISCalibrationResultsDistanceFromFloor[device1Enum]  = 0.0f;
            foreach (string device2 in names)
            {
                if (device != device2)
                {
                    string devicePairString = device + "-" + device2;
                    RUISCalibrationResultsInVector3[devicePairString]    = new Vector3(0, 0, 0);
                    RUISCalibrationResultsInQuaternion[devicePairString] = Quaternion.identity;
                    RUISCalibrationResultsIn4x4Matrix[devicePairString]  = Matrix4x4.identity;
                }
            }
        }

        if (loadFromXML)
        {
            if (!LoadMultiXML(coordinateXmlFile))
            {
                createExampleXML(coordinateXmlFile);
            }
        }

        inputManager = FindObjectOfType <RUISInputManager>();
        if (switchToAvailableDevice && inputManager)
        {
            bool       needToSwitch   = false;
            RUISDevice previousDevice = rootDevice;

            switch (rootDevice)
            {
            case RUISDevice.Kinect_1:
                if (!inputManager.enableKinect)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.Kinect_2:
                if (!inputManager.enableKinect2)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.PS_Move:
                if (!inputManager.enablePSMove)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.OpenVR:             // If OpenVR can't accessed AND a HMD can't be detected
                if (!RUISDisplayManager.IsOpenVrAccessible() && !RUISDisplayManager.IsHmdPresent())
                {
                    needToSwitch = true;
                }
                break;
            }

            if (needToSwitch)
            {
                // Try to determine if Kinect2 can be used (because this method is run before RUISInputManager can disable enableKinect2)
                bool kinect2FoundBySystem = false;
                if (inputManager.enableKinect2)
                {
                    try
                    {
                        Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;
                        if (kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen)
                        {
                            // IsOpen seems to return false mostly if Kinect 2 drivers are not installed?
                            //					Debug.Log("Kinect 2 was detected by the system.");
                            kinect2FoundBySystem = true;
                        }
                    }
                    catch
                    {}
                }

                if (RUISDisplayManager.IsHmdPositionTrackable())
                {
                    rootDevice = RUISDevice.OpenVR;
                }
                else if (inputManager.enableKinect2 && kinect2FoundBySystem)
                {
                    rootDevice = RUISDevice.Kinect_2;
                }
                else if (inputManager.enableKinect)
                {
                    rootDevice = RUISDevice.Kinect_1;
                }
                else if (inputManager.enablePSMove)
                {
                    rootDevice = RUISDevice.PS_Move;
                }

                if (rootDevice != previousDevice)
                {
                    if (previousDevice == RUISDevice.OpenVR)
                    {
                        Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
                                         + "because OpenVR could not be accessed! Is SteamVR installed?");
                    }
                    else
                    {
                        Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
                                         + "because the former was not enabled in " + typeof(RUISInputManager) + " while the latter was!");
                    }
                }
            }
        }
    }
Пример #8
0
//	public RUISDisplay GetHmdDisplay()
//	{
//		foreach(RUISDisplay display in displays)
//		{
//			if(display.linkedCamera && display.isHmdDisplay)
//			{
//				return display;
//			}
//		}
//
//		return null;
//	}

    private void InitRUISMenu(GameObject ruisMenuPrefab, int guiDisplayChoice)
    {
        if (ruisMenuPrefab == null)
        {
            return;
        }

        // HACK: displays is a list and accessing components by index might break if we modify the list in run-time
        if (displays.Count <= guiDisplayChoice)
        {
            Debug.LogError("displays.Count is too small: " + displays.Count + ", because guiDisplayChoice == " + guiDisplayChoice
                           + ". Add more RUISDisplays or change the 'Display With RUIS Menu' field in " + typeof(RUISDisplayManager), this);
            return;
        }

        if (displays[guiDisplayChoice] == null ||
            displays[guiDisplayChoice].GetComponent <RUISDisplay>() == null ||
            displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera == null)
        {
            return;
        }

        GameObject ruisMenu = Instantiate(ruisMenuPrefab) as GameObject;

        if (ruisMenu == null)
        {
            return;
        }

        if (menuLayer == -1)
        {
            Debug.LogError("Could not find layer '" + LayerMask.LayerToName(menuLayer) + "', the RUIS menu cursor will not work without this layer! "
                           + "The prefab '" + ruisMenuPrefab.name + "' and its children should be on this layer.");
        }

        if (!displays[guiDisplayChoice].GetComponent <RUISDisplay>().isStereo /* && !displays[guiDisplayChoice].GetComponent<RUISDisplay>().enableOculusRift */)
        {
            if (displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.centerCamera)
            {
                displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.centerCamera.gameObject.AddComponent <UICamera>();
            }
            else
            {
                Debug.LogError("The " + typeof(RUISDisplay) + " that was assigned with 'RUIS Menu Prefab' in " + typeof(RUISDisplayManager) + " has an 'Attached Camera' "
                               + " whose centerCamera is null for some reason! Can't create UICamera.");
            }
        }
        else
        {
            if (displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.rightCamera)
            {
                displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.rightCamera.gameObject.AddComponent <UICamera>();
            }
            else
            {
                Debug.LogError("The " + typeof(RUISDisplay) + " that was assigned with 'RUIS Menu Prefab' in " + typeof(RUISDisplayManager) + " has an 'Attached Camera' "
                               + " whose rightCamera is null for some reason! Can't create UICamera.");
            }
            if (displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.leftCamera)
            {
                displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.leftCamera.gameObject.AddComponent <UICamera>();
            }
            else
            {
                Debug.LogError("The " + typeof(RUISDisplay) + " that was assigned with 'RUIS Menu Prefab' in " + typeof(RUISDisplayManager) + " has an 'Attached Camera' "
                               + " whose leftCamera is null for some reason! Can't create UICamera.");
            }
        }

        UICamera[] NGUIcameras = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.GetComponentsInChildren <UICamera>();

        foreach (UICamera camera in NGUIcameras)
        {
            camera.eventReceiverMask = LayerMask.GetMask(LayerMask.LayerToName(menuLayer));
        }

        string primaryMenuParent   = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.centerCameraName;
        string secondaryMenuParent = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.rightCameraName;
        string tertiaryMenuParent  = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.leftCameraName;

        if (displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.centerCamera &&
            !(displays[guiDisplayChoice].GetComponent <RUISDisplay>().isStereo&& RUISDisplayManager.IsHmdPresent() &&
              displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.centerCamera.stereoTargetEye != StereoTargetEyeMask.None))
        {
            ruisMenu.transform.parent = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.centerCamera.transform;
        }
        else
        {
            if (displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.rightCamera)
            {
                ruisMenu.transform.parent = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.rightCamera.transform;
            }
            else
            {
                if (displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.leftCamera)
                {
                    ruisMenu.transform.parent = displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.leftCamera.transform;
                }
                else
                {
//					Debug.LogError(  "Could not find any of the following gameObjects under "
//					               + displays[guiDisplayChoice].GetComponent<RUISDisplay>().linkedCamera.gameObject.name
//					               + ": " + primaryMenuParent + ", " + secondaryMenuParent + ", " + tertiaryMenuParent + ". RUIS Menu will be parented "
//						+ "directly under " + displays[guiDisplayChoice].GetComponent<RUISDisplay>().linkedCamera.gameObject.name + ".");
//					ruisMenu.transform.parent = displays[guiDisplayChoice].GetComponent<RUISDisplay>().linkedCamera.transform;
                    Debug.LogError("Can't parent RUIS Menu Prefab under the correct Transform because the " + typeof(RUISCamera) + " in gameObject "
                                   + displays[guiDisplayChoice].GetComponent <RUISDisplay>().linkedCamera.gameObject + " has null value for centerCamera, "
                                   + "leftCamera, and rightCamera.");
                }
            }
        }

        ruisMenu.transform.localRotation = Quaternion.identity;
        ruisMenu.transform.localPosition = new Vector3(guiX, guiY, guiZ);

        if (ruisMenu.GetComponent <RUISMenuNGUI>())
        {
            ruisMenu.GetComponent <RUISMenuNGUI>().Hide3DGUI();
        }
    }
Пример #9
0
    private void handleInfotexts()
    {
        GameObject infotext_Changes_saved = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Infotexts/Saving/Label - Changes saved").gameObject;
        GameObject infotext_Changes_are_not_saved_in_free_version = this.transform.Find(
            "NGUIControls/Panel/selectAndConfigureDevices/Infotexts/Saving/Label - Changes are not saved in free version").gameObject;
        GameObject infotext_Changes_not_saved_yet = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Infotexts/Saving/Label - Changes not saved yet").gameObject;
        GameObject infotext_Hmd_Not_Detected      = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Infotexts/HMD/Label - HMD not detected").gameObject;   // Was "Rift not detected"
        GameObject infotext_Hmd_Detected          = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Infotexts/HMD/Label - HMD detected").gameObject;       // Was "Oculus DK1 detected"

        if (RUISDisplayManager.IsHmdPresent())
        {
            if (infotext_Hmd_Detected)
            {
                UILabel hmdDetectedLabel = infotext_Hmd_Detected.GetComponent <UILabel>();
                if (hmdDetectedLabel)
                {
                    hmdDetectedLabel.text = RUISDisplayManager.GetHmdModel() + " detected";
                }
            }
            infotext_Hmd_Not_Detected.SetActive(false);
            infotext_Hmd_Detected.SetActive(true);
        }
        else
        if (infotext_Hmd_Not_Detected)
        {
            infotext_Hmd_Not_Detected.SetActive(true);
            infotext_Hmd_Detected.SetActive(false);
        }

//		bool isRiftConnected = false;
//		{
//			try
//			{
//				if(OVRManager.display != null) //06to08
//					isRiftConnected = OVRManager.display.isPresent; //06to08
//				if(OVRManager.capiHmd != null)
//					ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type; //06to08
//
//
//			}
//			catch(UnityException e)
//			{
//				Debug.LogError(e);
//			}
//		}
//		if(isRiftConnected && ovrHmdVersion == Ovr.HmdType.DK1) //06to08
//		{
//			infotext_Rift_not_Detected.SetActive(false);
//			infotext_Oculus_DK1_detected.SetActive(true);
//			infotext_Oculus_DK2_detected.SetActive(false);
//		}
//		else if(isRiftConnected && (ovrHmdVersion == Ovr.HmdType.DK2 || ovrHmdVersion == Ovr.HmdType.Other)) //06to08
//		{
//			infotext_Rift_not_Detected.SetActive(false);
//			infotext_Oculus_DK2_detected.SetActive(true);
//			infotext_Oculus_DK1_detected.SetActive(false);
//		}
//		else {
//			infotext_Rift_not_Detected.SetActive(true);
//			infotext_Oculus_DK1_detected.SetActive(false);
//			infotext_Oculus_DK2_detected.SetActive(false);
//		}

        if (!XmlImportExport.XmlHandlingFunctionalityAvailable())
        {
            infotext_Changes_are_not_saved_in_free_version.SetActive(true);
            infotext_Changes_saved.SetActive(false);
            infotext_Changes_not_saved_yet.SetActive(false);
        }
        else
        {
            infotext_Changes_are_not_saved_in_free_version.SetActive(false);
            if (originalPSMoveIP == inputManager.PSMoveIP &&
                originalPSMovePort == inputManager.PSMovePort &&
                originalEnablePSMove == inputManager.enablePSMove &&
                originalEnableKinect == inputManager.enableKinect &&
                originalEnableKinect2 == inputManager.enableKinect2 &&
                originalEnableJumpGesture == inputManager.jumpGestureEnabled &&
                originalEnableHydra == inputManager.enableRazerHydra)
//			   && originalKinectDriftCorrection == inputManager.kinectDriftCorrectionPreferred)
            {
                infotext_Changes_saved.SetActive(true);
                infotext_Changes_not_saved_yet.SetActive(false);
            }
            else
            {
                infotext_Changes_not_saved_yet.SetActive(true);
                infotext_Changes_saved.SetActive(false);
            }
        }
    }
Пример #10
0
//	Ovr.HmdType ovrHmdVersion; //06to08

    void Awake()
    {
        if (!scriptEnabled)
        {
            return;
        }

        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        bool kinect2 = false;
        bool kinect  = false;
        bool psmove  = false;
        bool razer   = false;

//		bool isRiftConnected = false;
//		{
//			try
//			{
//				// Find out if an Oculus HMD is connected
//				if(OVRManager.display != null)
//					isRiftConnected = OVRManager.display.isPresent; //06to08
//
//				// Find out the Oculus HMD version
//				if(OVRManager.capiHmd != null)
//					ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type; //06to08
//			}
//			catch(UnityException e)
//			{
//				Debug.LogError(e);
//			}
//		}
//
        if (inputManager)
        {
            kinect2 = inputManager.enableKinect2;
            kinect  = inputManager.enableKinect;
            psmove  = inputManager.enablePSMove;
            razer   = inputManager.enableRazerHydra;

            int         trackerCount      = 0;
            RUISTracker closestMatch      = null;
            int         currentMatchScore = 0;

            bool kinect2FoundBySystem = false;
            if (kinect2)
            {
                try
                {
                    Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;

                    if (kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen)
                    {
                        // IsOpen seems to return false mostly if Kinect 2 drivers are not installed?
                        kinect2FoundBySystem = true;
                    }
                }
                catch
                {
                }

                if (!kinect2FoundBySystem)
                {
                    kinect2 = false;
                }
            }

            RUISHeadTrackerAssigner[] assigners = FindObjectsOfType(typeof(RUISHeadTrackerAssigner)) as RUISHeadTrackerAssigner[];
            if (!allowMultipleAssigners && assigners.Length > 1)
            {
                Debug.LogError("Multiple active RUISHeadTrackerAssigner scripts found while 'Allow Multiple Assigners' is false: "
                               + "Disabling all headtrackers and their child objects that are listed in the RUISHeadTrackerAssigner "
                               + "component of '" + gameObject.name + "' object.");

                for (int i = 0; i < headTrackers.Capacity; ++i)
                {
                    if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy)
                    {
                        headTrackers[i].gameObject.SetActive(false);
                    }
                }
                return;
            }

            foreach (RUISTracker trackerScript in headTrackers)
            {
                if (trackerScript && trackerScript.gameObject.activeInHierarchy)
                {
                    ++trackerCount;
                    int foundTrackerScore = 0;

//					bool openVRHmdFound = false;
//					try
//					{
//						if(RUISDisplayManager.IsOpenVrAccessible() && Valve.VR.OpenVR.IsHmdPresent()) // *** TODO HACK Valve API
//							openVRHmdFound = true;
//					} catch{}

                    // Give score to found head trackers
                    if (RUISDisplayManager.IsHmdPresent() && UnityEngine.XR.XRSettings.enabled && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.OpenVR)
                    {
                        foundTrackerScore = 7;
                    }
                    else if (psmove && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.PSMove)
                    {
                        foundTrackerScore = 6;
                    }
                    else if (razer && trackerScript.isRazerBaseMobile &&                         // Legacy: Mobile Hydra Base (custom tracker)
                             trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&
                             trackerScript.mobileRazerBase == RUISTracker.RazerHydraBase.InputTransform)
                    {
                        foundTrackerScore = 5;
                    }
                    else if (kinect2 && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.Kinect2)
                    {
                        foundTrackerScore = 4;
                    }
                    else if (kinect && razer && trackerScript.isRazerBaseMobile &&                         // Legacy: Mobile Hydra Base (Kinect)
                             trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&
                             trackerScript.mobileRazerBase == RUISTracker.RazerHydraBase.Kinect1)
                    {
                        foundTrackerScore = 3;
                    }
                    else if (kinect && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.Kinect1)
                    {
                        foundTrackerScore = 2;
                    }
                    else if (razer && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&                         // Plain ol' Razer Hydra
                             !trackerScript.isRazerBaseMobile)
                    {
                        foundTrackerScore = 1;
                    }

                    // Assign new best head tracker candidate if it is better than the previously found
                    if (currentMatchScore < foundTrackerScore)
                    {
                        closestMatch      = trackerScript;
                        currentMatchScore = foundTrackerScore;
                    }
                }
            }

            if (trackerCount == 0 && Application.isEditor)
            {
                Debug.LogError("No active GameObjects with RUISTracker script found from headTrackers list!");
            }

            string     positionTracker = "<None>";
            string     logString       = "";
            string     names           = "";
            RUISCamera ruisCamera      = null;

            if (closestMatch == null)
            {
                // Disable all but the first active head tracker from the headTrackers list
                logString = "Could not find a suitable head tracker with regard to "
                            + "enabled devices in RUISInputManager!";

                bool disabling        = false;
                int  leftEnabledIndex = -1;
                for (int i = 0; i < headTrackers.Capacity; ++i)
                {
                    if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy)
                    {
                        if (disabling)
                        {
                            if (names.Length > 0)
                            {
                                names = names + ", ";
                            }
                            names = names + headTrackers[i].gameObject.name;
                            headTrackers[i].gameObject.SetActive(false);
                        }
                        else
                        {
                            leftEnabledIndex = i;
                            closestMatch     = headTrackers[leftEnabledIndex];
                            positionTracker  = headTrackers[leftEnabledIndex].gameObject.name;
                            disabling        = true;
                        }
                    }
                }
                if (leftEnabledIndex >= 0)
                {
                    logString = logString + " Choosing the first head tracker in the list. Using "
                                + positionTracker + " for tracking head position";
                    if (names.Length > 0)
                    {
                        logString = logString + ", and disabling the following: " + names;
                    }
                    logString = logString + ". This choice was made using a pre-selected list of "
                                + "head trackers.";

                    ruisCamera = headTrackers[leftEnabledIndex].gameObject.GetComponentInChildren <RUISCamera>();
                }
                Debug.LogError(logString);
            }
            else
            {
                // Disable all but the closest match head tracker from the headTrackers list
                for (int i = 0; i < headTrackers.Capacity; ++i)
                {
                    if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy)
                    {
                        if (headTrackers[i] != closestMatch)
                        {
                            if (names.Length > 0)
                            {
                                names = names + ", ";
                            }
                            names = names + headTrackers[i].gameObject.name;
                            headTrackers[i].gameObject.SetActive(false);
                        }
                        else
                        {
                            positionTracker = headTrackers[i].gameObject.name;
                        }
                    }
                }
                logString = "Found the best head tracker with regard to enabled devices in "
                            + "RUISInputManager! Using " + positionTracker + " for tracking head position";
                if (names.Length > 0)
                {
                    logString = logString + ", and disabling the following: " + names;
                }
                Debug.Log(logString + ". This choice was made using a pre-selected list of head trackers.");

                ruisCamera = closestMatch.gameObject.GetComponentInChildren <RUISCamera>();

                if (changePivotIfNoKinect && psmove && !kinect && !kinect2 &&
                    closestMatch.headPositionInput == RUISTracker.HeadPositionSource.PSMove)
                {
                    RUISCharacterController characterController = gameObject.GetComponentInChildren <RUISCharacterController>();
                    if (characterController != null &&
                        characterController.characterPivotType != RUISCharacterController.CharacterPivotType.MoveController)
                    {
                        characterController.characterPivotType = RUISCharacterController.CharacterPivotType.MoveController;
                        characterController.moveControllerId   = closestMatch.positionPSMoveID;
                        Debug.Log("PS Move enabled and Kinect disabled. Setting " + characterController.name
                                  + "'s Character Pivot as PS Move controller #" + closestMatch.positionPSMoveID
                                  + ". PS Move position offset for this pivot is " + characterController.psmoveOffset);
                    }
                }
            }


            if (ruisCamera)
            {
                if (display == null)
                {
                    Debug.LogWarning("No RUISDisplay attached to the RUISHeadTrackerAssigner script!");
                    RUISDisplay[] displays = FindObjectsOfType(typeof(RUISDisplay)) as RUISDisplay[];
                    for (int i = 0; i < displays.Length; ++i)
                    {
                        if (displays[i].linkedCamera == null)
                        {
                            Debug.LogWarning("Assigned RUISCamera component from the child of " + positionTracker
                                             + " to render on " + displays[i].gameObject.name + " because that "
                                             + "RUISDisplay component's RUISCamera field was empty.");
                            displays[i].linkedCamera = ruisCamera;
                            break;
                        }
                    }
                }
                else
                {
                    if (display.linkedCamera == null)
                    {
                        Debug.Log("Assigned RUISCamera component from the child of " + positionTracker
                                  + " to render on " + display.gameObject.name);
                        display.linkedCamera = ruisCamera;
                    }
                    else
                    {
                        Debug.LogWarning("RUISDisplay " + display.gameObject.name + " is already connected with a "
                                         + "RUISCamera object! Leave the RUISCamera field empty in your RUISDisplay "
                                         + "component if you want RUISHeadTrackerAssigner script to automatically "
                                         + "assign a RUISCamera to your RUISDisplay.");
                    }
                }
            }
            else
            {
                if (closestMatch)
                {
                    Debug.LogError(positionTracker + " did not have a child with RUISCamera component, "
                                   + "and therefore it is not used to draw on any of the displays in "
                                   + "DisplayManager.");
                }
            }

            // If we are using Razer with a static base for head tracking, then apply onlyRazerOffset
            // on the parent objects of the Razer head tracker and the hand-held Razer
            if (closestMatch != null && razer &&
                closestMatch.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&
                !closestMatch.isRazerBaseMobile)
            {
                // The parent object of the Razer head tracker must not have RUISCharacterConroller,
                // because that script will modify the object's position
                if (closestMatch.transform.parent != null &&
                    closestMatch.transform.parent.GetComponent <RUISCharacterController>() == null &&
                    (onlyRazerOffset.x != 0 || onlyRazerOffset.y != 0 || onlyRazerOffset.z != 0))
                {
                    string razerWandOffsetInfo = "";
                    closestMatch.transform.parent.localPosition += onlyRazerOffset;
                    if (razerWandParent != null)
                    {
                        razerWandParent.localPosition += onlyRazerOffset;
                        razerWandOffsetInfo            = " and " + razerWandParent.gameObject.name + " (parent of hand-held Razer "
                                                         + "Hydra)";
                    }
                    Debug.Log("Applying offset of " + onlyRazerOffset + " to "
                              + closestMatch.transform.parent.gameObject.name + " (parent of Razer Hydra head tracker)"
                              + razerWandOffsetInfo + ".");
                }
            }

            // If no Razer, Kinect, or PS Move is available, then apply onlyMouseOffset
            // on the parent object of the head tracker that is left enabled
//			if(		closestMatch != null && !razer && !kinect && !psmove)
//			{
//				// The parent object of the Razer head tracker must not have RUISCharacterConroller,
//				// because that script will modify the object's position
//				if(		closestMatch.transform.parent != null
//					&&	closestMatch.transform.parent.GetComponent<RUISCharacterController>() == null
//					&& (onlyMouseOffset.x != 0 || onlyMouseOffset.y != 0 || onlyMouseOffset.z != 0)  )
//				{
//					closestMatch.transform.parent.localPosition += onlyMouseOffset;
//					Debug.Log(  "Applying offset of " + onlyMouseOffset + " to "
//							   + closestMatch.transform.parent.gameObject.name + " (parent of assigned head tracker).");
//				}
//			}

            // *** HACK TODO: Below is slightly hacky and only for HMDs with drift (i.e. Rift DK1)
            // Read inputConfig.xml to see if Kinect yaw drift correction for Oculus Rift should be enabled
            if (closestMatch != null &&
                closestMatch.useHmdRotation && applyKinectDriftCorrectionPreference)
            {
                if (inputManager.kinectDriftCorrectionPreferred)
                {
                    // Preference is to use Kinect for drift correction (if PS Move is not used for head tracking)
                    switch (closestMatch.headPositionInput)
                    {
                    case RUISTracker.HeadPositionSource.Kinect1:
                        if (!psmove && kinect)
                        {
                            closestMatch.externalDriftCorrection = true;
                            closestMatch.compass = RUISTracker.CompassSource.Kinect1;
                        }
                        break;

                    case RUISTracker.HeadPositionSource.RazerHydra:
                        if (!psmove && kinect && razer)
                        {
                            if (closestMatch.isRazerBaseMobile)
                            {
                                closestMatch.externalDriftCorrection = true;
                                closestMatch.compass = RUISTracker.CompassSource.Kinect1;
                            }
                        }
                        break;
                    }
                }
                else
                {
                    // Preference is NOT to use Kinect for drift correction
                    if (closestMatch.headPositionInput == RUISTracker.HeadPositionSource.Kinect1 &&
                        !psmove && kinect)
                    {
                        closestMatch.externalDriftCorrection = false;
                    }
                }
            }
        }
    }