Example #1
0
    public void LookedAt(Vector3 lookerPos, Vector3 rayDirection)
    {
        if (uiAnchor.Length == 0)
        {
            Debug.LogWarning(name);
            return;
        }
        if (!interactable)
        {
            return;
        }

        if (focused != this)
        {
            bestAnchor = uiAnchor[0].transform;
            float bestAngle = 180;
            for (int i = 0; i < uiAnchor.Length; i++)
            {
                float angle = Mathf.Abs(Vector3.Angle(uiAnchor[i].transform.forward, rayDirection));
                if (angle < bestAngle)
                {
                    bestAngle  = angle;
                    bestAnchor = uiAnchor[i].transform;
                }
            }
            UIInteractable.Place(bestAnchor);
            focused = this;
        }
        float dist = Vector3.Distance(lookerPos, bestAnchor.position);

        //looker = lookerPos;
        UIInteractable.canInteract = dist <= actionDistance;

        lastLookedUpon = Time.timeSinceLevelLoad;
    }
Example #2
0
    private void Update()
    {
        UIInteractable uIInteractable = GetComponentInChildren <UIInteractable>();

        if (uIInteractable && uIInteractable.showingKey && (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.Joystick1Button0)))
        {
            Toggle();
        }
    }
Example #3
0
 void Update()
 {
     if (focused != this)
     {
         return;
     }
     if (Time.timeSinceLevelLoad - lastLookedUpon > uiLingerTime || !interactable)
     {
         focused = null;
         UIInteractable.Hide();
     }
 }
Example #4
0
 private void Start()
 {
     if (_instance == null)
     {
         _instance = this;
         canvas    = GetComponent <Canvas>();
         keyHint.gameObject.SetActive(false);
         canvas.enabled = false;
     }
     else if (_instance != this)
     {
         Destroy(gameObject);
     }
 }
Example #5
0
 private void Reset()
 {
     _animator     = GetComponent <Animator>();
     _interactable = GetComponent <UIInteractable>();
 }
Example #6
0
 private void OnDestroy()
 {
     _instance = null;
 }
Example #7
0
        private void LateUpdate()
        {
            bool block = _blockRaycastTriggers.Any(propertyStateTrigger => propertyStateTrigger.IsValid());

            if (!block && _raycastTrigger.IsValid() && _raycastTrigger.RaycastHit.collider.gameObject.GetComponent <UIInteractable>() != null)
            {
                IsRaycasting = true;
                RaycastHit     hit = _raycastTrigger.RaycastHit;
                UIInteractable newHoveredElement = hit.collider.gameObject.GetComponent <UIInteractable>();

                // Did we hover a new element?
                if (newHoveredElement != _hoveredElement)
                {
                    // Hover out on the previous hovered element.
                    if (_hoveredElement != null)
                    {
                        _hoveredElement.HoverOut();
                    }

                    if (newHoveredElement.RaycastInteraction)
                    {
                        _line.gameObject.SetActive(true);
                    }
                    else
                    {
                        _line.gameObject.SetActive(false);
                    }

                    _hoveredElement = newHoveredElement;
                    Debug.Assert(_hoveredElement != null, "We asked for colliders attached to game objects with ClickableInteractable and now we can't find it?");

                    _hoveredElement.HoverIn(_onButtonTrigger.IsValid());
                }

                if (_raycastCollisionTrigger.IsValid())
                {
                    _hoveredElement.Hover(_raycastCollisionTrigger.RaycastHit, transform, true);
                }
                else
                {
                    _hoveredElement.Hover(_raycastCollisionTrigger.RaycastHit, transform, false);
                }

                // Update ray.
                Vector3[] positions = { transform.position, transform.position + transform.forward * (hit.distance + _raycastTrigger.Offset) };
                _line.SetPositions(positions);

                // Pass button events.
                if (_onButtonDownTrigger.IsValid())
                {
                    _hoveredElement.ButtonDown();
                }
                if (_onButtonTrigger.IsValid())
                {
                    _hoveredElement.Button(hit);
                }
                if (_onButtonUpTrigger.IsValid())
                {
                    _hoveredElement.ButtonUp();
                }
            }
            else
            {
                IsRaycasting = false;

                // Did we just leave an element?
                if (_hoveredElement != null)
                {
                    _line.gameObject.SetActive(false);
                    _hoveredElement.HoverOut();
                    _hoveredElement = null;
                }
            }
        }