Пример #1
0
            public override void Check()
            {
                Vector3 mouseCurrentPosition = Instance.GetMousePositionHandler();

                if (needCheckSpeed && (mouseCurrentPosition - mouseLastPosition).magnitude / Time.deltaTime > MouseSpeedThreshold)
                {
                    //鼠标过快移动
                    mouseStopTimeTicker = 0;
                    mouseLastPosition   = mouseCurrentPosition;
                    if (currentTarget)
                    {
                        Release();
                    }

                    return;
                }
                else
                {
                    mouseLastPosition    = mouseCurrentPosition;
                    mouseStopTimeTicker += Time.deltaTime;
                    if (mouseStopTimeTicker > DelaySeconds)
                    {
                        mouseStopTimeTicker = 0;
                        Ray        ray = Camera.ScreenPointToRay(Instance.GetMousePositionHandler());
                        RaycastHit raycast;
                        Physics.Raycast(ray, out raycast, 10f, LayerMask);
                        Debug.DrawLine(ray.origin, ray.origin + 10 * ray.direction.normalized, Color.red, 1f);
                        if (raycast.collider != null)
                        {
                            MouseHoverComponent mouseHoverComponent = raycast.collider.gameObject.GetComponentInParent <MouseHoverComponent>();
                            if (mouseHoverComponent && mouseHoverComponent.GetComponent <T>())
                            {
                                if (currentTarget && currentTarget != mouseHoverComponent)
                                {
                                    Release();
                                }

                                currentTarget           = mouseHoverComponent;
                                currentTarget.IsOnFocus = true;
                            }
                            else
                            {
                                if (currentTarget)
                                {
                                    Release();
                                }
                            }
                        }
                        else
                        {
                            if (currentTarget)
                            {
                                Release();
                            }
                        }
                    }
                }
            }
Пример #2
0
            public override void Check()
            {
                if (Instance.HoverKeyDownHandler())
                {
                    Ray        ray = Camera.ScreenPointToRay(Instance.GetMousePositionHandler());
                    RaycastHit raycast;
                    Physics.Raycast(ray, out raycast, 10f, LayerMask);
                    Debug.DrawLine(ray.origin, ray.origin + 10 * ray.direction.normalized, Color.yellow);
                    if (raycast.collider != null)
                    {
                        MouseHoverComponent mouseHoverComponent = raycast.collider.gameObject.GetComponentInParent <MouseHoverComponent>();
                        if (mouseHoverComponent)
                        {
                            if (mouseHoverComponent.GetComponent <T>())
                            {
                                if (currentTarget && currentTarget != mouseHoverComponent)
                                {
                                    Release();
                                }
                            }

                            currentTarget = mouseHoverComponent;
                            currentTarget.IsOnPressHover = true;
                        }
                        else
                        {
                            if (currentTarget)
                            {
                                Release();
                            }
                        }
                    }
                    else
                    {
                        if (currentTarget)
                        {
                            Release();
                        }
                    }
                }
                else
                {
                    if (currentTarget)
                    {
                        Release();
                    }
                }
            }