示例#1
0
            private void LateUpdate()
            {
                if (!IsInitialized)
                {
                    return;
                }

                VRController lastOffHandController = OffHandController;
                VRController currentMainController = VRControllerAccessor(ref _originalPointer);

                OffHandController = currentMainController == _rightController ? _leftController : _rightController;

                if (lastOffHandController != OffHandController)
                {
                    if (_laserPointerTransform == null)
                    {
                        _laserPointerTransform = Instantiate(_pointerPrefab, OffHandController.transform, false);
                    }
                    else
                    {
                        _laserPointerTransform.SetParent(OffHandController.transform, false);
                    }
                    SetPositionAndScale(_defaultPointerLength);
                }
            }
        private void Construct(
            PluginConfig config,
            SiraLog logger,
            [InjectOptional] PauseController pauseController,
            MovementController movementController,
            InputManager inputManager,
            SaberControllerBearer saberControllerBearer,
            SaberType saberType,
            SaberTrickModel saberTrickModel,
            AudioTimeSyncController audioTimeSyncController,
            Trick.Factory trickFactory)
        {
            _config                  = config;
            _logger                  = logger;
            _pauseController         = pauseController;
            _movementController      = movementController;
            _inputManager            = inputManager;
            _audioTimeSyncController = audioTimeSyncController;
            SaberTrickModel          = saberTrickModel;

            _saber        = saberControllerBearer[saberType].Saber;
            _vrController = saberControllerBearer[saberType].VRController;

            _trickFactory = trickFactory;
        }
示例#3
0
 private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (VRController._IsRunning)
     {
         VRController.Stop();
     }
 }
示例#4
0
    private void TestVRControllerButtons(string s, VRController c)
    {
        // Buttons
        if (c.Button1.OnDown)
        {
            print(s + "button1 pressed");
        }
        if (c.Button1_Touch.OnDown)
        {
            print(s + "Button1 touched");
        }
        if (c.Button2.OnDown)
        {
            print(s + "Button2 pressed");
        }
        if (c.Button2_Touch.OnDown)
        {
            print(s + "Button2 touched");
        }

        if (c.Index_Touch.OnDown)
        {
            print(s + "Index touched");
        }
        if (c.Thumb_Touch.OnDown)
        {
            print(s + "Thumb touched.");
        }
        if (c.Thumb_Press.OnDown)
        {
            print(s + "Thumb pressed.");
        }
    }
示例#5
0
    void PushSelected(VRController c, ControllerComponentArgs e)
    {
        // @stats
        // joystick pushpull
        // Calcflow.UserStatistics.StatisticsTracking.StartEvent("Joystick", "Push-Pull",
        // new Dictionary<string, object>()
        // {
        //     {"Hand", rayGrabber.gameObject.name}
        // });

        if (Mathf.Abs(e.x) > Mathf.Abs(e.y))
        {
            return;
        }

        Vector3 currPos = rayGrabber.transform.position;
        Vector3 nextPos = currPos + transform.forward * e.y * speed;

        float angle = Vector3.Angle(transform.forward, nextPos - transform.position);


        if (Mathf.Abs(angle) < 90)
        {
            rayGrabber.transform.position = nextPos;
        }

        // @stats
        // joystick pushpull
        // Calcflow.UserStatistics.StatisticsTracking.EndEvent("Joystick", "Push-Pull",
        // new Dictionary<string, object>()
        // {
        //     {"Hand", rayGrabber.gameObject.name}
        // });
    }
        public static void BeingDragCamera(Cam2 camera)
        {
            if (grabbedCamera != null)
            {
                FinishCameraMove();
            }

            var controllers = Resources.FindObjectsOfTypeAll <VRLaserPointer>();

            controller = (!HookFPFCToggle.isInFPFC ?
                          controllers.LastOrDefault(x => x.isActiveAndEnabled) :
                          controllers.LastOrDefault(x =>
            {
                var controllerTransform = x.transform;
                return(controllerTransform.eulerAngles + controllerTransform.position != Vector3.zero);
            })
                          )?.GetComponentInParent <VRController>();

            if (controller == null)
            {
                return;
            }

            //TODO: I should probably move this to use a Transformer...
            grabbedCamera = camera;
            camTransform  = camera.UCamera.transform;

            grabStartPos = controller.transform.InverseTransformPoint(camTransform.position);
            grabStartRot = Quaternion.Inverse(controller.rotation) * camTransform.rotation;

            grabbedCamera.worldCam.SetPreviewPositionAndSize(false);
        }
 // Start is called before the first frame update
 void Start()
 {
     controllerWithFocus = null;
     prevGrabRotation    = Quaternion.identity;
     startingRotation    = transform.localRotation;
     grabbed             = false;
 }
