Example #1
0
        void Start()
        {
            _interactGrab = GetComponent <VRTK_InteractGrab>();

            _lineRenderer = gameObject.GetComponent <LineRenderer>();

            _lineRenderer.startWidth = RayWidth;
            _lineRenderer.endWidth   = RayWidth;

            _lineRenderer.startColor = Color.cyan;
            _lineRenderer.endColor   = Color.cyan;

            _lineRenderer.enabled = false;

            _rayGrabColliderObject = new GameObject("RayGrabCollider");

            _rayGrabCollider           = _rayGrabColliderObject.AddComponent <SphereCollider>();
            _rayGrabCollider.radius    = GrabColliderRadius;
            _rayGrabCollider.isTrigger = true;

            _rayGrabColliderObject.layer = LayerMask.NameToLayer("Ignore Raycast");

            _raycastHit = new RaycastHit();

            _vrtkPointer = GetComponent <VRTK_StraightPointerRenderer>();

            _rayGrabColliderObject.transform.SetParent(_vrtkPointer.transform);
            _rayGrabColliderObject.transform.localPosition = Vector3.zero;
        }
Example #2
0
    public void Start()
    {
        pointer          = GetComponent <VRTK_Pointer>();
        bezierRenderer   = GetComponent <VRTK_BezierPointerRenderer>();
        straightRenderer = GetComponent <VRTK_StraightPointerRenderer>();

        attacker  = PlayerController.GetComponent <PlayerAttacker>();
        commander = PlayerController.GetComponent <PlayerCommander>();
        digger    = PlayerController.GetComponent <PlayerDigger>();
        flyer     = PlayerController.GetComponent <PlayerFlyer>();
        grabber   = PlayerController.GetComponent <PlayerGrabber>();
        mover     = PlayerController.GetComponent <PlayerMover>();
        summoner  = PlayerController.GetComponent <PlayerSummoner>();

        mover.PointerRenderer = bezierRenderer;

        SetPointer(false);

        pointer.DestinationMarkerHover += (object marker, DestinationMarkerEventArgs args) => {
            destinationArgs = args;
            destination     = args.destinationPosition;
        };

        controllerEvents = GetComponent <VRTK_ControllerEvents>();

        controllerEvents.TriggerPressed   += OnTriggerPressed;
        controllerEvents.TriggerReleased  += OnTriggerReleased;
        controllerEvents.TouchpadPressed  += OnTouchpadPressed;
        controllerEvents.TouchpadReleased += OnTouchpadReleased;
    }
Example #3
0
        public void Enable(IHandController ctl)
        {
            if (point != null)
            {
                GameObject.Destroy(point);
            }
            if (renderer != null)
            {
                GameObject.Destroy(renderer);
            }
            if (raycast != null)
            {
                GameObject.Destroy(raycast);
            }

            point    = ctl.gameObject.AddComponent <VRTK_Pointer>();
            renderer = ctl.gameObject.AddComponent <VRTK_StraightPointerRenderer>();
            raycast  = ctl.gameObject.AddComponent <VRTK_CustomRaycast>();

            point.pointerRenderer  = renderer;
            renderer.customRaycast = raycast;

            point.enableTeleport   = false;
            point.activationButton = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            raycast.layersToIgnore = ctl.Player.PointerIgnoreLayers;
        }
Example #4
0
 // Use this for initialization
 void Start()
 {
     vrtkControllerEvents         = GetComponent <VRTK_ControllerEvents> ();
     vrtk_Pointer                 = GetComponent <VRTK_Pointer> ();
     vrtk_StraightPointerRenderer = GetComponent <VRTK_StraightPointerRenderer> ();
     vrtk_BezierPointerRenderer   = GetComponent <VRTK_BezierPointerRenderer> ();
 }
    private void Start()
    {
        rightPointer         = ReferenceHandler.Instance.GetRightPointer();
        rightPointerRenderer = ReferenceHandler.Instance.GetRightPointerRenderer();

        rightPointer.ActivationButtonPressed  += SetPointerActivated;
        rightPointer.ActivationButtonReleased += SetPointerDeactivated;
    }
