public static EventCallBack RegEvent(RectTransform rect, Type type)
        {
            if (rect == null)
            {
                return(null);
            }
            if (type == typeof(EventCallBack))
            {
            }
            else if (type.IsSubclassOf(typeof(EventCallBack)))
            {
            }
            else
            {
                return(null);
            }
            int index = container.FindIndex((o) => { return(o.Target == rect); });

            if (index > -1)
            {
                container.RemoveAt(index);
            }
            EventCallBack back = Activator.CreateInstance(type) as EventCallBack;

            back.Target = rect;
            container.Add(back);
            return(back);
        }
Beispiel #2
0
        public static void DispatchEvent()
        {
            DateTime now = DateTime.Now;

            Ticks = now.Ticks;
            int s = now.Millisecond;
            int t = s - LastTime;

            if (t < 0)
            {
                t += 1000;
            }
            TimeSlice = t;
            LastTime  = s;
            EventCallBack.Rolling();
            if (inputType == InputType.OnlyMouse)
            {
                DispatchMouse();
            }
            else if (inputType == InputType.OnlyTouch)
            {
                DispatchTouch();
            }
            else
            {
                DispatchWin();
            }
            TextInputEvent.Dispatch();
            GestureEvent.Dispatch(new List <UserAction>(inputs));
        }
 public static void Dispose()
 {
     EventCallBack.ClearEvent();
     ThreadMission.DisposeAll();
     RecordManager.ReleaseAll();
     ElementAsset.bundles.Clear();
     AssetBundle.UnloadAllAssetBundles(true);
 }
Beispiel #4
0
 public void RemoveFocus(EventCallBack callBack)
 {
     LastEntry.Remove(callBack);
     CurrentEntry.Remove(callBack);
     LastFocus.Remove(callBack);
     MultiFocus.Remove(callBack);
     callBack.Pressed = false;
 }
Beispiel #5
0
 void Dispatch()
 {
     if (IsLeftButtonDown | IsRightButtonPressed | IsMiddleButtonPressed)
     {
         List <EventCallBack> tmp = MultiFocus;
         LastFocus.Clear();
         MultiFocus = LastFocus;
         LastFocus  = tmp;
     }
     EventCallBack.DispatchEvent(this);
     if (IsLeftButtonDown | IsRightButtonPressed | IsMiddleButtonPressed)
     {
         for (int i = 0; i < LastFocus.Count; i++)
         {
             var f = LastFocus[i];
             for (int j = 0; j < MultiFocus.Count; j++)
             {
                 if (f == MultiFocus[j])
                 {
                     goto label2;
                 }
             }
             if (!f.Pressed)
             {
                 f.OnLostFocus(this);
             }
             label2 :;
         }
     }
     else if (IsLeftButtonUp | IsRightButtonUp | IsMiddleButtonUp)
     {
         for (int i = 0; i < MultiFocus.Count; i++)
         {
             var f = MultiFocus[i];
             f.Pressed = false;
             f.OnDragEnd(this);
         }
     }
     else
     {
         for (int i = 0; i < MultiFocus.Count; i++)
         {
             MultiFocus[i].OnFocusMove(this);
         }
     }
     if (IsMouseWheel)
     {
         for (int i = 0; i < MultiFocus.Count; i++)
         {
             var f = MultiFocus[i];
             if (f.MouseWheel != null)
             {
                 f.MouseWheel(f, this);
             }
         }
     }
     CheckMouseLeave();
 }
Beispiel #6
0
 static void SubThread(object obj)
 {
     EventCallBack.Rolling();
     RenderForm.DispatchAction();
     Resize();
     UIPage.Refresh(UserAction.TimeSlice);
     UINotify.Refresh(UserAction.TimeSlice);
     UIAnimation.Manage.Update();
 }
Beispiel #7
0
        static void OnDrag(EventCallBack back, UserAction action, Vector2 v)
        {
            var slider = back as SliderEvent;

            OnDrag(slider, action, v);
            ValueChanged(slider);
            if (slider.OnVlaueChanged != null)
            {
                slider.OnVlaueChanged(slider);
            }
        }
Beispiel #8
0
 public void AddFocus(EventCallBack eve)
 {
     if (MultiFocus.Contains(eve))
     {
         return;
     }
     MultiFocus.Add(eve);
     eve.Pressed = isPressed;
     if (eve.Pressed)
     {
         eve.pressTime = EventTicks;
     }
 }
 static void Reset(EventCallBack eventCall)
 {
     eventCall.PointerDown  = null;
     eventCall.PointerUp    = null;
     eventCall.Click        = null;
     eventCall.PointerEntry = null;
     eventCall.PointerMove  = null;
     eventCall.PointerLeave = null;
     eventCall.Drag         = null;
     eventCall.DragEnd      = null;
     eventCall.Scrolling    = null;
     eventCall.AutoColor    = true;
     eventCall.forbid       = false;
     eventCall.mVelocity    = Vector2.zero;
     eventCall.maxVelocity  = Vector2.zero;
     eventCall.CutRect      = false;
     eventCall.ForceEvent   = false;
     eventCall.Penetrate    = false;
 }
