public static void switchScene(Vector2 dir, bool clearDoorLabel = false)
    {
        GameObject player = gameManager.Instance.player;

        AtlasScene fromScene = getScene();

        AtlasScene toScene = getNeighborWithCoords(getPlayerCoords() + dir);

        if (toScene == null || toScene.scene == "null")
        {
            return;
        }

        Vector2 d = (toScene.size + fromScene.size) * 0.5f;
        Vector2 t = (fromScene.getCenter() - toScene.getCenter()) * -SCREEN_HEIGHT;

        float startx = 0;
        float starty = 0;

        if (dir.x != 0)
        {
            startx = (toScene.size.x * SCREEN_WIDTH * 0.5f - 0.3f) * -dir.x;
            starty = player.transform.position.y + t.y;
        }
        else
        {
            startx = player.transform.position.x + t.x;
            starty = (toScene.size.y * SCREEN_HEIGHT * 0.5f - 0.4f) * dir.y;
        }
        if (clearDoorLabel)
        {
            gameManager.Instance.currentDoorLabel = "none";
        }
        gameManager.Instance.switchScene(toScene.scene, startx, starty);
    }
    public static List <AtlasScene> getNeighbors(string sceneName = null)
    {
        if (sceneName == null)
        {
            sceneName = SceneManager.GetActiveScene().name;
        }
        AtlasSceneData sceneData    = getSceneData();
        AtlasScene     currentScene = getScene();

        if (currentScene == null)
        {
            throw new Exception("Cannot get neighbors for scene: " + sceneName);
        }

        List <AtlasScene> neighbors = new List <AtlasScene>();

        for (int x = 0; x < currentScene.size.x; x++)
        {
            neighbors.Add(findSceneByCoords(currentScene.position + new Vector2(x, -1)));
            neighbors.Add(findSceneByCoords(currentScene.position + new Vector2(x, currentScene.size.y)));
        }
        for (int y = 0; y < currentScene.size.y; y++)
        {
            neighbors.Add(findSceneByCoords(currentScene.position + new Vector2(-1, y)));
            neighbors.Add(findSceneByCoords(currentScene.position + new Vector2(currentScene.size.x, y)));
        }

        return(neighbors);
    }
    public static AtlasScene findSceneByCoords(Vector2 sceneCoords)
    {
        AtlasSceneData sceneData = getSceneData();
        AtlasScene     rtnScene  = sceneData.scenes.Find(s => { return
                                                                (sceneCoords.x < s.position.x + s.size.x &&
                                                                 sceneCoords.x >= s.position.x &&
                                                                 sceneCoords.y < s.position.y + s.size.y &&
                                                                 sceneCoords.y >= s.position.y); });

        if (rtnScene == null)
        {
            rtnScene = new AtlasScene();
        }
        return(rtnScene);
    }
    public static Vector2 getSceneCoords(string sceneName = null)
    {
        if (sceneName == null)
        {
            sceneName = SceneManager.GetActiveScene().name;
        }
        AtlasSceneData sceneData = getSceneData();
        AtlasScene     scene     = sceneData.scenes.Find(s => s.scene == sceneName);

        if (scene != null)
        {
            return(new Vector2(scene.position.x, scene.position.y));
        }
        return(new Vector2(-1, -1));
    }
Ejemplo n.º 5
0
    static void loadScene()
    {
        List <AtlasScene> neighbors    = AtlasSceneManager.getNeighbors();
        AtlasScene        currentScene = AtlasSceneManager.getScene();

        foreach (AtlasScene n in neighbors)
        {
            if (n.scene != "null")
            {
                EditorSceneManager.OpenScene("Assets/Scenes/WorldMap/" + n.scene + ".unity", OpenSceneMode.Additive);
                Vector2 d = (n.size + currentScene.size) * 0.5f;
                Vector2 t = (n.getCenter() - currentScene.getCenter());
                shiftScene(n.scene, t.x, -t.y);
            }
        }
    }
    public static AtlasScene getScene(string sceneName = null)
    {
        if (sceneName == null)
        {
            sceneName = SceneManager.GetActiveScene().name;
        }
        if (sceneName == "Main Menu")
        {
            return(new AtlasScene());
        }
        AtlasSceneData sceneData    = getSceneData();
        AtlasScene     currentScene = sceneData.scenes.Find(s => s.scene == sceneName);

        if (currentScene == null)
        {
            throw new Exception("No Scene data found for scene: " + sceneName);
        }
        return(currentScene);
    }
    public static Vector2 getPlayerCoords()
    {
        Vector2 playerCoords = Vector2.zero;
        Vector2 player       = gameManager.Instance.player.transform.position;

        AtlasScene scene      = getScene();
        Vector2    bottomLeft = -scene.getExtents(true);

        player.x = Mathf.Clamp(player.x, bottomLeft.x, bottomLeft.x + scene.size.x * SCREEN_WIDTH);
        player.y = Mathf.Clamp(player.y, bottomLeft.y, bottomLeft.y + scene.size.y * SCREEN_HEIGHT);

        Vector2 d     = player - bottomLeft;
        Vector2 normd = new Vector2(
            (int)Mathf.Clamp(d.x / SCREEN_WIDTH, 0, scene.size.x - 1),
            (int)Mathf.Clamp(d.y / SCREEN_HEIGHT, 0, scene.size.y - 1));

        playerCoords.x = normd.x + scene.position.x;
        playerCoords.y = scene.size.y - 1 - normd.y + scene.position.y;

        return(playerCoords);
    }