Exemple #1
0
        void RecalculateBoundingRect()
        {
            Rect mapsize = mapSize;
            // Get some world space projections at this zoom level
            // Temporarily move camera to final look position
            Vector3 prevCameraPos = transform.position;

            transform.position = CameraPosition;
            transform.LookAt(LookPosition);

            // Project screen corners and center
            var bottomLeftScreen = new Vector3(0, 0);
            var topLeftScreen    = new Vector3(0, Screen.height);
            var centerScreen     = new Vector3(Screen.width * 0.5f, Screen.height * 0.5f);

            Vector3 bottomLeftWorld = Vector3.zero;
            Vector3 topLeftWorld    = Vector3.zero;
            Vector3 centerWorld     = Vector3.zero;
            float   dist;

            Ray ray = CachedCamera.ScreenPointToRay(bottomLeftScreen);

            if (m_FloorPlane.Raycast(ray, out dist))
            {
                bottomLeftWorld = ray.GetPoint(dist);
            }

            ray = CachedCamera.ScreenPointToRay(topLeftScreen);
            if (m_FloorPlane.Raycast(ray, out dist))
            {
                topLeftWorld = ray.GetPoint(dist);
            }

            ray = CachedCamera.ScreenPointToRay(centerScreen);
            if (m_FloorPlane.Raycast(ray, out dist))
            {
                centerWorld = ray.GetPoint(dist);
            }

            Vector3 toTopLeft    = topLeftWorld - centerWorld;
            Vector3 toBottomLeft = bottomLeftWorld - centerWorld;

            LookBounds = new Rect(
                mapsize.xMin - toBottomLeft.x,
                mapsize.yMin - toBottomLeft.z,
                Mathf.Max(mapsize.width + (toBottomLeft.x * 2), 0),
                Mathf.Max((mapsize.height - toTopLeft.z) + toBottomLeft.z, 0));

            // Restore camera position
            transform.position = prevCameraPos;
            transform.LookAt(CurrentLookPosition);
        }
        public override Vector3 GetRaycastWorldPointOnTargetSurface(Vector2 screenPoint, Vector3?defaultValue)
        {
            Ray r = CachedCamera.ScreenPointToRay(screenPoint);

            Vector3 result = defaultValue.HasValue ? defaultValue.Value : Vector3.zero;

            float dist;

            if (groundPlane.Raycast(r, out dist))
            {
                result = r.GetPoint(dist);
            }
            return(result);
        }