private void TargetEnter(InputReceiver inputReceiver) { //status: Status = PointerStatus.Targeting; //sets: Target = inputReceiver.gameObject; //catalog: _targetedInputReceiver = inputReceiver; _targetedInputReceiver.TargetEnter(gameObject); }
private void Awake() { //refs: _audioSource = GetComponent <AudioSource>(); _inputReceiver = GetComponent <InputReceiver>(); //sets: if (targetRenderer != null) { _idleColor = targetRenderer.material.color; } }
private void Awake() { Debug.Log("______MATERIAL TEST________ "); // targetRenderer.sharedMaterial = testOne; //refs: _audioSource = GetComponent <AudioSource>(); _inputReceiver = GetComponent <InputReceiver>(); //sets: if (targetRenderer != null) { _idleColor = targetRenderer.material; } }
private void TargetExit() { if (_dragging) { return; } if (Target != null) { Status = PointerStatus.Idle; //interactions: _targetedInputReceiver?.TargetExit(gameObject); //sets: Target = null; _targetedInputReceiver = null; } //adjust hit information: Normal = inputDriver.motionSource.forward * -1; }
private void Raycast() { //closest params: float closestDistance = float.MaxValue; RaycastHit closestRaycastHit = new RaycastHit(); RaycastHit secondClosestRaycastHit = new RaycastHit(); RaycastHit[] hits = Physics.RaycastAll(inputDriver.motionSource.position, Vector3.Normalize(InternalInteractionPoint - inputDriver.motionSource.position), _currentDistance, layerMask); if (hits.Length > 0) { //find closest: foreach (var item in hits) { if (item.distance < closestDistance) { closestDistance = item.distance; secondClosestRaycastHit = closestRaycastHit; closestRaycastHit = item; } } //look for targets: InputReceiver currentInputReceiver = closestRaycastHit.collider.GetComponent <InputReceiver>(); //we are colliding if we don't have a target: if (Target == null) { //status: Status = PointerStatus.Colliding; } //only consider targetEnter and targetExit if we aren't dragging: if (!_dragging) { if (currentInputReceiver != null) { if (_targetedInputReceiver != currentInputReceiver) { TargetExit(); TargetEnter(currentInputReceiver); _bendPointHistory.Clear(); } } else { TargetExit(); } } //while dragging we need to make sure raycasts against the dragged object do not //get considered in moving the hit point - if they did this dragged object would jump //closer and closer to the origin of the raycast: bool ignoreBecauseDragTarget = false; if (currentInputReceiver != null) { if (Status == PointerStatus.Dragging && _lastSelection == currentInputReceiver.gameObject) { ignoreBecauseDragTarget = true; } } //if this isn't our dragged object then go ahead and ride the cursor along this surface: if (!ignoreBecauseDragTarget) { //adjust hit information: Vector3 backup = Vector3.Normalize(closestRaycastHit.point - inputDriver.motionSource.position) * surfaceOffset; closestRaycastHit.point -= backup; InternalInteractionPoint = closestRaycastHit.point; //only change normal if we are not dragging: if (Status != PointerStatus.Dragging) { Normal = closestRaycastHit.normal; } } //find backing surface hit: if (Status == PointerStatus.Dragging) { //are we hitting something behind the target? if (secondClosestRaycastHit.collider != closestRaycastHit.collider && secondClosestRaycastHit.collider != null) { Vector3 backup = Vector3.Normalize(secondClosestRaycastHit.point - inputDriver.motionSource.position) * surfaceOffset; InternalInteractionPoint = secondClosestRaycastHit.point; } } } else { Status = PointerStatus.Idle; TargetExit(); } }
private void Scan() { RaycastHit[] hits = new RaycastHit[0]; if (raycastAll) { //cast: hits = Physics.RaycastAll(inputDriver.motionSource.position, inputDriver.motionSource.forward, distance, layermask); } else { RaycastHit hit; if (Physics.Raycast(inputDriver.motionSource.position, inputDriver.motionSource.forward, out hit, distance, layermask)) { hits = new RaycastHit[] { hit }; } } if (hits.Length == 0) { if (_targetedReceivers.Count > 0) { foreach (var item in _targetedReceivers) { if (!_selectedReceivers.Contains(item)) { item.TargetExit(gameObject); } } _scannedReceivers.Clear(); _targetedReceivers.Clear(); } return; } //catalog zones: _scannedReceivers.Clear(); foreach (var hit in hits) { InputReceiver zone = hit.transform.GetComponent <InputReceiver>(); if (zone != null) { zone.TargetEnter(gameObject); _scannedReceivers.Add(zone); } } //target exits: foreach (var item in _targetedReceivers) { if (!_selectedReceivers.Contains(item) && !_scannedReceivers.Contains(item)) { item.TargetExit(gameObject); } } //update active zones: _targetedReceivers = new List <InputReceiver>(_scannedReceivers); }