示例#1
0
文件: Paint.cs 项目: huqiang0204/HGUI
        public bool CheckPix(Vector2 pos)
        {
            var dx = pos.x - Start.x;
            var dy = pos.y - Start.y;

            if (dx * dx + dy * dy < sqr)
            {
                return(true);
            }
            dx = pos.x - End.x;
            dy = pos.y - End.y;
            if (dx * dx + dy * dy < sqr)
            {
                return(true);
            }
            if (box != null)
            {
                return(Physics2D.DotToPolygon(box, pos));
            }
            return(false);
        }
        public static bool DispatchEvent(ModelElement ui, Vector3 pos, Vector3 scale, Quaternion quate, UserAction action)
        {
            if (ui == null)
            {
                return(false);
            }
            if (!ui.activeSelf)
            {
                return(false);
            }
            Vector3 p = quate * ui.data.localPosition;
            Vector3 o = Vector3.zero;

            o.x = p.x * scale.x;
            o.y = p.y * scale.y;
            o.z = p.z * scale.z;
            o  += pos;
            Vector3    s = ui.data.localScale;
            Quaternion q = quate * ui.data.localRotation;

            s.x *= scale.x;
            s.y *= scale.y;
            var callBack = ui.baseEvent;

            if (callBack == null)
            {
                var child = ui.child;
                for (int i = child.Count - 1; i >= 0; i--)
                {
                    if (DispatchEvent(child[i], o, s, q, action))
                    {
                        return(true);
                    }
                }
            }
            else if (callBack.forbid)
            {
                var child = ui.child;
                for (int i = child.Count - 1; i >= 0; i--)
                {
                    if (DispatchEvent(child[i], o, s, q, action))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                callBack.pgs            = scale;
                callBack.GlobalScale    = s;
                callBack.GlobalPosition = o;
                callBack.GlobalRotation = q;
                bool  inside = false;
                float w, h;
                if (callBack.UseAssignSize)
                {
                    w = callBack.boxSize.x * s.x;
                    h = callBack.boxSize.y * s.y;
                }
                else
                {
                    w = ui.data.sizeDelta.x * s.x;
                    h = ui.data.sizeDelta.y * s.y;
                }
                if (callBack.IsCircular)
                {
                    float x = action.CanPosition.x - o.x;
                    float y = action.CanPosition.y - o.y;
                    w *= 0.5f;
                    if (x * x + y * y < w * w)
                    {
                        inside = true;
                    }
                }
                else
                {
                    float px = ui.data.pivot.x;
                    float py = ui.data.pivot.y;
                    float lx = -px * w;
                    float rx = lx + w;
                    float dy = -py * h;
                    float ty = dy + h;

                    var v           = action.CanPosition;
                    var Rectangular = callBack.Rectangular;
                    Rectangular[0] = q * new Vector3(lx, dy) + o;
                    Rectangular[1] = q * new Vector3(lx, ty) + o;
                    Rectangular[2] = q * new Vector3(rx, ty) + o;
                    Rectangular[3] = q * new Vector3(rx, dy) + o;
                    inside         = Physics2D.DotToPolygon(Rectangular, v);
                }
                if (inside)
                {
                    action.CurrentEntry.Add(callBack);
                    var child = ui.child;
                    for (int i = child.Count - 1; i >= 0; i--)
                    {
                        if (DispatchEvent(child[i], o, s, q, action))
                        {
                            if (callBack.ForceEvent)
                            {
                                if (!callBack.forbid)
                                {
                                    break;
                                }
                            }
                            return(true);
                        }
                    }
                    if (action.IsLeftButtonDown | action.IsRightButtonDown | action.IsMiddleButtonDown)
                    {
                        callBack.OnMouseDown(action);
                    }
                    else if (action.IsLeftButtonUp | action.IsRightButtonUp | action.IsMiddleButtonUp)
                    {
                        callBack.OnMouseUp(action);
                    }
                    else
                    {
                        callBack.OnMouseMove(action);
                    }
                    if (callBack.Penetrate)
                    {
                        return(false);
                    }
                    return(true);
                }
                else if (!callBack.CutRect)
                {
                    var child = ui.child;
                    for (int i = child.Count - 1; i >= 0; i--)
                    {
                        if (DispatchEvent(child[i], o, s, q, action))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }