Esempio n. 1
0
    public override RUISCalibrationPhase InitialPhase(float deltaTime)
    {
        timeSinceScriptStart += deltaTime;

        if (timeSinceScriptStart < 3)
        {
            this.guiTextLowerLocal = "Calibration of Kinect 2 floor data\n\n Starting up...";
            return(RUISCalibrationPhase.Initial);
        }

        if (timeSinceScriptStart < 4)
        {
            this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Please wait...";
            return(RUISCalibrationPhase.Initial);
        }

        if (!kinectChecked && timeSinceScriptStart > 4)
        {
            if (!kinect2SourceManager.GetSensor().IsOpen || !kinect2SourceManager.GetSensor().IsAvailable)
            {
                this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Error: Could not connect to Kinect 2.";
                return(RUISCalibrationPhase.Invalid);
            }
            else
            {
                return(RUISCalibrationPhase.Preparation);
            }
        }

        return(RUISCalibrationPhase.Invalid);        // Loop should not get this far
    }
Esempio n. 2
0
    private void updateKinect2FloorData()
    {
        Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;

        bool canAccessKinect2 = false;

        try
        {
            if (coordinateSystem != null && kinect2SourceManager != null &&
                kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen&& kinect2SourceManager.GetSensor().IsAvailable)
            {
                canAccessKinect2 = true;
            }
        }
        catch {}

        if (canAccessKinect2)
        {
            if (coordinateSystem.rootDevice == RUISDevice.Kinect_2)
            {
                coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_2);
                coordinateSystem.ResetDistanceFromFloor(RUISDevice.Kinect_2);
            }


            Windows.Kinect.Vector4 kinect2FloorPlane = kinect2SourceManager.GetFlootClipPlane();

            //print (kinect2FloorPlane.X + " " + kinect2FloorPlane.Y + " " + kinect2FloorPlane.Z  + " " +  kinect2FloorPlane.W);

            Vector3 kinect2FloorNormal = new Vector3(kinect2FloorPlane.X, kinect2FloorPlane.Y, kinect2FloorPlane.Z);
            kinect2FloorNormal.Normalize();

            float kinect2DistanceFromFloor = kinect2FloorPlane.W / Mathf.Sqrt(kinect2FloorNormal.sqrMagnitude);

            if (float.IsNaN(kinect2DistanceFromFloor))
            {
                kinect2DistanceFromFloor = 0;
            }
            if (float.IsNaN(kinect2FloorNormal.x) || kinect2FloorNormal.sqrMagnitude < 0.1f)
            {
                kinect2FloorNormal = Vector3.up;
            }

            if (coordinateSystem.rootDevice == RUISDevice.Kinect_2)
            {
                coordinateSystem.SetFloorNormal(kinect2FloorNormal, RUISDevice.Kinect_2);
                coordinateSystem.SetDistanceFromFloor(kinect2DistanceFromFloor, RUISDevice.Kinect_2);
            }
            Debug.Log("Updated Kinect 2 floor normal " + kinect2FloorNormal + " and floor distance (" + kinect2DistanceFromFloor + ")");
        }
    }
    public override RUISCalibrationPhase InitialPhase(float deltaTime)
    {
        timeSinceScriptStart += deltaTime;

        if (timeSinceScriptStart < 3)
        {
            this.guiTextLowerLocal = "Calibration of Kinect 2 and Oculus DK2\n\n Starting up...";
            return(RUISCalibrationPhase.Initial);
        }

        if (timeSinceScriptStart < 4)
        {
            this.guiTextLowerLocal = "Connecting to Oculus Rift DK2. \n\n Please wait...";
            return(RUISCalibrationPhase.Initial);
        }

        if (!oculusChecked && timeSinceScriptStart > 4)
        {
            oculusChecked = true;

            if ((RUISOVRManager.ovrHmd.GetTrackingState().StatusFlags & (uint)StatusBits.HmdConnected) == 0)               // Code from OVRManager.cs
            {
                this.guiTextLowerLocal = "Connecting to Oculus Rift DK2. \n\n Error: Could not connect to Oculus Rift DK2.";
                return(RUISCalibrationPhase.Invalid);
            }
        }

        if (timeSinceScriptStart < 5)
        {
            this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Please wait...";
            return(RUISCalibrationPhase.Initial);
        }

        if (!kinect2Checked && timeSinceScriptStart > 5)
        {
            kinect2Checked = true;
            if (!kinect2SourceManager.GetSensor().IsOpen || !kinect2SourceManager.GetSensor().IsAvailable)
            {
                this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Error: Could not connect to Kinect 2.";
                return(RUISCalibrationPhase.Invalid);
            }
            else
            {
                return(RUISCalibrationPhase.Preparation);
            }
        }

        return(RUISCalibrationPhase.Invalid);        // Loop should not get this far
    }
