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; } } } }
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); }
private void Awake() { // Debug.Log("[PlayerController]: Awake"); _lastRaycast = null; _nonAllocArray = new RaycastHit[5]; _eventSystem = EventSystem.current; }
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 }; }
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; } } }
public InputData( uint?rawValue, Vector3 normalizedAngles, float?normalizedSlider ) { this.rawValue = rawValue; this.normalizedAngles = normalizedAngles; this.normalizedSlider = normalizedSlider; stylusHit = IRaycastable.current; }
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); }
public Found(int?frame, RaycastHit?hit, IRaycastable obj) { this.frame = frame; this.hit = hit; this.obj = obj; }