Beispiel #1
0
        private void ColorizeObjects(List <GameObject> gobjects)
        {
            CommandMaterial command = new CommandMaterial(gobjects, GlobalState.CurrentColor, roughnessSlider.Value, metallicSlider.Value);

            command.Submit();
            VRInput.SendHaptic(VRInput.primaryController, 0.1f, 0.2f);
        }
Beispiel #2
0
        public override void OnRayHover(Ray ray)
        {
            base.OnRayHover(ray);

            bool joyRightJustClicked  = false;
            bool joyRightJustReleased = false;
            bool joyRightLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.primaryController, VRInput.JoyDirection.RIGHT, ref joyRightJustClicked, ref joyRightJustReleased, ref joyRightLongPush);

            bool joyLeftJustClicked  = false;
            bool joyLeftJustReleased = false;
            bool joyLeftLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.primaryController, VRInput.JoyDirection.LEFT, ref joyLeftJustClicked, ref joyLeftJustReleased, ref joyLeftLongPush);

            if (joyRightJustClicked || joyLeftJustClicked || joyRightLongPush || joyLeftLongPush)
            {
                if (joyRightJustClicked || joyRightLongPush)
                {
                    Value = Mathf.Clamp(Value + 1.0f, minValue, maxValue);
                }
                else if (joyLeftJustClicked || joyLeftLongPush)
                {
                    Value = Mathf.Clamp(Value - 1.0f, minValue, maxValue);
                }
                onSlideEvent.Invoke(currentValue);
                int intValue = Mathf.RoundToInt(currentValue);
                onSlideEventInt.Invoke(intValue);
            }
        }
Beispiel #3
0
        void Update()
        {
            if (VRInput.TryGetDevices())
            {
                // Toggle selection
                if (enableToggleTool)
                {
                    VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.secondaryButton, () =>
                    {
                        ToolsManager.ToggleTool();
                    });
                }

                // if tool has switch, THIS is now disabled, we dont want updates.
                if (!gameObject.activeSelf)
                {
                    return;
                }

                // Custom tool update
                if (IsInGui)
                {
                    DoUpdateGui();
                }
                else // TODO: voir si il faut pas quand meme faire DoUpdate dans tous les cas.
                // le probleme de faire les deux vient quand ils reagissent au meme input (ex: Grip dans UI)
                {
                    DoUpdate(); // call children DoUpdate
                }
            }
        }
Beispiel #4
0
        private void UpdateSelection()
        {
            // Get right controller buttons states
            bool primaryButtonState = VRInput.GetValue(VRInput.primaryController, CommonUsages.primaryButton);
            bool triggerState       = VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton);

            GameObject hoveredObject = Selection.HoveredObject;

            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.grip,
                                () =>
            {
                Selection.HoveredObject = hoveredObject;
            },
                                () => { Selection.AuxiliarySelection = null; });

            // Multi-selection using the trigger button
            if (triggerState && !GlobalState.Instance.selectionGripped && null != hoveredObject && !selector.Deforming)
            {
                if (!primaryButtonState)
                {
                    foreach (GameObject obj in collidedObjects)
                    {
                        selector.AddSiblingsToSelection(obj);
                    }
                }
            }
        }
