Пример #1
0
 private void OnHover()
 {
     RaycastHit[] rays = CursorOver();
     foreach (RaycastHit ray in rays)
     {
         IRaycastable comp = ray.collider.gameObject.GetComponent <IRaycastable>();
         if (comp != null)
         {
             if (comp != m_target)
             {
                 if (m_target)
                 {
                     m_target.OnHoverExit();
                 }
                 m_target = comp;
                 comp.OnHoverEnter();
             }
             comp.OnHoverStay();
             break;
         }
         else
         {
             if (m_target)
             {
                 m_target.OnHoverExit();
                 m_target = null;
             }
         }
     }
 }
Пример #2
0
        private bool InteractWithComponent()
        {
            var hits = RayCastAllSorted();

            foreach (var hit in hits)
            {
                if (hit.transform == null)
                {
                    continue;
                }
                var interfaces = hit.transform.GetComponents <IRaycastable>();
                foreach (var interactable in interfaces)
                {
                    if (!interactable.HandleRayCast())
                    {
                        continue;
                    }
                    SetCursor(interactable.GetCursorType());
                    _lastRaycast = interactable;
                    return(true);
                }
            }

            if (_lastRaycast == null)
            {
                return(false);
            }
            _lastRaycast.OnRaycastExit();
            _lastRaycast = null;
            return(false);
        }
Пример #3
0
 private void Awake()
 {
     // Debug.Log("[PlayerController]: Awake");
     _lastRaycast   = null;
     _nonAllocArray = new RaycastHit[5];
     _eventSystem   = EventSystem.current;
 }
Пример #4
0
    protected virtual void Awake()
    {
        _renderer = GetComponent <MeshRenderer>();
        _filter   = GetComponent <MeshFilter>();
        _collider = GetComponent <PolygonCollider2D>();
        _parent   = Transform.parent?.GetComponent <IRaycastable>();

        if (_customColor != CustomColor.None)
        {
            _color = ColorUtils.GetColor(_customColor, TRANSPARENCY);
            SetColor(_color);
        }

        _colorPropertyId    = Shader.PropertyToID("_Color");
        _emissionPropertyId = Shader.PropertyToID("_EmissionColor");


        _angleStep = _viewAngle / _detailAmount;
        _angleAxis = Quaternion.AngleAxis(_viewAngle / 2f, Vector3.forward) * _startAngle;

        Active = true;

        _mesh = InitMesh(_size, _detailAmount);
        _filter.sharedMesh = _mesh;

        _contactFilter = new ContactFilter2D
        {
            useLayerMask    = true,
            layerMask       = 1 << LayerMask.NameToLayer("Obstacle") | 1 << LayerMask.NameToLayer("DynamicObstacle") | 1 << LayerMask.NameToLayer("Enemy"),
                useTriggers = false
        };
    }
Пример #5
0
    private void RaycastForTarget()
    {
        if (ClickedOnUI())
        {
            return;
        }

        Ray        ray = mainCam.ScreenPointToRay(Input.mousePosition);
        RaycastHit info;

        if (Physics.Raycast(ray, out info))
        {
            IRaycastable raycastable = info.collider.GetComponent <IRaycastable>();
            if (raycastable != null)
            {
                if (selection != null)
                {
                    selection.HandleDeselect();
                }

                selection = raycastable;

                selection.HandleClick();
            }
            else
            {
                if (selection != null)
                {
                    selection.HandleDeselect();
                }

                selection = null;
            }
        }
    }
Пример #6
0
        public InputData(
            uint?rawValue,
            Vector3 normalizedAngles,
            float?normalizedSlider
            )
        {
            this.rawValue         = rawValue;
            this.normalizedAngles = normalizedAngles;
            this.normalizedSlider = normalizedSlider;

            stylusHit = IRaycastable.current;
        }
Пример #7
0
        public IRaycastable Raycast(out RaycastHit?hit)
        {
            if (lastFound.frame == Time.frameCount)
            {
                hit = lastFound.hit;
                return(lastFound.obj);
            }

            var raycastable = IRaycastable.Raycast(orientation.pos, orientation.rot, out hit);

            lastFound = new Found(Time.frameCount, hit, raycastable);

            return(raycastable);
        }
Пример #8
0
 public Found(int?frame, RaycastHit?hit, IRaycastable obj)
 {
     this.frame = frame;
     this.hit   = hit;
     this.obj   = obj;
 }