Beispiel #1
0
 /// <summary>
 /// Awake is used to initialize any variables or game state before the game starts.
 /// </summary>
 void Awake()
 {
     _canSpawnBunny = false;
     trackedObj     = GetComponent <ZEDControllerTracker>();
     zedPlane       = FindObjectOfType <ZEDPlaneDetectionManager>();
     bunnySpawner   = GetComponent <BunnySpawner>();
     if (!leftCamera)
     {
         leftCamera = ZEDManager.Instance.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
     }
 }
Beispiel #2
0
    /// <summary>
    /// Searched for a ZEDControllerTracker component in this object, its parents, and its children.
    /// Sets the controllerTracker value to the first one it finds.
    /// </summary>
    private void LoadTrackerComponent()
    {
        ZEDControllerTracker zct = GetComponent <ZEDControllerTracker>();

        if (zct == null)
        {
            zct = GetComponentInParent <ZEDControllerTracker>();
        }
        if (zct == null)
        {
            zct = GetComponentInChildren <ZEDControllerTracker>();
        }
        if (zct != null)
        {
            controllerTracker = zct;
        }
    }
Beispiel #3
0
    private void LoadComponentPad()
    {
        ZEDControllerTracker pad = GetComponent <ZEDControllerTracker>();

        if (pad == null)
        {
            pad = GetComponentInParent <ZEDControllerTracker>();
        }
        if (pad == null)
        {
            pad = GetComponentInChildren <ZEDControllerTracker>();
        }
        if (pad != null)
        {
            padManager = pad;
        }
    }
Beispiel #4
0
    /// <summary>
    /// Get necessary references and handle startup events.
    /// </summary>
    void Start()
    {
        if (!controllerTracker)
        {
            controllerTracker = GetComponent <ZEDControllerTracker>();
        }
        if (!zedManager)
        {
            zedManager = controllerTracker.zedManager;
        }

        zedManager.OnZEDReady += LoadCalibFile;

        //Dispatch event that this anchor is ready.
        if (OnCameraAnchorCreated != null)
        {
            OnCameraAnchorCreated.Invoke(this);
        }
    }
