コード例 #1
0
    void Awake()
    {
        if (TrackPosition == false)
        {
            SimulationOption = WVR_SimulationOption.NoSimulation;
            FollowHead       = false;
        }

        gameObject.SetActive(false);
        PrintDebugLog("Awake() " + this.Type
                      + ", TrackPosition: " + TrackPosition
                      + ", SimulationOption: " + SimulationOption
                      + ", FollowHead: " + FollowHead
                      + ", TrackRotation: " + TrackRotation
                      + ", TrackTiming: " + TrackTiming);

        WaveVR_PointerCameraTracker pcTracker = gameObject.GetComponent <WaveVR_PointerCameraTracker>();

        if (pcTracker == null)
        {
            if (this.Type == WaveVR_Controller.EDeviceType.Head)
            {
                PrintDebugLog("Awake() " + this.Type + ", load WaveVR_DevicePoseTracker.");
                devicePoseTracker = (WaveVR_DevicePoseTracker)gameObject.AddComponent <WaveVR_DevicePoseTracker> ();
                if (null != devicePoseTracker)
                {
                    devicePoseTracker.type            = Type;
                    devicePoseTracker.trackPosition   = TrackPosition;
                    devicePoseTracker.EnableNeckModel = this.EnableNeckModel;
                    devicePoseTracker.trackRotation   = TrackRotation;
                    devicePoseTracker.timing          = TrackTiming;
                }
            }
            else
            {
                PrintDebugLog("Awake() " + this.Type + ", load WaveVR_ControllerPoseTracker.");
                ctrlerPoseTracker = (WaveVR_ControllerPoseTracker)gameObject.AddComponent <WaveVR_ControllerPoseTracker> ();
                if (null != ctrlerPoseTracker)
                {
                    ctrlerPoseTracker.Type             = Type;
                    ctrlerPoseTracker.TrackPosition    = TrackPosition;
                    ctrlerPoseTracker.SimulationOption = SimulationOption;
                    ctrlerPoseTracker.FollowHead       = FollowHead;
                    ctrlerPoseTracker.TrackRotation    = TrackRotation;
                    ctrlerPoseTracker.TrackTiming      = TrackTiming;
                }
            }
        }
        gameObject.SetActive(true);
    }
コード例 #2
0
    void Awake()
    {
        if (TrackPosition == false)
        {
            SimulationOption = WVR_SimulationOption.NoSimulation;
            FollowHead       = false;
        }

        gameObject.SetActive(false);
        PrintDebugLog("Awake() TrackPosition: " + TrackPosition + ", SimulationOption=" + SimulationOption +
                      ", FollowHead: " + FollowHead + ", TrackRotation: " + TrackRotation + ", TrackTiming=" + TrackTiming);

        WaveVR_PointerCameraTracker pcTracker = gameObject.GetComponent <WaveVR_PointerCameraTracker>();

        if (SimulationOption == WVR_SimulationOption.ForceSimulation || SimulationOption == WVR_SimulationOption.WhenNoPosition)
        {
            if (pcTracker == null)
            {
                PrintDebugLog("Awake() load WaveVR_ControllerPoseTracker.");
                WaveVR_ControllerPoseTracker _cpt = (WaveVR_ControllerPoseTracker)gameObject.AddComponent <WaveVR_ControllerPoseTracker> ();
                if (null != _cpt)
                {
                    _cpt.Type             = Type;
                    _cpt.TrackPosition    = TrackPosition;
                    _cpt.SimulationOption = SimulationOption;
                    _cpt.FollowHead       = FollowHead;
                    _cpt.TrackRotation    = TrackRotation;
                    _cpt.TrackTiming      = TrackTiming;
                }
            }
        }
        else
        {
            if (pcTracker == null)
            {
                PrintDebugLog("Awake() load WaveVR_DevicePoseTracker.");
                WaveVR_DevicePoseTracker _dpt = (WaveVR_DevicePoseTracker)gameObject.AddComponent <WaveVR_DevicePoseTracker> ();
                if (null != _dpt)
                {
                    _dpt.type          = Type;
                    _dpt.trackPosition = TrackPosition;
                    _dpt.trackRotation = TrackRotation;
                    _dpt.timing        = TrackTiming;
                }
            }
        }
        gameObject.SetActive(true);
    }
コード例 #3
0
    void OnEnable()
    {
        WaveVR_PoseTrackerManager _ptm = (WaveVR_PoseTrackerManager)gameObject.GetComponent(typeof(WaveVR_PoseTrackerManager));

        if (_ptm != null)
        {
            Type = _ptm.Type;
            WaveVR_EventSystemControllerProvider.Instance.SetControllerModel(Type, gameObject);
            added = true;
        }
        else
        {
            WaveVR_ControllerPoseTracker _cpt = gameObject.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                this.Type = _cpt.Type;
                WaveVR_EventSystemControllerProvider.Instance.SetControllerModel(Type, gameObject);
                added = true;
            }
        }
    }