Beispiel #5
0
        private void ResetInitControllerMatrices(ResetType res)
        {
            Vector3    initLeftControllerPosition_L;
            Quaternion initLeftControllerRotation_L;

            VRInput.GetControllerTransform(VRInput.secondaryController, out initLeftControllerPosition_L, out initLeftControllerRotation_L);
            Matrix4x4 initLeftControllerMatrix_L = Matrix4x4.TRS(initLeftControllerPosition_L, initLeftControllerRotation_L, Vector3.one);

            initPivotMatrix = Matrix4x4.TRS(pivot.localPosition, pivot.localRotation, pivot.localScale);
            initLeftControllerMatrix_WtoL = (initPivotMatrix * initLeftControllerMatrix_L).inverse;

            if (res == ResetType.LEFT_AND_RIGHT)
            {
                Vector3    initRightControllerPosition_L; // initial right controller position in local space.
                Quaternion initRightControllerRotation_L; // initial right controller rotation in local space.
                VRInput.GetControllerTransform(VRInput.primaryController, out initRightControllerPosition_L, out initRightControllerRotation_L);
                Matrix4x4 initRightControllerMatrix_L = Matrix4x4.TRS(initRightControllerPosition_L, initRightControllerRotation_L, Vector3.one);
                initRightControllerMatrix_WtoL = (initPivotMatrix * initRightControllerMatrix_L).inverse;

                Vector3    initMiddlePosition_L = (initLeftControllerPosition_L + initRightControllerPosition_L) * 0.5f;
                Vector3    middleXVector        = (initRightControllerPosition_L - initLeftControllerPosition_L).normalized;
                Vector3    middleForwardVector  = -Vector3.Cross(middleXVector, pivot.up).normalized;
                Quaternion initMiddleRotation_L = Quaternion.LookRotation(middleForwardVector, pivot.up);
                Matrix4x4  initMiddleMatrix_L   = Matrix4x4.TRS(initMiddlePosition_L, initMiddleRotation_L, Vector3.one);
                initMiddleMatrix_WtoL = (initPivotMatrix * initMiddleMatrix_L).inverse;
            }
        }
Beispiel #6
0
        private void Update()
        {
            // Trigger action forwarded to Colorize script
            bool triggerState = VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton);

            if (triggerState && collidedObjects.Count > 0)
            {
                // Process then remove objects from the list of collided objects in order to prevent
                // processing the same objects each frame (until trigger exit)
                colorizer.ProcessObjects(collidedObjects.ToList());
                collidedObjects.Clear();
            }

            // Scaling of collider
            if (navigation.CanUseControls(NavigationMode.UsedControls.RIGHT_JOYSTICK))
            {
                Vector2 val = VRInput.GetValue(VRInput.primaryController, CommonUsages.primary2DAxis);
                if (val != Vector2.zero)
                {
                    float scale = gameObject.transform.localScale.x;
                    if (val.y > 0.3f)
                    {
                        scale += 0.001f;
                    }
                    if (val.y < -0.3f)
                    {
                        scale -= 0.001f;
                    }
                    scale = Mathf.Clamp(scale, 0.001f, 0.5f);
                    gameObject.transform.localScale = new Vector3(scale, scale, scale);
                }
            }
        }
Beispiel #7
0
        private void HandleTimeManipulation()
        {
            bool joyRightJustClicked  = false;
            bool joyRightJustReleased = false;
            bool joyRightLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.secondaryController, VRInput.JoyDirection.RIGHT, ref joyRightJustClicked, ref joyRightJustReleased, ref joyRightLongPush);

            bool joyLeftJustClicked  = false;
            bool joyLeftJustReleased = false;
            bool joyLeftLongPush     = false;

            VRInput.GetInstantJoyEvent(VRInput.secondaryController, VRInput.JoyDirection.LEFT, ref joyLeftJustClicked, ref joyLeftJustReleased, ref joyLeftLongPush);

            // Manage time with joystick
            if (joyRightJustClicked || joyLeftJustClicked || joyRightLongPush || joyLeftLongPush)
            {
                int frame = GlobalState.Animation.CurrentFrame;
                if (joyRightJustClicked || joyRightLongPush)
                {
                    frame = Mathf.Clamp(frame + 1, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame);
                }
                else
                {
                    frame = Mathf.Clamp(frame - 1, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame);
                }
                GlobalState.Animation.CurrentFrame = frame;
            }
        }
Beispiel #8
0
        void Update()
        {
            if (!VRInput.TryGetDevices())
            {
                return;
            }

            // Device rotation
            VRInput.GetControllerTransform(VRInput.primaryController, out Vector3 position, out Quaternion rotation);

            // The main cursor object always follows the controller
            // so that the collider sticks to the actual hand position.
            transform.localPosition = position;
            transform.localRotation = rotation;

            if (null != ray)
            {
                if (GlobalState.IsGrippingWorld)
                {
                    ray.gameObject.SetActive(false);
                    widgetClicked = null;
                }
                else
                {
                    HandleRaycast();
                }
            }
        }