Example #6
0
 void Start()
 {
     io  = GetComponentInParent <VRTK_InteractableObject>();
     po  = GetComponent <VRTK_Pointer>();
     spr = GetComponent <VRTK_StraightPointerRenderer>();
     io.InteractableObjectGrabbed   += ObjectGrabbed;
     io.InteractableObjectUngrabbed += ObjectUngrabbed;
 }
Example #7
0
 private void Start()
 {
     rightPointer  = rightController.GetComponent <VRTK_Pointer>();
     leftPointer   = leftController.GetComponent <VRTK_Pointer>();
     rightBezier   = rightController.GetComponent <VRTK_BezierPointerRenderer>();
     rightStraight = rightController.GetComponent <VRTK_StraightPointerRenderer>();
     leftBezier    = leftController.GetComponent <VRTK_BezierPointerRenderer>();
     leftStraight  = leftController.GetComponent <VRTK_StraightPointerRenderer>();
 }
Example #8
0
        void leftpress()
        {
            if (leftcontrol == 0)
            {
                meshCollider.enabled = true;

                GameObject.Destroy(currentCollisionMesh);
                currentCollisionMesh    = GameObject.Instantiate(cloth.clothMesh);
                meshCollider.sharedMesh = currentCollisionMesh;

                VRTK_StraightPointerRenderer tmp = GameObject.Find("LeftController").GetComponent <VRTK_StraightPointerRenderer>();
                Ray ray = tmp.getray();

                RaycastHit hitInfo;
                //Debug.Log("left_drag");
                if (meshCollider.Raycast(ray, out hitInfo, 100))
                {
                    int[]     tris     = currentCollisionMesh.triangles;
                    Vector3[] vertices = currentCollisionMesh.vertices;

                    lefthit = hitInfo;
                    // find closest vertex in the triangle we just hit:
                    int   closestVertex = -1;
                    float minDistance   = float.MaxValue;

                    for (int i = 0; i < 3; ++i)
                    {
                        int   vertex   = tris[hitInfo.triangleIndex * 3 + i];
                        float distance = (vertices[vertex] - hitInfo.point).sqrMagnitude;
                        if (distance < minDistance)
                        {
                            minDistance   = distance;
                            closestVertex = vertex;
                        }
                    }

                    // get particle index:
                    if (closestVertex >= 0 && closestVertex < cloth.topology.visualMap.Length)
                    {
                        pickedParticleIndexLeft = cloth.topology.visualMap[closestVertex];
                        pickedParticleDepthLeft = Mathf.Abs((cloth.transform.TransformPoint(vertices[closestVertex]) - Camera.main.transform.position).z);

                        if (OnParticlePickedLeft != null)
                        {
                            //Vector3 worldPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, pickedParticleDepthLeft));
                            Vector3 worldPosition = new Vector3(hitInfo.point.x, hitInfo.point.y, pickedParticleDepthLeft);
                            OnParticlePickedLeft(this, new ParticlePickEventArgs(pickedParticleIndexLeft, worldPosition));
                        }
                    }
                }

                meshCollider.enabled = false;
                leftcontrol++;
            }
        }
Example #9
0
 void OnEnable()
 {
     fpscontrollerScript = GameObject.FindGameObjectWithTag("Player").GetComponent <UnityStandardAssets.Characters.FirstPerson.FirstPersonController>();
     //pixel = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren<Pixelation>();
     if (!pointer)
     {
         pointer = GameObject.Find("RightController").GetComponent <VRTK_Pointer>();
     }
     straightRenderer = GameObject.Find("RightController").GetComponent <VRTK_StraightPointerRenderer>();
     //  pointer.enabled = false;
     // straightRenderer.enabled = false;
 }
        void MakeItSo()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                return;
            }

            if (!enablePointer.IsNone)
            {
                pointer         = go.GetComponent <VRTK_Pointer>();
                pointer.enabled = enablePointer.Value;
            }

            // set pointer renderer to be beizer
            if (enableBezierRenderer.Value)
            {
                bezier = go.GetComponent <VRTK_BezierPointerRenderer>();
                pointer.pointerRenderer = bezier;
            }

            // set pointer renderer to be straight
            if (enableStraightRenderer.Value)
            {
                straight = go.GetComponent <VRTK_StraightPointerRenderer>();
                pointer.pointerRenderer = straight;
            }

            if (!enableBezierRenderer.IsNone)
            {
                bezier         = go.GetComponent <VRTK_BezierPointerRenderer>();
                bezier.enabled = enableBezierRenderer.Value;
            }

            if (!enableHeightAdjustTele.IsNone)
            {
                heightTeleport         = go.GetComponent <VRTK_HeightAdjustTeleport>();
                heightTeleport.enabled = enableHeightAdjustTele.Value;
            }

            if (!enableStraightRenderer.IsNone)
            {
                straight         = go.GetComponent <VRTK_StraightPointerRenderer>();
                straight.enabled = enableStraightRenderer.Value;
            }

            if (!enableBodyTeleport.IsNone)
            {
                bodyPhysics = bodyPhysicsGO.Value.GetComponent <VRTK_BodyPhysics>();
                bodyPhysics.enableTeleport = enableBodyTeleport.Value;
            }
        }