Beispiel #5
0
    IEnumerator Start()
    {
        //Find the left camera object if we didn't assign it at start.
        if (!LeftCamera)
        {
            LeftCamera = ZEDManager.Instance.GetLeftCameraTransform().gameObject.GetComponent <Camera>();
        }

        _audioSource = GetComponent <AudioSource>();

        if (LaserPointerBeadHolder != null)
        {
            //Get the laser bead from the parent/achor object.
            PointerBead = LaserPointerBeadHolder.transform.GetChild(0).gameObject;
            //Disable the laser bead to wait for the ZED to initialize.
            PointerBead.SetActive(false);
        }

        //Wait for VR Controllers to initilize
        yield return(new WaitForSeconds(1f));

        objectTracker = GetComponent <ZEDControllerTracker>();

        if (objectTracker != null)
        {
#if ZED_STEAM_VR
            if (objectTracker.index >= 0)
            {
                yield break;
            }
#endif
#if ZED_OCULUS
            if (OVRInput.GetConnectedControllers().ToString() == "Touch")
            {
                yield break;
            }
#endif
            // If it got here then there's no VR Controller connected
            int children = transform.childCount;
            for (int i = 0; i < children; ++i)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }
            this.enabled = false;
        }
        else
        {
            //If its not attached to an object tracker
            var otherObjectTracker = FindObjectsOfType <ZEDControllerTracker>();

            if (otherObjectTracker != null)
            {
                int children = transform.childCount;
#if ZED_STEAM_VR
                foreach (ZEDControllerTracker trackers in otherObjectTracker)
                {
                    if (trackers.index >= 0)
                    {
                        for (int i = 0; i < children; ++i)
                        {
                            transform.GetChild(i).gameObject.SetActive(false);
                        }

                        this.enabled = false;
                        yield break;
                    }
                }
#endif
#if ZED_OCULUS
                if (OVRManager.isHmdPresent)
                {
                    if (OVRInput.GetConnectedControllers().ToString() == "Touch")
                    {
                        for (int i = 0; i < children; ++i)
                        {
                            transform.GetChild(i).gameObject.SetActive(false);
                        }

                        this.enabled = false;
                        yield break;
                    }
                }
#endif
            }
        }
    }
    /// <summary>
    /// Sets the chosen device as the anchor object, and enables/disables scene objects appropriately.
    /// Called by ChooseTrackedObjectMenu when the user clicks it.
    /// </summary>
    /// <param name="deviceindex">Index of the tracked object.</param>
    private void OnTrackedObjectSelected(int deviceindex)
    {
        //Make sure it's valid.
        ZEDControllerTracker.Devices trackeddevice = ZEDControllerTracker.Devices.Hmd; //Can't be HMD at end - will catch.

#if ZED_STEAM_VR
        ETrackedDeviceClass dclass = OpenVR.System.GetTrackedDeviceClass((uint)deviceindex);
        if (dclass == ETrackedDeviceClass.GenericTracker)
        {
            trackeddevice = ZEDControllerTracker.Devices.ViveTracker;
        }
        else if (dclass == ETrackedDeviceClass.Controller)
        {
            ETrackedControllerRole role = OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)deviceindex);
            if (role == ETrackedControllerRole.LeftHand)
            {
                trackeddevice = ZEDControllerTracker.Devices.LeftController;
            }
            else if (role == ETrackedControllerRole.RightHand)
            {
                trackeddevice = ZEDControllerTracker.Devices.RightController;
            }
            else
            {
                UnityEngine.Debug.Log("Couldn't assign to device of index " + deviceindex + " as it's a controller with an unknown role.");
            }
            //TODO: Make sure this works for a third controller.
        }
#endif

#if ZED_OCULUS
        if (deviceindex == TOUCH_INDEX_LEFT)
        {
            trackeddevice = ZEDControllerTracker.Devices.LeftController;
        }
        else if (deviceindex == TOUCH_INDEX_RIGHT)
        {
            trackeddevice = ZEDControllerTracker.Devices.RightController;
        }
#endif
        //Set up the anchor object, and readjust controllers if needed.
        zedAnchor.gameObject.SetActive(true);

        zedAnchor.controllerTracker.deviceToTrack = trackeddevice;

#if ZED_STEAM_VR
        leftController.index = tempLeftController.index;
#endif

        switch (trackeddevice)
        {
#if ZED_STEAM_VR
        case ZEDControllerTracker.Devices.ViveTracker:
            leftController.index = tempLeftController.index;
            leftController.gameObject.SetActive(true);
            break;
#endif
        case ZEDControllerTracker.Devices.LeftController:
            bellyMenu.gameObject.SetActive(true);
            break;

        case ZEDControllerTracker.Devices.RightController:
            PrimaryHandSwitcher switcher = leftController.GetComponentInChildren <PrimaryHandSwitcher>(true);
            if (!switcher)
            {
                break;
            }
            ToggleGroup3D handtoggle = switcher.transform.GetComponentInChildren <ToggleGroup3D>(true);
            handtoggle.toggleAtStart = false;
            leftController.gameObject.SetActive(true);
            switcher.SetPrimaryHand(false);     //Switch to being left-handed.
            Destroy(rightController.gameObject);
            rightController = null;
            bellyMenu.gameObject.SetActive(true);
            break;

        case ZEDControllerTracker.Devices.Hmd:
        default:
            UnityEngine.Debug.LogError("trackeddevice value somehow not set to valid value - must be a controller or tracker. ");
            break;
        }

        if (viewScreen)
        {
            viewScreen.SetActive(true);
        }

        Destroy(tempLeftController.gameObject);
        tempLeftController = null;

        //We're all done with this menu, so destroy it all.
        Destroy(gameObject);
    }