Beispiel #9
0
        protected override void DoUpdate()
        {
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.triggerButton,
                                () =>
            {
                group = new CommandGroup("Gun");
            },
                                () =>
            {
                group.Submit();
                group = null;
            }
                                );

            bool triggered = VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton);

            if (triggered && prefabs.Count > 0)
            {
                if (Time.time - prevTime > 1f / fireRate)
                {
                    int           prefabIndex = UnityEngine.Random.Range(0, prefabs.Count);
                    GameObject    spawned     = Instantiate(prefabs[prefabIndex]);
                    ThrowedObject throwed     = spawned.AddComponent <ThrowedObject>();
                    throwed.AddForce(transform.forward * power);
                    throwed.SetScale(objectScale);
                    new CommandAddGameObject(spawned).Submit();
                    Matrix4x4 matrix = SceneManager.RightHanded.worldToLocalMatrix * mouthpiece.localToWorldMatrix;
                    Maths.DecomposeMatrix(matrix, out Vector3 t, out _, out _);
                    Vector3 scale = Vector3.one;
                    SceneManager.SetObjectMatrix(spawned, Matrix4x4.TRS(t, Quaternion.identity, scale));
                    prevTime = Time.time;
                }
            }
        }
Beispiel #10
0
        private void UpdateEraser()
        {
            GameObject hoveredObject = Selection.HoveredObject;

            if (null == hoveredObject && Selection.SelectedObjects.Count == 0)
            {
                return;
            }

            // If we have a hovered object, only destroy it
            if (null != hoveredObject)
            {
                // Don't delete UI handles
                if (hoveredObject.GetComponent <UIHandle>())
                {
                    return;
                }

                if (VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton))
                {
                    CommandGroup group = new CommandGroup("Erase Hovered Object");
                    try
                    {
                        RemoveCollidedObject(hoveredObject);
                        selector.RemoveSiblingsFromSelection(hoveredObject, false);

                        new CommandRemoveGameObject(hoveredObject).Submit();
                    }
                    finally
                    {
                        group.Submit();
                    }
                }
            }

            // If we don't have any hovered object but we collided with a selection, delete the whole selection
            else if (collidedObjects.Count > 0 && Selection.IsSelected(collidedObjects[0]))
            {
                if (VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton))
                {
                    CommandGroup group = new CommandGroup("Erase Selected Objects");
                    try
                    {
                        foreach (GameObject gobject in Selection.SelectedObjects)
                        {
                            RemoveCollidedObject(gobject);
                            selector.RemoveSiblingsFromSelection(gobject, false);

                            new CommandRemoveGameObject(gobject).Submit();
                        }
                    }
                    finally
                    {
                        group.Submit();
                    }
                }
            }
        }
Beispiel #11
0
        // Update is called once per frame
        void Update()
        {
            if (!device.isValid)
            {
                CaptureController();
                CaptureInitialTransforms();
            }

            // GRIP
            if (null != gripTransform)
            {
                float gripAmount = VRInput.GetValue(device, CommonUsages.grip);
                gripTransform.localRotation = initGripRotation * Quaternion.Euler(0, gripAmount * gripRotationAmplitude * gripDirection, 0);
                gripTransform.gameObject.GetComponent <MeshRenderer>().material.SetColor("_BaseColor", gripAmount > 0.01f ? UIOptions.SelectedColor : Color.black);
            }

            // TRIGGER
            if (null != triggerTransform)
            {
                float triggerAmount = VRInput.GetValue(device, CommonUsages.trigger);
                triggerTransform.localRotation = initTriggerRotation * Quaternion.Euler(triggerAmount * triggerRotationAmplitude, 0, 0);
                triggerTransform.gameObject.GetComponent <MeshRenderer>().material.SetColor("_BaseColor", triggerAmount > 0.01f ? UIOptions.SelectedColor : Color.black);
            }

            // JOYSTICK
            if (null != joystickTransform)
            {
                Vector2 joystick = VRInput.GetValue(device, CommonUsages.primary2DAxis);
                joystickTransform.localRotation = initJoystickRotation * Quaternion.Euler(joystick.y * joystickRotationAmplitude, 0, joystick.x * -joystickRotationAmplitude);
                joystickTransform.gameObject.GetComponent <MeshRenderer>().materials[1].SetColor("_BaseColor", joystick.magnitude > 0.05f ? UIOptions.SelectedColor : Color.black);
            }

            // PRIMARY
            if (null != primaryTransform)
            {
                bool primaryState = VRInput.GetValue(device, CommonUsages.primaryButton);
                primaryTransform.localPosition = initPrimaryTranslation;
                primaryTransform.gameObject.GetComponent <MeshRenderer>().material.SetColor("_BaseColor", primaryState ? UIOptions.SelectedColor : Color.black);
                if (primaryState)
                {
                    primaryTransform.localPosition += new Vector3(0, 0, primaryTranslationAmplitude); // TODO: quick anim? CoRoutine.
                }
            }

            // SECONDARY
            if (null != secondaryTransform)
            {
                bool secondaryState = VRInput.GetValue(device, CommonUsages.secondaryButton);
                secondaryTransform.localPosition = initSecondaryTranslation;
                secondaryTransform.gameObject.GetComponent <MeshRenderer>().material.SetColor("_BaseColor", secondaryState ? UIOptions.SelectedColor : Color.black);
                if (secondaryState)
                {
                    secondaryTransform.localPosition += new Vector3(0, 0, secondaryTranslationAmplitude); // TODO: quick anim? CoRoutine.
                }
            }
        }