Beispiel #10
0
        static void OnClick(EventCallBack back, UserAction action)
        {
            SliderEvent slider = back as SliderEvent;

            if (slider.direction == Direction.Horizontal)
            {
                float x  = slider.GlobalPosition.x;
                float ox = action.CanPosition.x - x;
                float w  = back.Target.sizeDelta.x;
                float s  = w * slider.GlobalScale.x;
                slider.m_value = ox / s + 0.5f;
            }
            else
            {
                float y  = slider.GlobalPosition.y;
                float oy = action.CanPosition.y - y;
                float w  = back.Target.sizeDelta.y;
                float s  = w * slider.GlobalScale.y;
                slider.m_value = oy / s + 0.5f;
            }
            ValueChanged(slider);
        }
Beispiel #11
0
        public static void Initial(RectTransform uiRoot)
        {
            InitialUI();
            Initial();
            if (uiRoot == null)
            {
                var ui = new GameObject("UI", typeof(Canvas));
                ui.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
                UIRoot = new GameObject("uiRoot", typeof(RectTransform)).transform as RectTransform;
                UIRoot.SetParent(ui.transform);
                UIRoot.localPosition = Vector3.zero;

                Hint = new GameObject("Hint", typeof(RectTransform)).transform as RectTransform;
                Hint.SetParent(ui.transform);
                Hint.localPosition = Vector3.zero;
                Hint.SetAsLastSibling();
                //HintPage.root = Hint;
                //NotifyControll.root = Hint;
            }
            else
            {
                UIRoot = uiRoot;
            }
            var root = ModelElement.CreateNew("uiRoot");

            root.Context     = uiRoot as RectTransform;
            root.Main        = uiRoot.gameObject;
            UIPage.Root      = root;
            UIRoot.sizeDelta = new Vector2(Screen.width, Screen.height);

            var buff = new GameObject("buffer", typeof(Canvas));

            buff.SetActive(false);
            ModelManagerUI.CycleBuffer = buff.transform;
            EventCallBack.InsertRoot(UIRoot.root as RectTransform);
            ModelManager2D.Initial();
            Scale.NormalDpi = Screen.dpi;
        }
Beispiel #12
0
 public static void Dispose()
 {
     EventCallBack.ClearEvent();
     ThreadMission.DisposeAll();
     RecordManager.ReleaseAll();
 }
Beispiel #13
0
 public bool ExistFocus(EventCallBack eve)
 {
     return(MultiFocus.Contains(eve));
 }
        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);
        }
        static void DuringSlide(EventCallBack back)
        {
            if (back.mVelocity.x == 0 & back.mVelocity.y == 0)
            {
                return;
            }
            back.xTime += UserAction.TimeSlice;
            back.yTime += UserAction.TimeSlice;
            float x = 0, y = 0;
            bool  endx = false, endy = false;

            if (back.mVelocity.x != 0)
            {
                float t = (float)MathH.PowDistance(back.DecayRateX, back.maxVelocity.x, back.xTime);
                x          = t - back.lastX;
                back.lastX = t;
                float vx = Mathf.Pow(back.DecayRateX, back.xTime) * back.maxVelocity.x;
                if (vx <0.001f& vx> -0.001f)
                {
                    back.mVelocity.x = 0;
                    endx             = true;
                }
                else
                {
                    back.mVelocity.x = vx;
                }
            }
            if (back.mVelocity.y != 0)
            {
                float t = (float)MathH.PowDistance(back.DecayRateY, back.maxVelocity.y, back.yTime);
                y          = t - back.lastY;
                back.lastY = t;
                float vy = Mathf.Pow(back.DecayRateY, back.yTime) * back.maxVelocity.y;
                if (vy <0.001f& vy> -0.001f)
                {
                    back.mVelocity.y = 0;
                    endy             = true;
                }
                else
                {
                    back.mVelocity.y = vy;
                }
            }
            if (back.Scrolling != null)
            {
                back.Scrolling(back, new Vector2(x, y));
            }
            if (endx)
            {
                if (back.ScrollEndX != null)
                {
                    back.ScrollEndX(back);
                }
            }
            if (endy)
            {
                if (back.ScrollEndY != null)
                {
                    back.ScrollEndY(back);
                }
            }
        }