예제 #1
0
    // When you press the "Save Level as..." button
    public void OnSaveLevelAsButtonPressed()
    {
        // Initializes SaveFileDialog with some values 
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "Level Save Files (*.sav)|*.sav";
        dialog.FileName = "newLevel.sav";
        dialog.RestoreDirectory = true;
        dialog.InitialDirectory = UnityEngine.Application.dataPath + "/Saved Levels";

        DialogResult result = dialog.ShowDialog();
        switch(result)
        { 
            case DialogResult.OK:
                LevelObjectEditor.current.DeselectObject();

                loadSaveUtility.SaveGame(dialog.FileName, Path.GetFileNameWithoutExtension(dialog.FileName));
                //Debug.Log("Save filed as: " + dialog.FileName);
                LevelSaveManager.RecordSave(dialog.FileName);

                YesNoDialog.current.CancelDialog();
            break;

            case DialogResult.Cancel:
                YesNoDialog.current.CloseDialog();
            break;
        }
    }
예제 #2
0
    private void LoadLevel()
    { 
        // Windows forms OpenFileDialog
        OpenFileDialog dialog = new OpenFileDialog();

        // Asks for .sav files only
        dialog.Filter = "Level Save Files (*.sav)|*.sav";
        dialog.RestoreDirectory = true;
        dialog.InitialDirectory = UnityEngine.Application.dataPath + "/Saved Levels";

        // Gets path from dialog
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            LevelObjectEditor.current.DeselectObject();

            string path = dialog.FileName;
            loadSaveUtility.LoadGame(path);

            LevelSaveManager.RecordSave(path);

            YesNoDialog.current.CancelDialog();
        }
        else
        {
            YesNoDialog.current.CloseDialog();
        }
    }
예제 #3
0
    // Creates a new level
    public void CreateNewLevel()
    {
        //HACK: We should only set the currentlevel while debugging the level editor, remove this line when building
        m_currentLevel = levelHolder.transform.GetComponentInChildren <Level>();

        // Destroys the old level first
        // The old level should already be saved by this point
        if (m_currentLevel != null)
        {
            foreach (Transform levelBlock in m_currentLevel.transform)
            {
                Destroy(levelBlock.gameObject);
            }
            Destroy(m_currentLevel.gameObject);
        }

        // Creates new Level and sets a parent to it
        GameObject levelObj = Instantiate(Resources.Load("Level Prefabs/Empty Level", typeof(Object)) as GameObject);

        m_currentLevel = levelObj.AddComponent <Level>();

        foreach (Transform child in levelObj.transform.GetAllChildren())
        {
            ObjectIdentifier objID = child.gameObject.AddComponent <ObjectIdentifier>();
            objID.prefabName        = child.name;
            objID.componentSaveMode = ObjectIdentifier.ComponentSaveMode.All;
        }

        levelObj.transform.SetParent(levelHolder.transform);
        // Resets the position of the level to be at 0,0,0 locally
        m_currentLevel.transform.localPosition = Vector3.zero;

        // Records that a new level has been created
        LevelSaveManager.RecordNewLevel();
    }
예제 #4
0
    // Handles Left mouse clicking inside of the editor view
    private void LeftMouseDown()
    {
        // Get the currently selected block
        currentBlock = LevelBlockSelect.current.GetCurrentBlock();

        Vector2 mouseInRect;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(m_RT, Input.mousePosition, canvasCamera, out mouseInRect);
        Ray mouseRay = levelCamera.ScreenPointToRay(mouseInRect);
        // Checks if the ray hit an object
        RaycastHit2D hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction);

        if (hit.collider != null)
        {
            currentObject = hit.collider.gameObject;
            LevelObjectEditor.current.ChangeSelection(currentObject);
        }
        // If we don't click on an object
        else
        {
            // Checks if we already have an object selected
            if (currentObject != null)
            {
                currentObject     = null;
                m_followingObject = false;
                LevelObjectEditor.current.DeselectObject();
                return;
            }

            // Checks if we can place a block prefab
            if (currentBlock == null)
            {
                return;
            }

            // Creates a plane which has a normal towards the camera and we place it on the level's position
            Plane rayPlane = new Plane(-levelCamera.transform.forward, m_currentLevel.transform.position);
            float enter;
            if (rayPlane.Raycast(mouseRay, out enter))
            {
                // Gets the position where the ray hit the point
                Vector3 spawnPos = mouseRay.GetPoint(enter);

                Object     blockPrefab = Resources.Load("Level Blocks/" + currentBlock, typeof(GameObject));
                GameObject newBlock    = Instantiate(blockPrefab, spawnPos, Quaternion.identity, m_currentLevel.transform) as GameObject;

                // Selects the object in the custom objecteditor
                LevelObjectEditor.current.ChangeSelection(newBlock);
                currentObject = newBlock;

                // Records that their has been a change in the level
                LevelSaveManager.RecordChange();
            }
        }
    }
예제 #5
0
    // When you press the "Save Level..." button
    public void OnSaveLevelButtonPressed()
    {
        // Checks if the level has a path already or if we need to set a location and name first
        if (!LevelSaveManager.loadedFromPath)
        {
            OnSaveLevelAsButtonPressed();
            return;
        }
        LevelObjectEditor.current.DeselectObject();

        string fileName = Path.GetFileNameWithoutExtension(LevelSaveManager.levelSaveFullPath);
        //Debug.Log("Full Path: " + LevelSaveManager.levelSaveFullPath + ", Filename only: " + fileName);
        loadSaveUtility.SaveGame(LevelSaveManager.levelSaveFullPath, fileName);
        LevelSaveManager.RecordSave(LevelSaveManager.levelSaveFullPath);

        YesNoDialog.current.CancelDialog();
    }
예제 #6
0
 private void Awake()
 {
     saveFilePath    = Application.persistentDataPath + "/game_data.json";
     currentInstance = this;
 }