GetRenderCamera() public method

public GetRenderCamera ( ) : Camera
return UnityEngine.Camera
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <param name="localPoint"></param>
        /// <returns></returns>
        public virtual bool HitTest(Container container, ref Vector2 localPoint)
        {
            Camera camera = container.GetRenderCamera();
            RaycastHit hit;
            if (!HitTestContext.GetRaycastHitFromCache(camera, out hit))
                return false;

            if (hit.collider != collider)
                return false;

            localPoint = container.GetHitTestLocalPoint();
            return true;
        }
Example #2
0
 static public int GetRenderCamera(IntPtr l)
 {
     try {
         FairyGUI.Container self = (FairyGUI.Container)checkSelf(l);
         var ret = self.GetRenderCamera();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #3
0
 static int GetRenderCamera(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         FairyGUI.Container obj = (FairyGUI.Container)ToLua.CheckObject <FairyGUI.Container>(L, 1);
         UnityEngine.Camera o   = obj.GetRenderCamera();
         ToLua.PushSealed(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #4
0
        public override bool HitTest(Container container, ref Vector2 localPoint)
        {
            Camera camera = container.GetRenderCamera();

            RaycastHit hit;
            if (!HitTestContext.GetRaycastHitFromCache(camera, out hit))
                return false;

            if (hit.collider != collider)
                return false;

            localPoint = new Vector2(hit.textureCoord.x * this.width, (1 - hit.textureCoord.y) * this.height);
            HitTestContext.direction = Vector3.back;
            HitTestContext.worldPoint = StageCamera.main.ScreenToWorldPoint(new Vector2(localPoint.x, Screen.height - localPoint.y));

            return true;
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="container"></param>
        /// <param name="localPoint"></param>
        /// <returns></returns>
        virtual public bool HitTest(Container container, ref Vector2 localPoint)
        {
            Camera     camera = container.GetRenderCamera();
            RaycastHit hit;

            if (!HitTestContext.GetRaycastHitFromCache(camera, out hit))
            {
                return(false);
            }

            if (hit.collider != collider)
            {
                return(false);
            }

            localPoint = container.GetHitTestLocalPoint();
            return(true);
        }
Example #6
0
        /// <summary>
        /// 将舞台坐标转换为本地坐标
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public Vector2 GlobalToLocal(Vector2 point)
        {
            Container wsc = this.worldSpaceContainer;

            if (wsc != null)//I am in a world space
            {
                Camera  cam = wsc.GetRenderCamera();
                Vector3 worldPoint;
                Vector3 direction;
                Vector3 screenPoint = new Vector3();
                screenPoint.x = point.x;
                screenPoint.y = Screen.height - point.y;

                if (wsc.hitArea is MeshColliderHitTest)
                {
                    Ray        ray = cam.ScreenPointToRay(screenPoint);
                    RaycastHit hit;
                    if (((MeshColliderHitTest)wsc.hitArea).collider.Raycast(ray, out hit, 100))
                    {
                        point      = new Vector2(hit.textureCoord.x * _contentRect.width, (1 - hit.textureCoord.y) * _contentRect.height);
                        worldPoint = Stage.inst.cachedTransform.TransformPoint(point.x, -point.y, 0);
                        direction  = Vector3.back;
                    }
                    else //当射线没有击中模型时,无法确定本地坐标
                    {
                        return(new Vector2(float.NaN, float.NaN));
                    }
                }
                else
                {
                    screenPoint.z = cam.WorldToScreenPoint(this.cachedTransform.position).z;
                    worldPoint    = cam.ScreenToWorldPoint(screenPoint);
                    Ray ray = cam.ScreenPointToRay(screenPoint);
                    direction = Vector3.zero - ray.direction;
                }

                return(this.WorldToLocal(worldPoint, direction));
            }
            else //I am in stage space
            {
                Vector3 worldPoint = Stage.inst.cachedTransform.TransformPoint(point.x, -point.y, 0);
                return(this.WorldToLocal(worldPoint, Vector3.back));
            }
        }
Example #7
0
        /// <summary>
        /// 将舞台坐标转换为本地坐标
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public Vector2 GlobalToLocal(Vector2 point)
        {
            Container wsc = this.worldSpaceContainer;

            if (wsc != null)            //I am in a world space
            {
                Camera  cam = wsc.GetRenderCamera();
                Vector3 worldPoint;
                Vector3 direction;
                Vector3 screenPoint = new Vector3();
                screenPoint.x = point.x;
                screenPoint.y = Screen.height - point.y;

                if (wsc.hitArea is MeshColliderHitTest)
                {
                    if (((MeshColliderHitTest)wsc.hitArea).ScreenToLocal(cam, screenPoint, ref point))
                    {
                        worldPoint = Stage.inst.cachedTransform.TransformPoint(point.x, -point.y, 0);
                        direction  = Vector3.back;
                    }
                    else
                    {
                        return(new Vector2(float.NaN, float.NaN));
                    }
                }
                else
                {
                    screenPoint.z = cam.WorldToScreenPoint(this.cachedTransform.position).z;
                    worldPoint    = cam.ScreenToWorldPoint(screenPoint);
                    Ray ray = cam.ScreenPointToRay(screenPoint);
                    direction = Vector3.zero - ray.direction;
                }

                return(this.WorldToLocal(worldPoint, direction));
            }
            else             //I am in stage space
            {
                Vector3 worldPoint = Stage.inst.cachedTransform.TransformPoint(point.x, -point.y, 0);
                return(this.WorldToLocal(worldPoint, Vector3.back));
            }
        }
        override public bool HitTest(Container container, ref Vector2 localPoint)
        {
            Camera camera = container.GetRenderCamera();

            RaycastHit hit;

            if (!HitTestContext.GetRaycastHitFromCache(camera, out hit))
            {
                return(false);
            }

            if (hit.collider != collider)
            {
                return(false);
            }

            localPoint = new Vector2(hit.textureCoord.x * this.width, (1 - hit.textureCoord.y) * this.height);
            HitTestContext.direction  = Vector3.back;
            HitTestContext.worldPoint = StageCamera.main.ScreenToWorldPoint(new Vector2(localPoint.x, Screen.height - localPoint.y));

            return(true);
        }
Example #9
0
        /// <summary>
        /// 将本地坐标转换为舞台坐标
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public Vector2 LocalToGlobal(Vector2 point)
        {
            Container wsc = this.worldSpaceContainer;

            Vector3 worldPoint = this.cachedTransform.TransformPoint(point.x, -point.y, 0);

            if (wsc != null)
            {
                if (wsc.hitArea is MeshColliderHitTest)                 //Not supported for UIPainter, use TransfromPoint instead.
                {
                    return(new Vector2(float.NaN, float.NaN));
                }

                Vector3 screePoint = wsc.GetRenderCamera().WorldToScreenPoint(worldPoint);
                return(new Vector2(screePoint.x, Stage.inst.stageHeight - screePoint.y));
            }
            else
            {
                point   = Stage.inst.cachedTransform.InverseTransformPoint(worldPoint);
                point.y = -point.y;
                return(point);
            }
        }