/// <summary>Handles everything realted to the pointer.</summary> public static void UpdateHoverDetect() { if (isRunning) { //Cast ray Ray ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition); var colliderHit = Physics.Raycast( ray, out hit, maxDistance: 500, layerMask: (int)(KspLayerMask.Part | KspLayerMask.Kerbal | KspLayerMask.SurfaceCollider), queryTriggerInteraction: QueryTriggerInteraction.Ignore); if (!colliderHit) { pointerTarget = PointerTarget.Nothing; ResetMouseOver(); return; } // Check target type var tgtPart = Mouse.HoveredPart; KerbalEVA tgtKerbalEva = null; AttachNode tgtAttachNode = null; if (!tgtPart) { // check linked part KIS_LinkedPart linkedObject = hit.collider.gameObject.GetComponent <KIS_LinkedPart>(); if (linkedObject) { tgtPart = linkedObject.part; } } if (tgtPart) { tgtKerbalEva = tgtPart.GetComponent <KerbalEVA>(); } // If rigidbody if (hit.rigidbody && !tgtPart && !tgtKerbalEva) { pointerTarget = PointerTarget.StaticRb; } // If kerbal if (tgtKerbalEva) { pointerTarget = PointerTarget.KerbalEva; } // If part if (tgtPart && !tgtKerbalEva) { float currentDist = Mathf.Infinity; foreach (AttachNode an in tgtPart.attachNodes) { if (an.icon) { float dist; var cameraToMouseRay = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition); var iconRenderer = an.icon.GetComponent <Renderer>(); if (iconRenderer.bounds.IntersectRay(cameraToMouseRay, out dist)) { if (dist < currentDist) { tgtAttachNode = an; currentDist = dist; } } } } if (tgtAttachNode != null) { if (tgtAttachNode.icon.name == "KISMount") { pointerTarget = PointerTarget.PartMount; } else { pointerTarget = PointerTarget.PartNode; } } else { pointerTarget = PointerTarget.Part; } } //if nothing if (!hit.rigidbody && !tgtPart && !tgtKerbalEva) { pointerTarget = PointerTarget.Static; } if (tgtPart) { if (tgtAttachNode != null) { // OnMouseEnter node if (tgtAttachNode != hoveredNode) { if (hoveredNode != null) { OnMouseExitNode(hoveredNode); } OnMouseEnterNode(tgtAttachNode); hoveredNode = tgtAttachNode; } } else { // OnMouseExit node if (tgtAttachNode != hoveredNode) { OnMouseExitNode(hoveredNode); hoveredNode = null; } } // OnMouseEnter part if (tgtPart != hoveredPart) { if (hoveredPart) { OnMouseExitPart(hoveredPart); } OnMouseEnterPart(tgtPart); hoveredPart = tgtPart; } } else { // OnMouseExit part if (tgtPart != hoveredPart) { OnMouseExitPart(hoveredPart); hoveredPart = null; } } } }
public void UpdateHoverDetect() { if (isRunning) { //Cast ray Ray ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition); if (!Physics.Raycast(ray, out hit, 500, 557059)) { pointerTarget = PointerTarget.Nothing; ResetMouseOver(); return; } // Check target type Part tgtPart = null; KerbalEVA tgtKerbalEva = null; AttachNode tgtAttachNode = null; if (hit.rigidbody) { tgtPart = hit.rigidbody.GetComponent <Part>(); } if (!tgtPart) { tgtPart = (Part)UIPartActionController.GetComponentUpwards("Part", hit.collider.gameObject); } if (!tgtPart) { // check linked part KIS_LinkedPart linkedObject = hit.collider.gameObject.GetComponent <KIS_LinkedPart>(); if (linkedObject) { tgtPart = linkedObject.part; } } if (tgtPart) { tgtKerbalEva = tgtPart.GetComponent <KerbalEVA>(); } // If rigidbody if (hit.rigidbody && !tgtPart && !tgtKerbalEva) { pointerTarget = PointerTarget.StaticRb; } // If kerbal if (tgtKerbalEva) { pointerTarget = PointerTarget.KerbalEva; } // If part if (tgtPart && !tgtKerbalEva) { float currentDist = Mathf.Infinity; foreach (AttachNode an in tgtPart.attachNodes) { if (an.icon) { float dist; if (an.icon.renderer.bounds.IntersectRay(FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition), out dist)) { if (dist < currentDist) { tgtAttachNode = an; currentDist = dist; } } } } if (tgtAttachNode != null) { if (tgtAttachNode.icon.name == "KISMount") { pointerTarget = PointerTarget.PartMount; } else { pointerTarget = PointerTarget.PartNode; } } else { pointerTarget = PointerTarget.Part; } } //if nothing if (!hit.rigidbody && !tgtPart && !tgtKerbalEva) { pointerTarget = PointerTarget.Static; } if (tgtPart) { if (tgtAttachNode != null) { // OnMouseEnter node if (tgtAttachNode != hoveredNode) { if (hoveredNode != null) { OnMouseExitNode(hoveredNode); } OnMouseEnterNode(tgtAttachNode); hoveredNode = tgtAttachNode; } } else { // OnMouseExit node if (tgtAttachNode != hoveredNode) { OnMouseExitNode(hoveredNode); hoveredNode = null; } } // OnMouseEnter part if (tgtPart != hoveredPart) { if (hoveredPart) { OnMouseExitPart(hoveredPart); } OnMouseEnterPart(tgtPart); hoveredPart = tgtPart; } } else { // OnMouseExit part if (tgtPart != hoveredPart) { OnMouseExitPart(hoveredPart); hoveredPart = null; } } } }