Example #11
0
        private IEnumerator WaitPointer()
        {
            VRTK_StraightPointerRenderer vrtkPointer = null;

            while (vrtkPointer == null)
            {
                yield return(new WaitForEndOfFrame());

                vrtkPointer = RightHand.GetComponentInChildren <VRTK_StraightPointerRenderer>();
            }

            yield return(true);
        }
Example #12
0
    // Use this for initialization
    void Start()
    {
        ClusterLabelingEnabled = true;
        LabelingEnabled        = true;

        rightPointer         = ReferenceHandler.Instance.GetRightPointer();
        rightPointerRenderer = ReferenceHandler.Instance.GetRightPointerRenderer();

        rightPointer.ActivationButtonPressed  += SetPointerActivated;
        rightPointer.ActivationButtonReleased += SetPointerDeactivated;
        rightPointer.SelectionButtonPressed   += SetPointerSelectionActivated;
        rightPointer.SelectionButtonReleased  += SetPointerSelectionDeactivated;

        startTime = Time.realtimeSinceStartup;
    }
Example #13
0
    protected override void Update()
    {
        base.Update();

        if (controller != null)
        {
            VRTK_StraightPointerRenderer pointer = controller.GetComponent <VRTK_StraightPointerRenderer> ();
            Vector3 pos = Quaternion.AngleAxis(controller.transform.rotation.eulerAngles.y, Vector3.up) * Vector3.forward * speed * Time.deltaTime;
            transform.position           += pos;
            pointer.validCollisionColor   = color;
            pointer.invalidCollisionColor = color;
            //VRTK_DeviceFinder.HeadsetTransform.pointerActivatesUseAction += pos;
            GameObject.Find("[CameraRig]").transform.position += pos;
        }
    }
Example #14
0
    void Start()
    {
        rightPointer         = ReferenceHandler.Instance.GetRightPointer();
        rightPointerRenderer = ReferenceHandler.Instance.GetRightPointerRenderer();

        //rightPointer.ActivationButtonPressed += PointerEnabled;
        //rightPointer.ActivationButtonReleased += PointerDisabled;

        _displayTransform = GetComponent <RectTransform>();
        Transform parent = _displayTransform.parent.transform;

        _displayTransform.position = parent.position + (parent.up * 0.1f);
        //gameObject.SetActive(false);
        DisplayEnabled = true;
        UpdatePointerDisplay();
    }
Example #15
0
        private bool boolRightPointerEnabled;                      // Whether the right controller's pointer is enabled or disabled.


        // Awake is called on initialization, BEFORE Start.
        void Awake()
        {
            LeftPointer          = LeftController.GetComponent <VRTK_Pointer>();
            LeftPointerRenderer  = LeftController.GetComponent <VRTK_BezierPointerRenderer>();
            RightPointer         = RightController.GetComponent <VRTK_Pointer>();
            RightPointerRenderer = RightController.GetComponent <VRTK_StraightPointerRenderer>();
            RightUIPointer       = RightController.GetComponent <VRTK_UIPointer>();

            LeftPointerRenderer.enabled  = false;
            LeftPointer.enabled          = false;
            RightUIPointer.enabled       = false;
            RightPointerRenderer.enabled = false;
            RightPointer.enabled         = false;

            LeftUI.SetActive(false);
            RightUI.SetActive(false);
        }