示例#8
0
        public void Init(VRController vrController, SaberTrickManager saberTrickManager)
        {
            Controller        = vrController;
            SaberTrickManager = saberTrickManager;

            enabled = true;
        }
示例#9
0
        protected virtual void Update()
        {
            if (_vrPointer.vrController != null)
            {
                if (GetGrip())
                {
                    if (_grabbingController != null)
                    {
                        return;
                    }
                    RaycastHit hit;
                    if (Physics.Raycast(_vrPointer.vrController.position, _vrPointer.vrController.forward, out hit, MaxLaserDistance))
                    {
                        if (hit.transform != _moveable)
                        {
                            return;
                        }
                        _grabbingController = _vrPointer.vrController;
                        _grabPos            = _vrPointer.vrController.transform.InverseTransformPoint(_moveable.position);
                        _grabRot            = Quaternion.Inverse(_vrPointer.vrController.transform.rotation) * _moveable.rotation;
                    }
                }
            }

            if (_grabbingController == null || GetGrip())
            {
                return;
            }
            if (_grabbingController == null)
            {
                return;
            }
            wasMoved?.Invoke(_realPos, _realRot, _realScale);
            _grabbingController = null;
        }
示例#10
0
        static void Postfix(VRController __instance)
        {
            if (!PluginConfig.Instance.Enabled)
            {
                return;
            }

            Plugin.Multi.checkMessages();
            if (ReferenceEquals(__instance, RemoteSaber.LeftSaber))
            {
                if (PluginConfig.Instance.isLeftRemoteSaber)
                {
                    __instance.transform.position = Plugin.Multi.getLatestPosition();
                    __instance.transform.rotation = Plugin.Multi.getLatestRotation();
                }
                else
                {
                    Plugin.Multi.sendCoords(__instance.transform.position, __instance.transform.rotation);
                }
            }
            else if (ReferenceEquals(__instance, RemoteSaber.RightSaber))
            {
                if (!PluginConfig.Instance.isLeftRemoteSaber)
                {
                    __instance.transform.position = Plugin.Multi.getLatestPosition();
                    __instance.transform.rotation = Plugin.Multi.getLatestRotation();
                }
                else
                {
                    Plugin.Multi.sendCoords(__instance.transform.position, __instance.transform.rotation);
                }
            }
        }
    void ControllerGrab(VRController controller, bool gripped)
    {
        if (gripped)
        {
            rb.isKinematic     = true;
            rb.velocity        = Vector3.zero;
            rb.angularVelocity = Vector3.zero;

            // world to local space
            grabRotationOffset = Quaternion.Inverse(controller.transform.rotation) * rb.transform.rotation;
            grabOffset         = controller.transform.InverseTransformPoint(rb.transform.position);

            grabbed = true;

            if (onGrabStartEvent != null)
            {
                onGrabStartEvent(controller);
            }
        }
        else
        {
            rb.isKinematic     = false;
            rb.velocity        = controller.LinearVelocity;
            rb.angularVelocity = controller.AngularVelocity;

            grabbed = false;

            if (onGrabEndEvent != null)
            {
                onGrabEndEvent(controller);
            }
        }
    }
示例#12
0
        public RemoteSaber(GameObject gameCore)
        {
            Plugin.Log.Info("Searching Sabers ...");

            var saberManagerObj = gameCore.transform
                                  .Find("Origin")
                                  ?.Find("VRGameCore")
                                  ?.Find("SaberManager");

            if (saberManagerObj == null)
            {
                Plugin.Log.Critical("Couldn't find SaberManager !");
                return;
            }

            var saberManager = saberManagerObj.GetComponent <SaberManager>();

            LeftSaber  = saberManager.GetPrivateField <Saber>("_leftSaber").GetComponent <VRController>();
            RightSaber = saberManager.GetPrivateField <Saber>("_rightSaber").GetComponent <VRController>();

            if (LeftSaber is null || RightSaber is null)
            {
                Plugin.Log.Critical("Sabers cannot be found !");
                return;
            }

            Plugin.Log.Info("Sabers Found !");
        }