Beispiel #12
0
        private void HandleControllers()
        {
            if (!paletteController.gameObject.activeSelf)
            {
                paletteController.gameObject.SetActive(true);
            }

            // Update controllers transform
            VRInput.UpdateTransformFromVRDevice(paletteController, VRInput.secondaryController);
            VRInput.UpdateTransformFromVRDevice(toolsController, VRInput.primaryController);
        }
Beispiel #13
0
        private void ResetInitControllerMatrices()
        {
            Vector3    initLeftControllerPosition_L;
            Quaternion initLeftControllerRotation_L;

            VRInput.GetControllerTransform(VRInput.secondaryController, out initLeftControllerPosition_L, out initLeftControllerRotation_L);
            Matrix4x4 initLeftControllerMatrix_L = Matrix4x4.TRS(initLeftControllerPosition_L, initLeftControllerRotation_L, Vector3.one);

            initPivotMatrix = Matrix4x4.TRS(pivot.localPosition, pivot.localRotation, pivot.localScale);
            initLeftControllerMatrix_WtoL = (initPivotMatrix * initLeftControllerMatrix_L).inverse;
        }
Beispiel #14
0
 protected override void DoUpdateGui()
 {
     VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.gripButton, () =>
     {
         if (UIObject)
         {
             CreateLight(UIObject.name);
             UIObject = null;
         }
         OnStartGrip();
     }, OnEndGrip);
 }
Beispiel #15
0
 private void HandleUndoRedo()
 {
     VRInput.ButtonEvent(VRInput.secondaryController, CommonUsages.primaryButton, () => { },
                         () =>
     {
         CommandManager.Undo();
     });
     VRInput.ButtonEvent(VRInput.secondaryController, CommonUsages.secondaryButton, () => { },
                         () =>
     {
         CommandManager.Redo();
     });
 }
Beispiel #16
0
        public void SpawnDeleteInstanceVFX(GameObject source)
        {
            GameObject vfxInstance = Instantiate(deleteInstanceVFXPrefab);
            Bounds     bounds      = GetVFXBounds(source);

            vfxInstance.transform.localPosition = bounds.center;
            float s = Mathf.Max(Mathf.Max(bounds.size.x, bounds.size.y), bounds.size.z) * 2f;

            vfxInstance.transform.localScale = Vector3.one * s;
            SoundManager.Instance.PlayUISound(SoundManager.Sounds.Despawn);
            VRInput.SendHapticImpulse(VRInput.primaryController, 0, 0.3f, 0.2f);
            Destroy(vfxInstance, 1f);
        }
Beispiel #17
0
        private void HandleResetScale()
        {
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.primary2DAxisClick,
                                () =>
            {
                ResetCameraClipPlanes();

                Transform cam = vrCamera.transform;
                Vector3 initCameraInWorldPosition = cam.position;
                transform.localScale = Vector3.one;

                transform.position += initCameraInWorldPosition - cam.position;
            });
        }
