Exemplo n.º 1
0
        protected void InjectTouchEvent()
        {
            try
            {
                List <TouchEvent> events = TouchEventHandler.INSTANCE.GetTouchEvents();

                if (events != null)
                {
                    float offsetx = 0, offsety = 0, scalex = 0, scaley = 0;
                    if (CoordinateTool.GetCurrenScreenParam(ref offsetx, ref offsety, ref scalex, ref scaley))
                    {
                        for (int i = 0; i < events.Count; ++i)
                        {
                            events[i].x -= offsetx;
                            events[i].y -= offsety;
                        }
                    }
                    for (int i = 0; i < events.Count; ++i)
                    {
                        TouchEvent touchEvent = events[i];
                        AndroidRobot.INSTANCE.InjectMotionEvent(touchEvent.x, touchEvent.y, touchEvent.type);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Logger.w(ex.Message + "\n" + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        public Rectangle GetBound(GameObject obj)
        {
            if (obj == null)
            {
                return(null);
            }
            Rectangle rc = null;
            Camera    cm = FindBestCamera(obj);

            if (cm == null)
            {
                return(null);
            }

            rc = GetBoundByCollider(cm, obj);//主要是boxcolider2d物体的时候

            if (rc == null)
            {
                rc = NGUITools.GetNGUIBound(cm, obj);
            }

            if (rc == null)
            {
                rc = GetGUIBound(cm, obj);
            }

            if (rc == null)
            {
                return(null);
            }

            Logger.v("GetBound gameobject =" + obj.name + "  rc.x=" + rc.x + ", rc.y=" + rc.y + ", wight = " + rc.width + ", height=" + rc.height);

            //坐标缩放
            float offsetx = 0, offsety = 0, scalex = 0, scaley = 0;

            if (RuntimePlatform.IPhonePlayer == Application.platform)//ios默认返回归一化的值
            {
                rc.x      = rc.x / Screen.width;
                rc.y      = rc.y / Screen.height;
                rc.width  = rc.width / Screen.width;
                rc.height = rc.height / Screen.height;
            }
            else if (CoordinateTool.GetCurrenScreenParam(ref offsetx, ref offsety, ref scalex, ref scaley))
            {
                rc.x = rc.x * scalex + offsetx;
                rc.y = rc.y * scaley + offsety;

                rc.width  = rc.width * scalex;
                rc.height = rc.height * scaley;
            }
            Logger.v("GetBound() after scale : rc.x=" + rc.x + ", rc.y=" + rc.y + ", wight = " + rc.width + ", height=" + rc.height);

            return(rc);
        }