Exemplo n.º 1
0
 // CORE HACK by [email protected]
 void Start()
 {
     if (this.transform.parent)
     {
         ruisCamera = this.transform.parent.GetComponent <RUISCamera>();
         if (!ruisCamera)
         {
             ruisCamera = this.transform.GetComponent <RUISCamera>();                        // Non stereo camera
         }
     }
 }
	void Awake () {
        ruisCamera = GetComponent<RUISCamera>();

        centerCameraCorners = new RUISKeystoning.KeystoningCorners();
        leftCameraCorners = new RUISKeystoning.KeystoningCorners();
        rightCameraCorners = new RUISKeystoning.KeystoningCorners();

        centerSpec = new RUISKeystoning.KeystoningSpecification();
        leftSpec = new RUISKeystoning.KeystoningSpecification();
        rightSpec = new RUISKeystoning.KeystoningSpecification();
	}
    void OnEnable()
    {
        near = serializedObject.FindProperty("near");
        far = serializedObject.FindProperty("far");

        horizontalFOV = serializedObject.FindProperty("horizontalFOV");
        verticalFOV = serializedObject.FindProperty("verticalFOV");

        cullingMask = serializedObject.FindProperty("cullingMask");

        camera = target as RUISCamera;
    }
    void Awake()
    {
        ruisCamera = GetComponent <RUISCamera>();

        centerCameraCorners = new RUISKeystoning.KeystoningCorners();
        leftCameraCorners   = new RUISKeystoning.KeystoningCorners();
        rightCameraCorners  = new RUISKeystoning.KeystoningCorners();

        centerSpec = new RUISKeystoning.KeystoningSpecification();
        leftSpec   = new RUISKeystoning.KeystoningSpecification();
        rightSpec  = new RUISKeystoning.KeystoningSpecification();
    }
Exemplo n.º 5
0
    void OnEnable()
    {
        near = serializedObject.FindProperty("near");
        far  = serializedObject.FindProperty("far");

        horizontalFOV = serializedObject.FindProperty("horizontalFOV");
        verticalFOV   = serializedObject.FindProperty("verticalFOV");

        cullingMask = serializedObject.FindProperty("cullingMask");

        camera = target as RUISCamera;
    }
Exemplo n.º 6
0
    // RUIS CORE HACK
    void Start()
    {
        if (this.transform.parent)
        {
            ruisCamera = this.transform.parent.GetComponent <RUISCamera>();
            if (!ruisCamera)
            {
                ruisCamera = this.transform.GetComponent <RUISCamera>();                // Non stereo camera
            }
        }

        displayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;
    }
Exemplo n.º 7
0
    void Start()
    {
        menuScript = this.GetComponent <RUISMenuNGUI>();
        if (menuScript == null)
        {
            Debug.LogError("Did not find " + typeof(RUISMenuNGUI) + " script!");
        }

        this.guiPlane = this.transform.Find("NGUIControls/planeCollider").GetComponent <Collider>();
        if (this.guiPlane == null)
        {
            Debug.LogError("Did not find RUIS Menu collider object, onto which mouse selection ray is projected!");
        }

        if (menuScript.transform.parent == null)
        {
            Debug.LogError("The parent of GameObject '" + menuScript.name
                           + " is null and RUIS Menu will not function. Something is wrong with 'RUIS NGUI Menu' prefab or you "
                           + "are misusing the " + typeof(RUIS3dGuiCursor) + " script.");
        }
        else if (menuScript.transform.parent.parent == null)
        {
            Debug.LogError("The grand-parent of GameObject '" + menuScript.name
                           + " is null and RUIS Menu will not function. Something is wrong with 'RUIS NGUI Menu' prefab or you "
                           + "are misusing the " + typeof(RUIS3dGuiCursor) + " script.");
        }
        else
        {
            ruisCamera = menuScript.transform.parent.parent.GetComponent <RUISCamera>();
        }

        if (ruisCamera == null)
        {
            Debug.LogError(typeof(RUIS3dGuiCursor) + " script did not find " + typeof(RUISCamera) + " from the parent of "
                           + menuScript.transform.name + "gameobject! RUIS Menu is unavailable.");
        }

        ruisDisplayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;

        if (ruisDisplayManager == null)
        {
            this.enabled = false;
            Debug.LogError("Could not find " + typeof(RUISDisplayManager) + " script, RUIS menu will not work!");
            return;
        }
        if (ruisDisplayManager.hideMouseOnPlay && menuScript.currentMenuState != RUISMenuNGUI.RUISMenuStates.calibration)
        {
            Screen.showCursor = false;
        }
        markerObject = ruisDisplayManager.menuCursorPrefab;
    }