コード例 #4
0
    public void FollowHMD()
    {
        WaveVR_ControllerPoseTracker _cpt = null;

        if (this.domintController != null)
        {
            _cpt = this.domintController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("FollowHMD() right.");
                _cpt.FollowHead = true;
            }
        }
        if (this.noDomiController != null)
        {
            _cpt = this.noDomiController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("FollowHMD() left.");
                _cpt.FollowHead = true;
            }
        }
    }
コード例 #5
0
    public void RealPose()
    {
        WaveVR_ControllerPoseTracker _cpt = null;

        if (this.domintController != null)
        {
            _cpt = this.domintController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("RealPose() real right.");
                _cpt.SimulationOption = WVR_SimulationOption.NoSimulation;
            }
        }
        if (this.noDomiController != null)
        {
            _cpt = this.noDomiController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("RealPose() real left.");
                _cpt.SimulationOption = WVR_SimulationOption.NoSimulation;
            }
        }
    }
コード例 #6
0
    public void SimulatePose()
    {
        WaveVR_ControllerPoseTracker _cpt = null;

        if (this.domintController != null)
        {
            _cpt = this.domintController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("SimulatePose() simulate dominant pose.");
                _cpt.SimulationOption = WVR_SimulationOption.ForceSimulation;
            }
        }
        if (this.noDomiController != null)
        {
            _cpt = this.noDomiController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("SimulatePose() simulate non-dominant pose.");
                _cpt.SimulationOption = WVR_SimulationOption.ForceSimulation;
            }
        }
    }
コード例 #7
0
    public void NoFollowHMD()
    {
        WaveVR_ControllerPoseTracker _cpt = null;

        if (this.domintController != null)
        {
            _cpt = this.domintController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("NoFollowHMD() dominant.");
                _cpt.FollowHead = false;
            }
        }
        if (this.noDomiController != null)
        {
            _cpt = this.noDomiController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("NoFollowHMD() non-dominant.");
                _cpt.FollowHead = false;
            }
        }
    }
    public override void OnInspectorGUI()
    {
        WaveVR_ControllerPoseTracker myScript = target as WaveVR_ControllerPoseTracker;

        myScript.Type          = (WaveVR_Controller.EDeviceType)EditorGUILayout.EnumPopup("Type", myScript.Type);
        myScript.TrackPosition = EditorGUILayout.Toggle("Track Position", myScript.TrackPosition);
        if (true == myScript.TrackPosition)
        {
            myScript.SimulationOption = (WVR_SimulationOption)EditorGUILayout.EnumPopup("    Simulate Position", myScript.SimulationOption);
            if (myScript.SimulationOption == WVR_SimulationOption.ForceSimulation || myScript.SimulationOption == WVR_SimulationOption.WhenNoPosition)
            {
                myScript.FollowHead = (bool)EditorGUILayout.Toggle("        Follow Head", myScript.FollowHead);
            }
        }

        myScript.TrackRotation = EditorGUILayout.Toggle("Track Rotation", myScript.TrackRotation);
        myScript.TrackTiming   = (WVR_TrackTiming)EditorGUILayout.EnumPopup("Track Timing", myScript.TrackTiming);

        if (GUI.changed)
        {
            EditorUtility.SetDirty((WaveVR_ControllerPoseTracker)target);
        }
    }
コード例 #9
0
    public void SimulatePose()
    {
        WaveVR_ControllerPoseTracker _cpt = null;

        if (this.rightController != null)
        {
            _cpt = this.rightController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("SimulatePose() simulate right.");
                _cpt.SimulationOption = WVR_SimulationOption.ForceSimulation;
            }
        }
        if (this.leftController != null)
        {
            _cpt = this.leftController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("SimulatePose() simulate left.");
                _cpt.SimulationOption = WVR_SimulationOption.ForceSimulation;
            }
        }
    }
コード例 #10
0
    public void NoFollowHMD()
    {
        WaveVR_ControllerPoseTracker _cpt = null;

        if (this.rightController != null)
        {
            _cpt = this.rightController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("NoFollowHMD() right.");
                _cpt.FollowHead = false;
            }
        }
        if (this.leftController != null)
        {
            _cpt = this.leftController.GetComponent <WaveVR_ControllerPoseTracker> ();
            if (_cpt != null)
            {
                PrintDebugLog("NoFollowHMD() left.");
                _cpt.FollowHead = false;
            }
        }
    }