示例#13
0
文件: Gun.cs 项目: silky/calcflow
    public override void triggerReleaseOperation(VRController c, ControllerComponentArgs e)
    {
        base.triggerReleaseOperation(c, e);

        switch (currMode)
        {
        case 0:
            break;

        case 1:
            break;

        case 2:
            if (ball != null)
            {
                print(i++);
                ball.name = "CurveBall";
                ball.transform.SetParent(null, true);
                ball.AddComponent <Rigidbody>();
                rb = ball.GetComponent <Rigidbody>();

                rb.interpolation          = RigidbodyInterpolation.Interpolate;
                rb.mass                   = ballsize / .01f;
                rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
                rb.velocity               = transform.forward * 10;
                rb.useGravity             = false;
            }
            break;
        }
    }
示例#14
0
文件: Gun.cs 项目: silky/calcflow
    public override void triggerHoldOperation(VRController c, ControllerComponentArgs e)
    {
        base.triggerHoldOperation(c, e);
        switch (currMode)
        {
        case 0:
            break;

        case 1:
            ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            ball.transform.localScale = new Vector3(.01f, .01f, .01f);
            ball.transform.position   = tip.position;
            rb = ball.AddComponent <Rigidbody>();
            rb.interpolation          = RigidbodyInterpolation.Interpolate;
            rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
            rb.velocity   = transform.forward * 10;
            rb.useGravity = false;
            break;

        case 2:
            ballsize += 1 / (ballsize / .0001f);
            ball.transform.localScale += new Vector3(ballsize, ballsize, ballsize);
            break;
        }
    }
示例#15
0
 public void OnObjectStopUsing(VRController _controller)
 {
     if (isUsable && (_controller.InputSource == allowedSource || allowedSource == SteamVR_Input_Sources.Any))
     {
         onGrabbed.Invoke(GenerateArgs(_controller));
     }
 }
示例#16
0
 // This code was straight copied from xyonico's camera+ mod, so all credit goes to him :)
 public void Update()
 {
     //Plugin.Log($"ChatMover! VRPointer: {(_vrPointer != null ? "NOT NULL" : "NULL")}");
     if (ChatConfig.instance.LockChatPosition)
     {
         return;
     }
     if (_vrPointer.vrController != null)
     {
         if (_vrPointer.vrController.triggerValue > 0.9f)
         {
             if (_grabbingController != null)
             {
                 return;
             }
             if (Physics.Raycast(_vrPointer.vrController.transform.position, _vrPointer.vrController.forward, out var hit, MaxLaserDistance))
             {
                 if (hit.transform != _moverCube)
                 {
                     return;
                 }
                 _grabbingController = _vrPointer.vrController;
                 _grabPos            = _vrPointer.vrController.transform.InverseTransformPoint(ChatConfig.instance.ChatPosition);
                 _grabRot            = Quaternion.Inverse(_vrPointer.vrController.transform.rotation) * _moverCube.rotation;
             }
         }
     }
     if (_grabbingController == null || !(_grabbingController.triggerValue <= 0.9f))
     {
         return;
     }
     _grabbingController = null;
 }
示例#17
0
    // Use this for initialization
    void Start()
    {
        file = new StreamWriter("MaxSpeed.txt");
        if (GameObject.Find("PreferenceLoader") == null)
        {
            GameObject obj = Instantiate(Resources.Load("PreferenceLoader")) as GameObject;
            obj.name = "PreferenceLoader";
        }
        pl = GameObject.Find("PreferenceLoader").GetComponent <PreferenceLoader>();         // Get PreferenceLoader script which stores all user setting.


        DirectionSwitch = new Vector3(1, 0, 0);


        pixels2World = (Camera.main.orthographicSize * 2.0f) / Camera.main.pixelHeight; // screen space to world space ratio
        maxHeadAcc   = 0f;
        maxHeadSpeed = 0f;


        //Connect to other scripts
        //dataSource = GetComponent<DataSource>();
        vrController = GetComponent <VRController>();

        /*if(dataSource != null)
         *  dataSource.initializeSource(sourceType);*/
    }
