Beispiel #1
0
        private Vector2 GetRndPosOutsideScreen(EScreenEdge screenEdge, float offsetFromEdge = 5.0f)
        {
            Vector3 screenBounds = cachedCamera.ViewportToWorldPoint(Vector2.one);
            float   posX         = 0.0f;
            float   posY         = 0.0f;

            switch (screenEdge)
            {
            case EScreenEdge.Top:
                posX = Random.Range(-screenBounds.x, screenBounds.x);
                posY = screenBounds.y + offsetFromEdge;
                break;

            case EScreenEdge.Right:
                posX = screenBounds.x + offsetFromEdge;
                posY = Random.Range(-screenBounds.y, screenBounds.y);
                break;

            case EScreenEdge.Bottom:
                posX = Random.Range(-screenBounds.x, screenBounds.x);
                posY = -screenBounds.y - offsetFromEdge;
                break;

            case EScreenEdge.Left:
                posX = -screenBounds.x - offsetFromEdge;
                posY = Random.Range(-screenBounds.y, screenBounds.y);
                break;
            }

            return(new Vector2(posX, posY));
        }
Beispiel #2
0
        public static Vector2 GetScreenEdge(EScreenEdge _edge, Camera _camera)
        {
            Vector2 result = new Vector2(0f, 0f);

            switch (_edge)
            {
            case EScreenEdge.RIGHT:
                result.x = _camera.aspect * _camera.orthographicSize;
                break;

            case EScreenEdge.TOP:
                result.y = _camera.orthographicSize;
                break;

            case EScreenEdge.BOTTOM:
                result.y = 0f - _camera.orthographicSize;
                break;

            case EScreenEdge.LEFT:
                result.x = (0f - _camera.orthographicSize) * _camera.aspect;
                break;
            }
            return(result);
        }
Beispiel #3
0
 public GameObject Spawn(PoolData pool, EScreenEdge screenEdge, float offsetFromScreenEdge = 5.0f)
 {
     return(PoolManager.Spawn(pool, GetRndPosOutsideScreen(screenEdge, offsetFromScreenEdge), Quaternion.identity));
 }
Beispiel #4
0
 public GameObject Spawn(GameObject prefab, EScreenEdge screenEdge, float offsetFromScreenEdge = 5.0f)
 {
     return(Instantiate(prefab, GetRndPosOutsideScreen(screenEdge, offsetFromScreenEdge), Quaternion.identity));
 }