Example #16
0
    void Start()
    {
        leftPointer         = ReferenceHandler.Instance.GetLeftPointer();
        leftPointerRenderer = ReferenceHandler.Instance.GetLeftPointerRenderer();

        leftPointer.ActivationButtonPressed  += PointerTeleport_ActivationButtonPressed;
        leftPointer.ActivationButtonReleased += PointerTeleport_ActivationButtonReleased;
        leftPointer.SelectionButtonPressed   += PointerTeleport_SelectionButtonPressed;

        PointerLengthDisplay.Instance.Disable();
        leftPointerRenderer.maximumLength = _iDefaultPointerLength;
        PointerTeleportEnabled            = true;

        if (MovementOptions.MoveMode != Util.MovementMode.TeleportMode)
        {
            leftPointerRenderer.enabled = false;
        }
    }
Example #17
0
    // Use this for initialization
    void Start()
    {
        terrainSound = GetComponent <AudioSource>();
        evts         = GetComponentInParent <VRTK_ControllerEvents>();

        pointerRenderer = GetComponentInParent <VRTK_StraightPointerRenderer>();

        xResolution      = terrain.terrainData.heightmapWidth;
        zResolution      = terrain.terrainData.heightmapHeight;
        alphaMapWidth    = terrain.terrainData.alphamapWidth;
        alphaMapHeight   = terrain.terrainData.alphamapHeight;
        numOfAlphaLayers = terrain.terrainData.alphamapLayers;


        //Back up the terrain's height and alpha maps so that you don't permanently alter it
        heightMapBackup = terrain.terrainData.GetHeights(0, 0, xResolution, zResolution);
        alphaMapBackup  = terrain.terrainData.GetAlphamaps(0, 0, alphaMapWidth, alphaMapHeight);
    }
    // this method returns the cursor that is touching the current object
    private GameObject getCursor(object sender, InteractableObjectEventArgs e)
    {
        //Debug.Log("getCursor");

        //Debug.Log(sender.ToString());
        GameObject controller = e.interactingObject;

        //Debug.Log("interacting object:::    " + controller.GetType());
        Component[] controllerComponents = controller.GetComponents <Component>();
        //Debug.Log("controller components ::::    " + controllerComponents.ToString());

        VRTK_StraightPointerRenderer pointerRenderer = null;

        foreach (Component c in controllerComponents)
        {
            //Debug.Log("components ::::    " + c.ToString());
            if (c.GetType() == typeof(VRTK_StraightPointerRenderer))
            {
                pointerRenderer = (VRTK_StraightPointerRenderer)c;
            }
        }

        if (pointerRenderer == null)
        {
            Debug.Log("Pointer renderer not found");
        }

        //GameObject cursor = pointerRenderer.getCursor();
        GameObject cursor = pointerRenderer.GetPointerObjects()[1];

        //Debug.Log("cursor transform local position:::: " + cursor.transform.position);

        if (cursor != null)
        {
            //Debug.Log("cursor.transform.position: " + cursor.transform.position);
            return(cursor);
        }
        else
        {
            Debug.Log("cursor not found");
            return(null);
        }
    }
Example #19
0
    void OnEnable()
    {
        try {
            leftctrl = VRTK_DeviceFinder.GetControllerLeftHand();
        } catch (Exception e) {
            Debug.Log(e);
        }

        if (leftctrl == null)
        {
            leftctrl = GameObject.FindGameObjectWithTag("LeftController");
        }


        pointer   = leftctrl.GetComponent <VRTK_Pointer>();
        uiPointer = leftctrl.GetComponent <VRTK_UIPointer>();
        bezeierPointerRenderer  = leftctrl.GetComponent <VRTK_BezierPointerRenderer>();
        straightPointerRenderer = leftctrl.GetComponent <VRTK_StraightPointerRenderer>();
        //straightPointerRenderer = leftctrl.GetComponent<Custom_VRTK_UIStraightPointerRenderer>();
        controllerEvents = leftctrl.GetComponent <VRTK_ControllerEvents>();
    }