示例#18
0
        protected virtual void Update()
        {
            if (_vrPointer.vrController != null)
            {
                if (_vrPointer.vrController.triggerValue > 0.9f || Input.GetMouseButton(0))
                {
                    if (_grabbingController != null)
                    {
                        return;
                    }
                    if (Physics.Raycast(_vrPointer.vrController.position, _vrPointer.vrController.forward, out RaycastHit hit, MaxLaserDistance))
                    {
                        if (hit.transform != _screenHandle)
                        {
                            return;
                        }
                        _grabbingController = _vrPointer.vrController;
                        _grabPos            = _vrPointer.vrController.transform.InverseTransformPoint(_floatingScreen.transform.position);
                        _grabRot            = Quaternion.Inverse(_vrPointer.vrController.transform.rotation) * _floatingScreen.transform.rotation;
                        OnGrab?.Invoke(_floatingScreen.transform.position, _floatingScreen.transform.rotation);
                    }
                }
            }

            if (_grabbingController == null || !_isFpfc && _grabbingController.triggerValue > 0.9f ||
                _isFpfc && Input.GetMouseButton(0))
            {
                return;
            }
            _grabbingController = null;
            OnRelease?.Invoke(_floatingScreen.transform.position, _floatingScreen.transform.rotation);
        }
示例#19
0
 public void ReceiverJoystickInput(VRController c, ControllerComponentArgs e)
 {
     if (JoyStickTouched != null)
     {
         JoyStickTouched.Invoke(c, e);
     }
 }
示例#20
0
 static void Postfix(ref VRController ____leftVRController, ref bool ____lastControllerUsedWasRight)
 {
     if (____leftVRController.active == false)
     {
         ____lastControllerUsedWasRight = true;
     }
 }
示例#21
0
    void ControllerGrab(VRController controller, bool gripped)
    {
        if (!enabled)
        {
            return;
        }

        if (gripped)
        {
            prevGrabRotation = Quaternion.Inverse(controller.transform.rotation) * transform.rotation;
            grabbed          = true;

            if (onPreGrabStartEvent != null)
            {
                onPreGrabStartEvent(controller);
            }

            if (onGrabStartEvent != null)
            {
                onGrabStartEvent(controller);
            }
        }
        else
        {
            Ungrab(controller);
        }
    }
示例#22
0
 public void OnObjectReleased(VRController _controller)
 {
     if (isGrabbable && IsInputSourceAllowed(_controller))
     {
         onReleased.Invoke(GenerateArgs(_controller));
     }
 }
示例#23
0
    void RotateSelected(VRController c, ControllerComponentArgs e)
    {
        // @stats
        // joystick rotate
        // Calcflow.UserStatistics.StatisticsTracking.StartEvent("Joystick", "Rotate",
        // new Dictionary<string, object>()
        // {
        //     {"Hand", rayGrabber.gameObject.name}
        // });

        if (Mathf.Abs(e.y) > Mathf.Abs(e.x))
        {
            return;
        }

        rayGrabber.transform.RotateAround(rayGrabber.transform.position, Vector3.up, e.x * 4);

        // @stats
        // joystick pushpull
        // Calcflow.UserStatistics.StatisticsTracking.EndEvent("Joystick", "Rotate",
        // new Dictionary<string, object>()
        // {
        //     {"Hand", rayGrabber.gameObject.name}
        // });
    }
示例#24
0
 public void OnObjectTouched(VRController _controller)
 {
     if (isTouchable && IsInputSourceAllowed(_controller))
     {
         onTouched.Invoke(GenerateArgs(_controller));
     }
 }
示例#25
0
    // This section is not needed to make a new tool.
    #region driving mechanics
    protected override void OnReleaseController(Grabber g)
    {
        VRController c = g.controller;

        // removes the tools callbacks from the controllers event system.
        c.components[ButtonId.TRIGGER].ComponentPressed   -= triggerPressOperation;
        c.components[ButtonId.TRIGGER].ComponentPressing  -= triggerHoldOperation;
        c.components[ButtonId.TRIGGER].ComponentUnpressed -= triggerReleaseOperation;

        // if grabbed by 2 hands at once, attaches controller to hand that is still grabbing.
        if (activeGrabbers.Count == 1)
        {
            AttachToPivot(activeGrabbers.First.Value.transform, false);
        } // if the releasing hand was the only one grabbing, detaches the tool and transfers momentum.
        else if (activeGrabbers.Count == 0)
        {
            DetachFromPivot();
            if (GetComponent <Rigidbody>() != null)
            {
                Rigidbody r = GetComponent <Rigidbody>();
                r.velocity        = c.Velocity;
                r.angularVelocity = c.AngularVelocity;
            }
            isGrabbed = false;
            triggerReleaseOperation(c, new ControllerComponentArgs());
            DetachFromPivot();
            OnDeselect();
        }
    }