Beispiel #18
0
        private void HandlePalette()
        {
            if (null == ToolsUIManager.Instance)
            {
                return;
            }

            if (VRInput.GetValue(VRInput.secondaryController, CommonUsages.trigger) > deadZone)
            {
                ToolsUIManager.Instance.PopUpPalette(true);
            }
            else
            {
                ToolsUIManager.Instance.PopUpPalette(false);
            }
        }
Beispiel #19
0
 protected override void DoUpdateGui()
 {
     VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.triggerButton, () =>
     {
     }, () =>
     {
         // Manage click on an asset bank item
         if (selectedItem != -1)
         {
             if (AssetBankUtils.TryGetItem(selectedItem, out AssetBankItemData data))
             {
                 AddPrefab(data);
             }
         }
     });
 }
Beispiel #20
0
        void Update()
        {
            if (VRInput.TryGetDevices())
            {
                // CONTROLLERS
                HandleControllers();

                if (IsInLobby)
                {
                    return;
                }

                // Only in "scene mode" (not in lobby)
                // NAVIGATION
                HandleNavigation();

                // RESET/FIT -- Left Joystick Click
                if (IsCompatibleWithReset(options.currentNavigationMode))
                {
                    HandleReset();
                }

                // RESET SCALE -- Right Joystick Click
                if (IsCompatibleWithResetScale(options.currentNavigationMode))
                {
                    HandleResetScale();
                }

                // PALETTE POP -- Left Trigger
                if (IsCompatibleWithPalette(options.currentNavigationMode))
                {
                    HandlePalette();
                }

                // UNDO/REDO -- Left A/B
                if (IsCompatibleWithUndoRedo(options.currentNavigationMode))
                {
                    HandleUndoRedo();
                }

                // Time manipulation
                if (IsCompatibleWithTimeManipulation(options.currentNavigationMode))
                {
                    HandleTimeManipulation();
                }
            }
        }
Beispiel #21
0
        void Start()
        {
            if (!VRInput.TryGetDevices())
            {
                Debug.LogWarning("PlayerController cannot VRInput.TryGetDevices().");
            }

            if (vrCamera == null)
            {
                Debug.LogWarning("Cannot find 'VRCamera' game object");
            }
            if (paletteController == null)
            {
                Debug.LogWarning("Cannot find 'PaletteController' game object");
            }
            if (toolsController == null)
            {
                Debug.LogWarning("Cannot find 'ToolsController' game object");
            }
            if (pivot == null)
            {
                Debug.LogWarning("Cannot find 'Pivot' game object");
            }

            if (ray != null)
            {
                ray.gameObject.SetActive(false);
            }

            if (teleport != null)
            {
                teleport.gameObject.SetActive(false);
            }

            Tooltips.SetText(VRDevice.SecondaryController, Tooltips.Location.Trigger, Tooltips.Action.HoldPush, "Open Palette");
            Tooltips.SetText(VRDevice.SecondaryController, Tooltips.Location.Primary, Tooltips.Action.Push, "Undo");
            Tooltips.SetText(VRDevice.SecondaryController, Tooltips.Location.Secondary, Tooltips.Action.Push, "Redo");
            Tooltips.SetText(VRDevice.SecondaryController, Tooltips.Location.Joystick, Tooltips.Action.Push, "Reset");
            IsInLobby = true;  // hide tooltips

            OnChangeNavigationMode("BiManual");

            rightHanded = world.Find("Avatars");

            StartCoroutine(SendPlayerTransform());
        }
Beispiel #22
0
        private void PickObjects(List <GameObject> gobjects)
        {
            MeshRenderer renderer = gobjects[0].GetComponentInChildren <MeshRenderer>();

            GlobalState.CurrentColor = renderer.material.GetColor("_BaseColor");
            if (renderer.material.HasProperty("_Smoothness"))
            {
                roughnessSlider.Value = 1f - renderer.material.GetFloat("_Smoothness");
            }
            else
            {
                roughnessSlider.Value = renderer.material.GetFloat("_Roughness");
            }
            metallicSlider.Value = renderer.material.GetFloat("_Metallic");
            UpdatePreview();
            VRInput.SendHaptic(VRInput.primaryController, 0.1f, 0.2f);
        }
