private void Awake()
        {
            try
            {
                Input.GetAxisRaw("Axis1");
            }
            catch (Exception e)
            {
                Debug.LogError("Input Manager for XRInteraction Library has not been setup." +
                               " This can be corrected by selecting Fjord > XRInteraction > Setup Input Manager. " +
                               e.Message);
                return;
            }

            XRDevice.SetTrackingSpaceType(_trackingSpaceType);

            configuration = null;
            if (XRSettings.loadedDeviceName == "OpenVR")
            {
                string openVRDevice = "OpenVR-" + OpenVRTrackingSystemName();
                Debug.Log("Trying to find XRUserConfiguration " + openVRDevice + " on " + name);
                configuration = _configs.Find(
                    c => c.DeviceName == openVRDevice
                    );
            }
            else
            {
                Debug.Log("Trying to find XRUserConfiguration " + XRSettings.loadedDeviceName + " on " + name);
                configuration = _configs.Find(
                    c => c.DeviceName == XRSettings.loadedDeviceName
                    );
            }

            if (null != configuration)
            {
                Debug.Log("Loading XRUserConfiguration: " + configuration.DeviceName);
                InputTracking.nodeAdded        += InputTracking_nodeAdded;
                InputTracking.nodeRemoved      += InputTracking_nodeRemoved;
                InputTracking.trackingAcquired += InputTracking_trackingAcquired;
                InputTracking.trackingLost     += InputTracking_trackingLost;
            }
            else
            {
                Debug.LogError("XR User configuration not found for " + XRSettings.loadedDeviceName);
            }

            UserHead = Instantiate(_userHeadPrefab, Vector3.zero, Quaternion.identity);
            UserHead.gameObject.RemoveCloneSuffix();
            UserHead.transform.SetParent(transform);
        }
Exemple #2
0
        public virtual void Initialize(
            Chirality controllerChirality,
            XRUserRoot userRoot,
            XRUserRootConfig config,
            ulong uniqueID)
        {
            UserRoot            = userRoot;
            UniqueID            = uniqueID;
            ControllerChirality = controllerChirality;
            _inputMap           = config.InputMapping(controllerChirality);
            _hapticMap          = config.HapticMap;

            switch (ControllerChirality)
            {
            case Chirality.Left:
                _xrNode = XRNode.LeftHand;
                break;

            case Chirality.Right:
                _xrNode = XRNode.RightHand;
                break;

            case Chirality.None:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (null != config.HapticEngine)
            {
                HapticEngine = Instantiate(config.HapticEngine);
                HapticEngine.transform.SetParent(transform);
                HapticEngine.transform.localPosition = Vector3.zero;
                HapticEngine.Initialize(controllerChirality);
            }
            else
            {
                Debug.Log("HapticEngine is null for " + _inputMap.name + " on " + name);
            }

            SetupInputs(_inputMap);

            XRControllerModel model = Instantiate(config.ControllerModelPrefab(controllerChirality));

            model.transform.SetParent(transform);
            model.transform.localPosition = Vector3.zero;
            model.transform.localRotation = Quaternion.identity;
            model.Initialize(this);

            for (int i = 0; i < _physicsInteractors.Count; ++i)
            {
                _physicsInteractors[i].transform.position = model.FrontAnchor.transform.position;
                _physicsInteractors[i].transform.rotation = model.FrontAnchor.transform.rotation;
            }
            if (null != UnityUIInteractor)
            {
                UnityUIInteractor.transform.position = model.FrontAnchor.transform.position;
                UnityUIInteractor.transform.rotation = model.FrontAnchor.transform.rotation;
            }
        }