示例#26
0
 public void OnObjectStopUsing(VRController _controller)
 {
     if (isUsable && IsInputSourceAllowed(_controller))
     {
         onStopUsing.Invoke(GenerateArgs(_controller));
     }
 }
示例#27
0
        internal void ApplyToGameCore(GameObject gameCore)
        {
            LeftSaber  = null;
            RightSaber = null;

            Plugin.Log.Info("Setting up grip adjustments...");

            var saberManagerObj = gameCore.transform
                                  .Find("Origin")
                                  ?.Find("VRGameCore")
                                  ?.Find("SaberManager");

            if (saberManagerObj == null)
            {
                Plugin.Log.Critical("Couldn't find SaberManager, bailing!");
                return;
            }

            var saberManager = saberManagerObj.GetComponent <SaberManager>();

            LeftSaber  = saberManager.GetPrivateField <Saber>("_leftSaber").GetComponent <VRController>();
            RightSaber = saberManager.GetPrivateField <Saber>("_rightSaber").GetComponent <VRController>();

            if (LeftSaber is null || RightSaber is null)
            {
                Plugin.Log.Critical("Sabers couldn't be found. Bailing!");
                return;
            }

            Plugin.Log.Info("Grip adjustments ready!");
        }
示例#28
0
 public void Update()
 {
     vrController = vrPointer?.vrController;
     if (vrController != null)
     {
         if (vrController.triggerValue > 0.9f)
         {
             if (Vector3.Distance(vrController.transform.position, transform.position) < maxDistance)
             {
                 if (objectMover != null && objectMover.grabbedObject == null)
                 {
                     if (pressed == false)
                     {
                         pressed = true;
                         Plugin.twitchIRC.SendTwitchMessage(message);
                     }
                 }
             }
         }
     }
     if (vrController.triggerValue < 0.9f)
     {
         pressed = false;
     }
 }
示例#29
0
        protected virtual void Update()
        {
            if (_vrPointer.vrController != null)
            {
                if (_vrPointer.vrController.triggerValue > 0.9f)
                {
                    if (_grabbingController != null)
                    {
                        return;
                    }
                    if (Physics.Raycast(_vrPointer.vrController.position, _vrPointer.vrController.forward, out var hit, MaxLaserDistance))
                    {
                        if (hit.transform != _cameraCube)
                        {
                            return;
                        }
                        _grabbingController = _vrPointer.vrController;
                        _grabPos            = _vrPointer.vrController.transform.InverseTransformPoint(_cameraCube.position);
                        _grabRot            = Quaternion.Inverse(_vrPointer.vrController.transform.rotation) * _cameraCube.rotation;
                    }
                }
            }

            if (_grabbingController == null || !(_grabbingController.triggerValue <= 0.9f))
            {
                return;
            }
            if (_grabbingController == null)
            {
                return;
            }
            SaveToConfig();
            _grabbingController = null;
        }
示例#30
0
        public override void Update()
        {
            base.Update();
            if (vrController != null)
            {
                if (vrController.triggerValue > 0.9f)
                {
                    if (_grabbingController != null)
                    {
                        return;
                    }
                    RaycastHit hit;
                    if (Physics.Raycast(vrController.position, vrController.forward, out hit, _defaultLaserPointerLength))
                    {
                        if (hit.transform.name != "CameraCube")
                        {
                            return;
                        }
                        _grabbedCamera      = hit.transform;
                        _grabbingController = vrController;
                        _grabPos            = vrController.transform.InverseTransformPoint(_grabbedCamera.position);
                        _grabRot            = Quaternion.Inverse(vrController.transform.rotation) * _grabbedCamera.rotation;
                    }
                }
            }

            if (_grabbingController == null || !(_grabbingController.triggerValue <= 0.9f))
            {
                return;
            }

            SaveToIni();
            _grabbingController = null;
        }