Beispiel #1
0
        public static Part GetPartUnderCursor()
        {
            RaycastHit hit;
            Part       part = null;
            Camera     cam  = null;

            if (HighLogic.LoadedSceneIsEditor)
            {
                cam = EditorLogic.fetch.editorCamera;
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                cam = FlightCamera.fetch.mainCamera;
            }

            if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 1000, 557059))
            {
                //part = hit.transform.gameObject.GetComponent<Part>();
                part = (Part)UIPartActionController.GetComponentUpwards("Part", hit.collider.gameObject);
            }
            return(part);
        }
Beispiel #2
0
        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;
                    }
                }
            }
        }