void checkRoomBoundaries()
    {
        GameObject roomBounds = GameObject.FindGameObjectWithTag("RoomBounds");

        if (roomBounds == null)
        {
            throw new System.Exception("No RoomBounds in Scene: " + SceneManager.GetActiveScene().name);
        }

        Bounds bounds = roomBounds.GetComponent <BoxCollider2D>().bounds;

        AtlasSceneManager.getPlayerCoords();
        //UP
        if (transform.position.y + boxCollider.size.y / 2.0f > bounds.max.y)
        {
            AtlasSceneManager.switchScene(-Vector2.up, true);
        }
        //LEFT
        if (transform.position.x - boxCollider.size.x / 2.0f < bounds.min.x)
        {
            AtlasSceneManager.switchScene(-Vector2.right, true);
        }
        //RIGHT
        if (transform.position.x + boxCollider.size.x / 2.0f > bounds.max.x)
        {
            AtlasSceneManager.switchScene(Vector2.right, true);
        }
        //DOWN
        if (transform.position.y - boxCollider.size.y / 2.0f < bounds.min.y)
        {
            AtlasSceneManager.switchScene(Vector2.up, true);
        }
    }
 public static void displayNeighbors()
 {
     AtlasSceneManager.getSceneData();
     AtlasSceneManager.getNeighbors();
     loadScene();
     displayingNeighbors = true;
 }
 private static void Init()
 {
     instance = Resources.LoadAll <AtlasSceneManager>("Managers")[0];
     SceneManager.sceneLoaded += instance.OnSceneLoaded;
     instance.OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
     getSceneData();
 }
    public Vector2 getExtents(bool abs = false)
    {
        Vector2 extents = size * 0.5f;

        if (abs)
        {
            extents.Scale(AtlasSceneManager.getScreenSize());
        }
        return(extents);
    }
    public Vector2 getCenter(bool abs = false)
    {
        Vector2 center = position + size * 0.5f;

        if (abs)
        {
            center.Scale(AtlasSceneManager.getScreenSize());
        }
        return(center);
    }
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();

        scrollpos = EditorGUILayout.BeginScrollView(scrollpos, GUIStyle.none, GUI.skin.verticalScrollbar);
        List <SceneAsset> m_SceneAssets = new List <SceneAsset>();
        string            folderName    = Application.dataPath + "/Scenes/WorldMap/";
        var dirInfo      = new DirectoryInfo(folderName);
        var allFileInfos = dirInfo.GetFiles("*.unity", SearchOption.AllDirectories);

        foreach (var fileInfo in allFileInfos)
        {
            SceneAsset sa = AssetDatabase.LoadAssetAtPath <SceneAsset>("Assets/Scenes/WorldMap/" + fileInfo.Name);
            m_SceneAssets.Add(sa);
        }

        foreach (var sa in m_SceneAssets)
        {
            sceneAsset = EditorGUILayout.ObjectField("", sa, typeof(SceneAsset), true) as SceneAsset;
        }
        EditorGUILayout.EndScrollView();

        EditorGUILayout.BeginVertical();
        if (GUILayout.Button("Take Screenshot"))
        {
            ScreenshotEditor.takeScreenshot();
            GUIUtility.ExitGUI();
        }
        if (GUILayout.Button("Add Scenes to Build"))
        {
            AddAllWorldScenes();
            GUIUtility.ExitGUI();
        }
        if (GUILayout.Button("Update Scene Data"))
        {
            AtlasSceneManager.getSceneData();
        }
        if (GUILayout.Button("Toggle Neighbors"))
        {
            MapEditor.toggleNeighbors();
            GUIUtility.ExitGUI();
        }
        if (GUILayout.Button("Open Map Editor"))
        {
            Object mapEditor = AssetDatabase.LoadAssetAtPath("Assets/Scenes/MapEditor.lnk", typeof(Object));
            AssetDatabase.OpenAsset(mapEditor);
            GUIUtility.ExitGUI();
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
    }
    private void Start()
    {
        anim     = GetComponent <Animator>();
        deformer = GetComponent <Deformer>();
        col      = GetComponent <BoxCollider2D>();

        Vector2 scenePos = AtlasSceneManager.getPlayerCoords();

        if (scenePos.x >= 6 && scenePos.x <= 12 && scenePos.y >= -1 && scenePos.y <= 4)
        {
            setDry();
        }

        AtlasEventManager.Instance.onFlagSet += setDry;
    }
    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 void updateSceneData()
 {
     AtlasSceneManager.getSceneData();
 }
Beispiel #10
0
    public void TakeScreenshot()
    {
        string dir      = "Assets/../MapEditor/screenshots/";
        string filename = AtlasSceneManager.getScene().scene + ".png";
        string path     = dir + filename;

        Camera cam = GetComponent <Camera>();

        // Create Render Texture with width and height.
        RenderTexture rt = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32);

        // Assign Render Texture to camera.
        cam.targetTexture = rt;

        // save current background settings of the camera
        CameraClearFlags clearFlags      = cam.clearFlags;
        Color            backgroundColor = cam.backgroundColor;

        // make the background transparent when enabled
        if (ensureTransparentBackground)
        {
            cam.clearFlags      = CameraClearFlags.SolidColor;
            cam.backgroundColor = new Color(); // alpha is zero
        }

        // Render the camera's view to the Target Texture.
        cam.Render();

        // restore the camera's background settings if they were changed before rendering
        if (ensureTransparentBackground)
        {
            cam.clearFlags      = clearFlags;
            cam.backgroundColor = backgroundColor;
        }

        // Save the currently active Render Texture so we can override it.
        RenderTexture currentRT = RenderTexture.active;

        // ReadPixels reads from the active Render Texture.
        RenderTexture.active = cam.targetTexture;

        // Make a new texture and read the active Render Texture into it.
        Texture2D screenshot = new Texture2D(width, height, TextureFormat.ARGB32, false);

        screenshot.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);

        // PNGs should be sRGB so convert to sRGB color space when rendering in linear.
        if (QualitySettings.activeColorSpace == ColorSpace.Linear)
        {
            Color[] pixels = screenshot.GetPixels();
            for (int p = 0; p < pixels.Length; p++)
            {
                pixels[p] = pixels[p].gamma;
            }
            screenshot.SetPixels(pixels);
        }

        // Apply the changes to the screenshot texture.
        screenshot.Apply(false);

        // Save the screnshot.
        Directory.CreateDirectory(dir);
        byte[] png = screenshot.EncodeToPNG();
        File.WriteAllBytes(path, png);

        // Remove the reference to the Target Texture so our Render Texture is garbage collected.
        cam.targetTexture = null;

        // Replace the original active Render Texture.
        RenderTexture.active = currentRT;

        Debug.Log("Screenshot saved to:\n" + path);
    }