Exemplo n.º 8
0
    void Awake()
    {
        ruisCamera = GetComponent <RUISCamera>();
        if (!ruisCamera)
        {
            Debug.LogWarning("GameObject " + name + " has " + typeof(RUISKeystoningConfiguration) + " script, but it is missing "
                             + typeof(RUISCamera) + "script. These two should always be together in the same gameObject.");
        }

        centerCameraCorners = new RUISKeystoning.KeystoningCorners();
        leftCameraCorners   = new RUISKeystoning.KeystoningCorners();
        rightCameraCorners  = new RUISKeystoning.KeystoningCorners();

        centerSpec = new RUISKeystoning.KeystoningSpecification();
        leftSpec   = new RUISKeystoning.KeystoningSpecification();
        rightSpec  = new RUISKeystoning.KeystoningSpecification();
    }
Exemplo n.º 9
0
	void Start() 
	{
		menuScript = this.GetComponent<RUISMenuNGUI>();
		if(menuScript == null)
			Debug.LogError( "Did not find " + typeof(RUISMenuNGUI) + " script!");

		this.guiPlane = this.transform.Find ("NGUIControls/planeCollider").GetComponent<Collider>();
		if(this.guiPlane == null)
			Debug.LogError( "Did not find RUIS Menu collider object, onto which mouse selection ray is projected!" );

		if(menuScript.transform.parent == null)
			Debug.LogError(  "The parent of GameObject '" + menuScript.name 
			               + " is null and RUIS Menu will not function. Something is wrong with 'RUIS NGUI Menu' prefab or you "
			               + "are misusing the " + typeof(RUIS3dGuiCursor) + " script.");
		else if(menuScript.transform.parent.parent == null)
			Debug.LogError(  "The grand-parent of GameObject '" + menuScript.name 
			               + " is null and RUIS Menu will not function. Something is wrong with 'RUIS NGUI Menu' prefab or you "
			               + "are misusing the " + typeof(RUIS3dGuiCursor) + " script.");
		else
			ruisCamera = menuScript.transform.parent.parent.GetComponent<RUISCamera>();

		if(ruisCamera == null)
			Debug.LogError(  typeof(RUIS3dGuiCursor) + " script did not find "  + typeof(RUISCamera) + " from the parent of "
			               + menuScript.transform.name + "gameobject! RUIS Menu is unavailable.");
			               
		ruisDisplayManager =  FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;

		if(ruisDisplayManager == null) 
		{ 
			this.enabled = false;
			Debug.LogError("Could not find " + typeof(RUISDisplayManager) + " script, RUIS menu will not work!");
			return;
		}
		if(ruisDisplayManager.hideMouseOnPlay && menuScript.currentMenuState != RUISMenuNGUI.RUISMenuStates.calibration) 
			Cursor.visible = false;
		markerObject = ruisDisplayManager.menuCursorPrefab;

		if(markerObject)
			originalLocalScale = this.markerObject.transform.localScale;
	}
Exemplo n.º 10
0
    void Awake()
    {
        if (!scriptEnabled)
        {
            return;
        }

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

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

        bool isRiftConnected = false;

        //#if UNITY_EDITOR
        //if(UnityEditorInternal.InternalEditorUtility.HasPro())
        //#endif
        {
            try
            {
                // Find out if an Oculus HMD is connected
                if (OVRManager.display != null)
                {
                    isRiftConnected = OVRManager.display.isPresent;
                }

                // Find out the Oculus HMD version
                if (OVRManager.capiHmd != null)
                {
                    ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type;
                }
            }
            catch (UnityException e)
            {
                Debug.LogError(e);
            }
        }

        if (inputManager)
        {
            if (isRiftConnected && (ovrHmdVersion == Ovr.HmdType.DK2 || ovrHmdVersion == Ovr.HmdType.Other))
            {
                oculusDK2 = true;
            }

            kinect2 = inputManager.enableKinect2;
            kinect  = inputManager.enableKinect;
            psmove  = inputManager.enablePSMove;
            razer   = inputManager.enableRazerHydra;

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

            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;

                    // Give score to found head trackers
                    if (oculusDK2 && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.OculusDK2)
                    {
                        foundTrackerScore = 7;
                        print(trackerScript);
                    }
                    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 CharacterCamera 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).");
//				}
//			}

            // *** TODO: Below is slightly hacky
            // Read inputConfig.xml to see if Kinect yaw drift correction for Oculus Rift should be enabled
            if (closestMatch != null &&
                closestMatch.useOculusRiftRotation && 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;
                    }
                }
            }
        }
    }
Exemplo n.º 11
0
	// CORE HACK by [email protected]
	void Start() 
	{
		if(this.transform.parent) {
			ruisCamera = this.transform.parent.GetComponent<RUISCamera>();
			if(!ruisCamera) ruisCamera = this.transform.GetComponent<RUISCamera>(); // Non stereo camera
		}
	}
Exemplo n.º 12
0
//	public void Start()
//	{
//		if(!linkedCamera)
//		{
//			Debug.LogError(   "Please set up a RUISCamera for display: " + name + ". Each RUISDisplay defined in "
//					+ "RUISDisplayManager should link to a RUISCamera at field 'Attached Camera'.");
//		}
//	}

    public void LinkToCamera(RUISCamera ruisCamera)
    {
        ruisCamera.isKeystoneCorrected = isKeystoneCorrected;
        ruisCamera.associatedDisplay   = this;
        this.linkedCamera = ruisCamera;
    }