コード例 #11
0
    private void onLoadController()
    {
        // Make up file name
        // Rule =
        // ControllerModel_TrackingMethod_CComponent_Hand
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
            genericControllerFileName = "Generic_";

            genericControllerFileName += "MC_";

            if (WhichHand == ControllerHand.Controller_Right)
            {
                genericControllerFileName += "R";
            }
            else
            {
                genericControllerFileName += "L";
            }

            originalControllerPrefab = Resources.Load(controllerModelFoler + genericControllerFileName) as GameObject;
            if (originalControllerPrefab == null)
            {
                Debug.Log("Cant load generic controller model, Please check file under Resources/" + controllerModelFoler + genericControllerFileName + ".prefab is exist!");
            }
            else
            {
                Debug.Log(genericControllerFileName + " controller model is found!");
                controllerPrefab = Instantiate(originalControllerPrefab, transform.position, transform.rotation);
                controllerPrefab.transform.parent = this.transform.parent;

                if (TrackingMethod == CTrackingSpace.CTS_6DOF)
                {
                    WaveVR_ControllerPoseTracker armComp = controllerPrefab.GetComponent <WaveVR_ControllerPoseTracker>();
                    if (armComp != null)
                    {
                        armComp.trackPosition = true;
                    }
                    Debug.Log("Controller model CTS_USE_Position");
                }

                Debug.Log("Controller model loaded");
                if (onControllerModelLoaded != null)
                {
                    Debug.Log("trigger delegate");
                    onControllerModelLoaded(controllerPrefab);
                }
            }
            return;
        }
#endif
        if (WhichHand == ControllerHand.Controller_Right)
        {
            deviceType = WVR_DeviceType.WVR_DeviceType_Controller_Right;
        }
        else
        {
            deviceType = WVR_DeviceType.WVR_DeviceType_Controller_Left;
        }

        string parameterName    = "GetRenderModelName";
        IntPtr ptrParameterName = Marshal.StringToHGlobalAnsi(parameterName);

        IntPtr ptrResult        = Marshal.AllocHGlobal(30);
        uint   resultVertLength = 30;

        Interop.WVR_GetParameters(deviceType, ptrParameterName, ptrResult, resultVertLength);

        string renderModelName = Marshal.PtrToStringAnsi(ptrResult);

        Log.i(LOG_TAG, "get controller id from runtime is " + renderModelName);

        controllerFileName += renderModelName;
        controllerFileName += "_";

        if (ControllerComponents == CComponent.Multi_Component)
        {
            controllerFileName += "MC_";
        }
        else
        {
            controllerFileName += "OB_";
        }

        if (WhichHand == ControllerHand.Controller_Right)
        {
            controllerFileName += "R";
        }
        else
        {
            controllerFileName += "L";
        }

        Log.i(LOG_TAG, "controller file name is " + controllerFileName);

        originalControllerPrefab = Resources.Load(controllerModelFoler + controllerFileName) as GameObject;
        var found = true;

        if (originalControllerPrefab == null)
        {
            if (WhichHand == ControllerHand.Controller_Right)
            {
                genericControllerFileName += "MC_R";
            }
            else
            {
                genericControllerFileName += "MC_L";
            }
            Log.w(LOG_TAG, "cant find preferred controller model, load generic controller : " + genericControllerFileName);
            Log.i(LOG_TAG, "Please download controller model from .... to have better experience!");
            originalControllerPrefab = Resources.Load(controllerModelFoler + genericControllerFileName) as GameObject;
            if (originalControllerPrefab == null)
            {
                Log.e(LOG_TAG, "Cant load generic controller model, Please check file under Resources/" + controllerModelFoler + genericControllerFileName + ".prefab is exist!");
                found = false;
            }
            else
            {
                Log.i(LOG_TAG, genericControllerFileName + " controller model is found!");
            }
        }
        else
        {
            Log.i(LOG_TAG, controllerFileName + " controller model is found!");
        }

        if (found)
        {
            controllerPrefab = Instantiate(originalControllerPrefab, transform.position, transform.rotation);
            controllerPrefab.transform.parent = this.transform.parent;

            if (TrackingMethod == CTrackingSpace.CTS_SYSTEM)
            {
                if (WaveVR.Instance.is6DoFTracking() == 6)
                {
                    WaveVR_ControllerPoseTracker armComp = controllerPrefab.GetComponent <WaveVR_ControllerPoseTracker>();
                    if (armComp != null)
                    {
                        armComp.trackPosition = true;
                    }
                    Log.i(LOG_TAG, "Controller model CTS_ENABLE_ArmModel (CTS_SYSTEM = 6DOF)");
                }
            }
            else if (TrackingMethod == CTrackingSpace.CTS_6DOF)
            {
                WaveVR_ControllerPoseTracker armComp = controllerPrefab.GetComponent <WaveVR_ControllerPoseTracker>();
                if (armComp != null)
                {
                    armComp.trackPosition = true;
                }
                Log.i(LOG_TAG, "Controller model CTS_ENABLE_ArmModel (force enable)");
            }

            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.CONTROLLER_MODEL_LOADED, deviceType, controllerPrefab);
        }
        Marshal.FreeHGlobal(ptrParameterName);
        Marshal.FreeHGlobal(ptrResult);
    }