Пример #1
0
        static bool DispatchEvent(RectTransform rt, Vector3 pos, Vector3 scale, Quaternion quate, UserAction action)
        {
            if (rt == null)
            {
                Debug.Log("null trans");
                return(false);
            }
            if (!rt.gameObject.activeSelf)
            {
                return(false);
            }
            Vector3 p = rt.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 = rt.localScale;
            Quaternion q = rt.localRotation * quate;

            s.x *= scale.x;
            s.y *= scale.y;
            EventCallBack callBack = container.Find((e) => { return(e.Target == rt); });

            if (callBack == null)
            {
                for (int i = rt.childCount - 1; i >= 0; i--)
                {
                    if (DispatchEvent(rt.GetChild(i) as RectTransform, o, s, q, action))
                    {
                        return(true);
                    }
                }
            }
            else if (callBack.forbid)
            {
                for (int i = rt.childCount - 1; i >= 0; i--)
                {
                    if (DispatchEvent(rt.GetChild(i) as RectTransform, o, s, q, action))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                callBack.pgs            = scale;
                callBack.GlobalScale    = s;
                callBack.GlobalPosition = o;
                callBack.GlobalRotation = q;
                bool  inside = false;
                float w      = rt.sizeDelta.x * s.x;
                float h      = rt.sizeDelta.y * s.y;
                if (callBack.UseAssignSize)
                {
                    w = callBack.boxSize.x * s.x;
                    h = callBack.boxSize.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 x1 = 0.5f * w;
                    float x0 = -x1;
                    float y1 = 0.5f * h;
                    float y0 = -y1;

                    var v           = action.CanPosition;
                    var Rectangular = callBack.Rectangular;
                    Rectangular[0] = q * new Vector3(x0, y0) + o;
                    Rectangular[1] = q * new Vector3(x0, y1) + o;
                    Rectangular[2] = q * new Vector3(x1, y1) + o;
                    Rectangular[3] = q * new Vector3(x1, y0) + o;
                    inside         = Physics2D.DotToPolygon(Rectangular, v);
                }
                if (inside)
                {
                    action.CurrentEntry.Add(callBack);
                    for (int i = rt.childCount - 1; i >= 0; i--)
                    {
                        if (DispatchEvent(rt.GetChild(i) as RectTransform, o, s, q, action))
                        {
                            if (callBack.ForceEvent)
                            {
                                if (!callBack.forbid)
                                {
                                    break;
                                }
                            }
                            return(true);
                        }
                    }
                    if (action.IsLeftButtonDown | action.IsRightButtonPressed | action.IsMiddleButtonPressed)
                    {
                        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)
                {
                    for (int i = rt.childCount - 1; i >= 0; i--)
                    {
                        if (DispatchEvent(rt.GetChild(i) as RectTransform, o, s, q, action))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Пример #2
0
 protected override void OnDrag(UserAction action)
 {
 }
Пример #3
0
 public static void ClearEvent()
 {
     container.Clear();
     UserAction.ClearAll();
     TextInputEvent.Reset();
 }
Пример #4
0
 protected override void OnMouseUp(UserAction action)
 {
 }