Esempio n. 4
0
	public override RUISCalibrationPhase InitialPhase(float deltaTime) {
		
		timeSinceScriptStart += deltaTime;
		
		if(timeSinceScriptStart < 3) {
			this.guiTextLowerLocal = "Calibration of PS Move and Kinect 2\n\n Starting up...";
			return RUISCalibrationPhase.Initial;
		}
		
		if(timeSinceScriptStart < 4) {
			this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Please wait...";
			return RUISCalibrationPhase.Initial;
		}
		
		if(!kinectChecked && timeSinceScriptStart > 4) {
			if (!kinect2SourceManager.GetSensor().IsOpen || !kinect2SourceManager.GetSensor().IsAvailable) {
				this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Error: Could not connect to Kinect 2.";
				return RUISCalibrationPhase.Invalid;
			}
			kinectChecked = true;	
		}	
		
		
		if(timeSinceScriptStart < 5) {
			this.guiTextLowerLocal = "Connecting to PSMove. \n\n Please wait...";
			return RUISCalibrationPhase.Initial;
		}
		
		if(!PSMoveChecked && timeSinceScriptStart > 5) {  
			PSMoveChecked = true;
			if(!psMoveWrapper.isConnected) {
				this.guiTextLowerLocal = "Connecting to PSMove. \n\n Error: Could not start PSMove";
				return RUISCalibrationPhase.Invalid;
			}
			else {
				return RUISCalibrationPhase.Preparation;
			}
		}
		
		return RUISCalibrationPhase.Invalid; // Loop should not get this far
	}
	void Start () 
	{
		trackingIDs = new trackedBody[6]; 
		for(int y = 0; y < trackingIDs.Length; y++) {
			trackingIDs[y] = new trackedBody(-1, false, 1);
		}
		coordinateCalibration = FindObjectOfType(typeof(RUISCoordinateCalibration)) as RUISCoordinateCalibration;
		
		_SourceManager = SourceManager.GetComponent<Kinect2SourceManager>();
		_Sensor = _SourceManager.GetSensor();
		if(_Sensor != null) {
			imageWidth = _Sensor.DepthFrameSource.FrameDescription.Width;
			imageHeight = _Sensor.DepthFrameSource.FrameDescription.Height;
			texture = new Texture2D(imageWidth / _DownsampleSize, imageHeight / _DownsampleSize);
		}
	}
Esempio n. 6
0
    void Start()
    {
        trackingIDs = new trackedBody[6];
        for (int y = 0; y < trackingIDs.Length; y++)
        {
            trackingIDs[y] = new trackedBody(-1, false, 1);
        }
        coordinateCalibration = FindObjectOfType(typeof(RUISCoordinateCalibration)) as RUISCoordinateCalibration;

        _SourceManager = SourceManager.GetComponent <Kinect2SourceManager>();
        _Sensor        = _SourceManager.GetSensor();
        if (_Sensor != null)
        {
            imageWidth  = _Sensor.DepthFrameSource.FrameDescription.Width;
            imageHeight = _Sensor.DepthFrameSource.FrameDescription.Height;
            texture     = new Texture2D(imageWidth / _DownsampleSize, imageHeight / _DownsampleSize);
        }
    }
Esempio n. 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!");
                    }
                }
            }
        }
    }
Esempio n. 8
0
    void Start()
    {
        Quaternion dictionaryFloorNormal       = coordinateSystem.RUISCalibrationResultsFloorPitchRotation[coordinateSystem.rootDevice];
        float      dictionaryDistanceFromFloor = coordinateSystem.RUISCalibrationResultsDistanceFromFloor[coordinateSystem.rootDevice];
        Vector3    normalVector = dictionaryFloorNormal * Vector3.up;

        coordinateSystem.SetFloorNormal(normalVector, coordinateSystem.rootDevice);
        coordinateSystem.SetDistanceFromFloor(dictionaryDistanceFromFloor, coordinateSystem.rootDevice);

        //check whether the kinect camera is actually connected
        if (enableKinect)
        {
            OpenNISettingsManager settingsManager = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;
            if (settingsManager.UserGenrator == null || !settingsManager.UserGenrator.Valid)
            {
                Debug.LogError("Could not start OpenNI! Check your Kinect connection.");
                GetComponentInChildren <RUISKinectDisabler>().KinectNotAvailable();
            }
        }

        if (!enableKinect2)
        {
            Debug.Log("Kinect 2 is disabled from RUISInputManager.");
            BodySourceManager kinect2Manager = GetComponentInChildren <BodySourceManager>();
            if (kinect2Manager)
            {
                kinect2Manager.gameObject.SetActive(false);
            }
        }
        else
        {
            bool kinect2FoundBySystem = false;
            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;
                }
                else
                {
                    Debug.LogError("Kinect 2 was NOT detected by the system. Disabling Kinect 2 in RUISInputManager.");
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError("Kinect 2 was NOT detected by the system. Disabling Kinect 2 in RUISInputManager.\n" + e.Message);
            }

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

        if ((enableKinect && kinectFloorDetection) || (enableKinect2 && kinect2FloorDetection))
        {
            StartFloorDetection();
        }

        //if (enablePSMove)
        //      {
        //          RUISPSMoveWand[] controllers = GetComponentsInChildren<RUISPSMoveWand>();
        //          moveControllers = new RUISPSMoveWand[controllers.Length];
        //          foreach (RUISPSMoveWand controller in controllers)
        //          {
        //              moveControllers[controller.controllerId] = controller;
        //          }
        //      }
    }
 public bool IsReadyToDetectFloor()
 {
     return(coordinateSystem != null && kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null &&
            kinect2SourceManager.GetSensor().IsOpen&& kinect2SourceManager.GetSensor().IsAvailable);
 }
Esempio n. 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;
                    }
                }
            }
        }
    }
    public override RUISCalibrationPhase InitialPhase(float deltaTime)
    {
        timeSinceScriptStart += deltaTime;

        if (timeSinceScriptStart < 3)
        {
            this.guiTextLowerLocal = "Calibration of Kinect 1 and Kinect 2\n\n Starting up...";
            return(RUISCalibrationPhase.Initial);
        }

        if (timeSinceScriptStart < 4)
        {
            this.guiTextLowerLocal = "Connecting to Kinect 1. \n\n Please wait...";
            return(RUISCalibrationPhase.Initial);
        }

        if (!kinectChecked && timeSinceScriptStart > 4)
        {
            if (settingsManager == null)
            {
                this.guiTextLowerLocal = "Connecting to Kinect 1. \n\n Error: Could not start OpenNI";
                return(RUISCalibrationPhase.Invalid);
            }
            else if (settingsManager.UserGenrator == null)
            {
                this.guiTextLowerLocal = "Connecting to Kinect 1. \n\n Error: Could not start OpenNI";
                return(RUISCalibrationPhase.Invalid);
            }
            else if (!settingsManager.UserGenrator.Valid)
            {
                this.guiTextLowerLocal = "Connecting to Kinect 1. \n\n Error: Could not start OpenNI";
                return(RUISCalibrationPhase.Invalid);
            }
            else
            {
                sceneAnalyzer = new OpenNI.SceneAnalyzer((MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager).CurrentContext.BasicContext);
                sceneAnalyzer.StartGenerating();
            }
            kinectChecked = true;
        }

        if (timeSinceScriptStart < 5)
        {
            this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Please wait...";
            return(RUISCalibrationPhase.Initial);
        }

        if (!kinect2Checked && timeSinceScriptStart > 5)
        {
            kinect2Checked = true;
            if (!kinect2SourceManager.GetSensor().IsOpen || !kinect2SourceManager.GetSensor().IsAvailable)
            {
                this.guiTextLowerLocal = "Connecting to Kinect 2. \n\n Error: Could not connect to Kinect 2.";
                return(RUISCalibrationPhase.Invalid);
            }
            else
            {
                return(RUISCalibrationPhase.Preparation);
            }
        }

        return(RUISCalibrationPhase.Invalid);        // Loop should not get this far
    }