Beispiel #23
0
        private void SelectObjects(List <GameObject> gobjects)
        {
            bool     primaryState = VRInput.GetValue(VRInput.primaryController, CommonUsages.primaryButton);
            ICommand command;

            if (!primaryState)
            {
                command = new CommandAddToSelection(gobjects);
            }
            else
            {
                command = new CommandRemoveFromSelection(gobjects);
            }
            command.Redo();
            command.Submit();
            selectionHasChanged = true;
        }
Beispiel #24
0
        public override void OverrideRayEndPoint(Ray ray, ref Vector3 rayEndPoint)
        {
            bool triggerJustClicked  = false;
            bool triggerJustReleased = false;

            VRInput.GetInstantButtonEvent(VRInput.primaryController, CommonUsages.triggerButton, ref triggerJustClicked, ref triggerJustReleased);

            // Project ray on the widget plane.
            Plane widgetPlane = new Plane(-transform.forward, transform.position);

            widgetPlane.Raycast(ray, out float enter);
            Vector3 worldCollisionOnWidgetPlane = ray.GetPoint(enter);

            Vector3 localWidgetPosition          = transform.InverseTransformPoint(worldCollisionOnWidgetPlane);
            Vector3 localProjectedWidgetPosition = new Vector3(localWidgetPosition.x, localWidgetPosition.y, 0.0f);

            if (IgnoreRayInteraction())
            {
                rayEndPoint = transform.TransformPoint(localProjectedWidgetPosition);
                return;
            }


            //Vector2 localCenter = new Vector2(width / 2.0f, -height / 2.0f);
            Vector2 project = new Vector3(localWidgetPosition.x, localWidgetPosition.y);

            if (triggerJustClicked)
            {
                grippedPos = project;
            }

            if (Vector2.Distance(project, grippedPos) < 3.0f * height)
            {
                grippedUnderThreshold          = true;
                localProjectedWidgetPosition.x = grippedPos.x;
                localProjectedWidgetPosition.y = grippedPos.y;
            }
            else
            {
                grippedUnderThreshold = false;
            }

            Vector3 worldProjectedWidgetPosition = transform.TransformPoint(localProjectedWidgetPosition);

            rayEndPoint = worldProjectedWidgetPosition;
        }
Beispiel #25
0
        protected override void DoUpdate()
        {
            // Alt button
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.primaryButton, () =>
            {
                previousColorOp = colorOp;
                colorOp         = ColorOp.Pick;
                uiInitialized   = false;
            }, () =>
            {
                colorOp       = previousColorOp;
                uiInitialized = false;
            });

            // Update UI
            if (!uiInitialized)
            {
                uiInitialized = true;
                switch (colorOp)
                {
                case ColorOp.Colorize: OnSetColorize(); break;

                case ColorOp.UpdateSelection: OnSetUpdateSelection(); break;

                case ColorOp.Pick: OnSetPick(); break;
                }
                UpdatePreview();
            }

            // Clear selection: only when triggering on nothing with the ColorOp.UpdateSelection
            if (ColorOp.UpdateSelection == colorOp)
            {
                VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.triggerButton, () =>
                {
                    selectionHasChanged = false;
                }, () =>
                {
                    if (!selectionHasChanged && ColorOp.UpdateSelection == colorOp)
                    {
                        CommandRemoveFromSelection command = new CommandRemoveFromSelection(Selection.SelectedObjects.ToList());
                        command.Redo();
                        command.Submit();
                    }
                });
            }
        }
Beispiel #26
0
 private void HandleReset()
 {
     VRInput.ButtonEvent(VRInput.secondaryController, CommonUsages.primary2DAxisClick,
                         () =>
     {
         if (Selection.SelectedObjects.Count == 0)
         {
             ResetCameraClipPlanes();
             transform.localPosition = Vector3.zero;
             transform.localRotation = Quaternion.identity;
             transform.localScale    = Vector3.one;
         }
         else
         {
             FitToSelection();
         }
     });
 }