Example #20
0
    // this method returns the cursor that is touching the current object
    private GameObject getCursor(object sender, InteractableObjectEventArgs e)
    {
        //Debug.Log("getCursor");

        // get the interacting object (the controller) and its components
        GameObject controller = e.interactingObject;

        Component[] controllerComponents = controller.GetComponents <Component>();

        // find the straight pointer renderer, this probably could be condensed to just GetComponent<VRTK_StraightPointerRenderer>()
        VRTK_StraightPointerRenderer pointerRenderer = null;

        foreach (Component c in controllerComponents)
        {
            if (c.GetType() == typeof(VRTK_StraightPointerRenderer))
            {
                pointerRenderer = (VRTK_StraightPointerRenderer)c;
            }
        }

        // if the pointer renderer is null, output a log
        if (pointerRenderer == null)
        {
            Debug.Log("Pointer renderer not found");
        }

        GameObject cursor = pointerRenderer.GetPointerObjects()[1];

        // if the cursor isn't null, return it, else return null and debug
        if (cursor != null)
        {
            return(cursor);
        }
        else
        {
            Debug.Log("cursor not found");
            return(null);
        }
    }
Example #21
0
 private void Start()
 {
     uiPointer       = ReferenceHandler.Instance.GetRightUiPointer();
     pointerRenderer = ReferenceHandler.Instance.GetRightPointerRenderer();
 }
Example #22
0
        public void Enable(IHandController ctl)
        {
            ctl.Events.ButtonTwoPressed += OnMenu;

            if (point != null)
            {
                GameObject.Destroy(point);
            }
            if (renderer != null)
            {
                GameObject.Destroy(renderer);
            }
            if (raycast != null)
            {
                GameObject.Destroy(raycast);
            }
            if (policyList != null)
            {
                GameObject.Destroy(policyList);
            }
            if (menuObj != null)
            {
                GameObject.Destroy(menuObj);
            }
            // No need to destroy menu, as it should have been attached to menuObj
            // (and if it wasn't then we have bigger problems to worry about)

            point      = ctl.gameObject.AddComponent <VRTK_Pointer>();
            renderer   = ctl.gameObject.AddComponent <VRTK_StraightPointerRenderer>();
            raycast    = ctl.gameObject.AddComponent <VRTK_CustomRaycast>();
            policyList = ctl.gameObject.AddComponent <VRTK_PolicyList>();
            menuObj    = new GameObject("ModeMenu");
            menu       = menuObj.AddComponent <ModeMenu>();

            point.pointerRenderer  = renderer;
            point.targetListPolicy = policyList;
            renderer.customRaycast = raycast;

            point.enableTeleport   = false;
            point.activationButton = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            point.selectionButton  = VRTK_ControllerEvents.ButtonAlias.TriggerPress;
            point.selectOnPress    = false;
            raycast.layersToIgnore = ctl.Player.PointerIgnoreLayers;
            policyList.checkType   = VRTK_PolicyList.CheckTypes.Script;
            policyList.operation   = VRTK_PolicyList.OperationTypes.Include;
            policyList.identifiers = new List <string> {
                nameof(ModeMenuItem)
            };

            point.DestinationMarkerEnter += (sender, e) => Debug.Log(e.target);
            point.DestinationMarkerSet   += (sender, e) => {
                var item = e.target.GetComponent <ModeMenuItem>();

                if (item != null)
                {
                    switch (item.type)
                    {
                    case ModeMenuItem.ModeType.Primary: modeCtl.SelectPrimary(item.index); break;

                    case ModeMenuItem.ModeType.Grip: modeCtl.SelectGrip(item.index); break;
                    }

                    modeCtl.EndMenu();
                }
            };

            menuObj.transform.position = ctl.gameObject.transform.position;
            // The ternary ensures the menu's not flipped if you're pointing the controller backwards
            menuObj.transform.rotation = Quaternion.Euler(
                0.0f,
                ctl.gameObject.transform.eulerAngles.y + (ctl.gameObject.transform.up.y < 0.0f ? 180.0f : 0.0f),
                0.0f);
            menuObj.transform.localScale = ctl.gameObject.transform.lossyScale;

            menu.Init(ctl.Player, modeCtl);
        }
Example #23
0
 // Use this for initialization
 void Start()
 {
     sprScript = rightController.GetComponent <VRTK_StraightPointerRenderer>();
     uipScript = rightController.GetComponent <VRTK_UIPointer>();
     pScript   = rightController.GetComponent <VRTK_Pointer>();
 }