Beispiel #27
0
        void Start()
        {
            if (!VRInput.TryGetDevices())
            {
                Debug.LogWarning("PlayerController cannot VRInput.TryGetDevices().");
            }

            if (vrCamera == null)
            {
                Debug.LogWarning("Cannot find 'VRCamera' game object");
            }
            if (paletteController == null)
            {
                Debug.LogWarning("Cannot find 'PaletteController' game object");
            }
            if (toolsController == null)
            {
                Debug.LogWarning("Cannot find 'ToolsController' game object");
            }
            if (pivot == null)
            {
                Debug.LogWarning("Cannot find 'Pivot' game object");
            }

            if (ray != null)
            {
                ray.gameObject.SetActive(false);
            }

            if (teleport != null)
            {
                teleport.gameObject.SetActive(false);
            }

            Tooltips.InitSecondaryTooltips();

            IsInLobby = true;  // hide tooltips

            OnChangeNavigationMode("BiManual");

            rightHanded = world.Find("Avatars");

            StartCoroutine(SendPlayerTransform());
        }
        // Update is called once per frame
        void Update()
        {
            if (!device.isValid)
            {
                CaptureController();
                CaptureInitialTransforms();
            }

            // GRIP
            if (null != gripTransform)
            {
                float gripAmount = VRInput.GetValue(device, CommonUsages.grip);
                AnimateGrip(gripAmount);
            }

            // TRIGGER
            if (null != triggerTransform)
            {
                float triggerAmout = VRInput.GetValue(device, CommonUsages.trigger);
                AnimateTrigger(triggerAmout);
            }

            // JOYSTICK
            if (null != joystickTransform)
            {
                Vector2 joystick = VRInput.GetValue(device, CommonUsages.primary2DAxis);
                AnimateJoystick(joystick);
            }

            // PRIMARY
            if (null != primaryTransform)
            {
                bool primaryState = VRInput.GetValue(device, CommonUsages.primaryButton);
                AnimatePrimaryButton(primaryState);
            }

            // SECONDARY
            if (null != secondaryTransform)
            {
                bool secondaryState = VRInput.GetValue(device, CommonUsages.secondaryButton);
                AnimateSecondaryButton(secondaryState);
            }
        }
Beispiel #29
0
        public override GameObject CreateInstance(GameObject source, Transform parent = null, bool isPrefab = false)
        {
            GameObject      newLight        = GameObject.Instantiate(source, parent);
            LightController lightController = source.GetComponentInChildren <LightController>();

            VRInput.DeepSetLayer(newLight, "CameraHidden");

            LightController newController = newLight.GetComponentInChildren <LightController>();

            newController.CopyParameters(lightController);
            GlobalState.castShadowsEvent.AddListener(newController.OnCastShadowsChanged);

            if (!GlobalState.Settings.DisplayGizmos)
            {
                GlobalState.SetGizmoVisible(newLight, false);
            }

            return(newLight);
        }
Beispiel #30
0
        protected override void DoUpdateGui()
        {
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.gripButton, () =>
            {
                if (UIObject)
                {
                    Matrix4x4 matrix        = cameraContainer.worldToLocalMatrix * mouthpiece.localToWorldMatrix * Matrix4x4.Scale(new Vector3(5f, 5f, 5f));
                    GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera);

                    GameObject instance = SceneManager.InstantiateUnityPrefab(cameraPrefab);
                    Vector3 position    = matrix.GetColumn(3);
                    Quaternion rotation = Quaternion.AngleAxis(180, Vector3.forward) * Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
                    Vector3 scale       = new Vector3(matrix.GetColumn(0).magnitude, matrix.GetColumn(1).magnitude, matrix.GetColumn(2).magnitude);

                    CommandGroup undoGroup = new CommandGroup("Instantiate Camera");
                    try
                    {
                        ClearSelection();
                        CommandAddGameObject command = new CommandAddGameObject(instance);
                        command.Submit();
                        GameObject newCamera = command.newObject;
                        AddToSelection(newCamera);
                        SceneManager.SetObjectTransform(instance, position, rotation, scale);
                        Selection.HoveredObject = newCamera;
                    }
                    finally
                    {
                        undoGroup.Submit();
                        UIObject = null;
                    }
                }
                OnStartGrip();
            },
                                () =>
            {
                OnEndGrip();
            });

            // called to update focal slider value
            UpdateUI();
        }