Exemplo n.º 1
0
    public void SaveGame(string saveSlotNumber)
    {
        // File name and path setup
        string fileName = "/saveFile" + saveSlotNumber + ".dat";
        string filePath = _persistentFilesPath + fileName;

        // If file already exits ...
        if (File.Exists(filePath))
        {
            // ... Prompt User ...
            // TODO: Modal Window - Return if canceled
        }
        FileStream file = File.Create(filePath);


        // Saved Data Initialization
        GameObject   player = GameObject.FindGameObjectWithTag("Player");
        SaveFileData data   = new SaveFileData
        {
            // TODO: Add Data to be saved
            sceneName          = SceneManager.GetActiveScene().name,
            characterPositionX = player.transform.position.x,
            characterPositionY = player.transform.position.y,
            characterPositionZ = player.transform.position.z,
            totalPlayTime      = Time.time - startTime - lastLoadTime + gameplayTime
        };

        // Write File
        BinaryFormatter bf = new BinaryFormatter();

        bf.Serialize(file, data);
        file.Close();

        Debug.Log("Game Saved Successfully!");
        Debug.Log("File Stored in path: " + filePath);
    }
Exemplo n.º 2
0
 // Token: 0x06000757 RID: 1879 RVA: 0x0006F390 File Offset: 0x0006D790
 private SaveFile(SaveFileData data, int index)
 {
     this.data  = data;
     this.index = index;
 }
Exemplo n.º 3
0
 public void AddFile(SaveFileData fileData)
 {
     fileData.Selected = true;
     bindingFiles.Add(fileData);
 }
Exemplo n.º 4
0
    private bool OpenFile(string projectPath)
    {
        data = SaveFile.OpenFile(projectPath);

        openVideo = Path.Combine(Application.persistentDataPath, Path.Combine(data.meta.guid.ToString(), SaveFile.videoFilename));
        fileLoader.LoadFile(openVideo);

        var tagsPath = Path.Combine(Application.persistentDataPath, data.meta.guid.ToString());
        var tags     = SaveFile.ReadTags(tagsPath);

        TagManager.Instance.SetTags(tags);

        var chaptersPath = Path.Combine(Application.persistentDataPath, data.meta.guid.ToString());
        var chapters     = SaveFile.ReadChapters(chaptersPath);

        ChapterManager.Instance.SetChapters(chapters);

        //NOTE(Simon): Sort all interactionpoints based on their timing
        data.points.Sort((x, y) => x.startTime != y.startTime
                                                                                ? x.startTime.CompareTo(y.startTime)
                                                                                : x.endTime.CompareTo(y.endTime));

        foreach (var point in data.points)
        {
            var newPoint = Instantiate(interactionPointPrefab);

            var newInteractionPoint = new InteractionPointPlayer
            {
                startTime          = point.startTime,
                endTime            = point.endTime,
                title              = point.title,
                body               = point.body,
                filename           = point.filename,
                type               = point.type,
                point              = newPoint,
                tagId              = point.tagId,
                mandatory          = point.mandatory,
                returnRayOrigin    = point.returnRayOrigin,
                returnRayDirection = point.returnRayDirection
            };

            bool isValidPoint = true;

            switch (newInteractionPoint.type)
            {
            case InteractionType.None:
            {
                isValidPoint = false;
                Debug.Log("InteractionPoint with Type None encountered");
                break;
            }

            case InteractionType.Text:
            {
                var panel = Instantiate(textPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                panel.GetComponent <TextPanel>().Init(newInteractionPoint.title, newInteractionPoint.body);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.Image:
            {
                var panel     = Instantiate(imagePanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                var filenames = newInteractionPoint.filename.Split('\f');
                var urls      = new List <string>();
                foreach (var file in filenames)
                {
                    string url = Path.Combine(Application.persistentDataPath, Path.Combine(data.meta.guid.ToString(), file));
                    urls.Add(url);
                }
                panel.GetComponent <ImagePanel>().Init(newInteractionPoint.title, urls);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.Video:
            {
                var    panel = Instantiate(videoPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                string url   = Path.Combine(Application.persistentDataPath, data.meta.guid.ToString(), newInteractionPoint.filename);
                panel.GetComponent <VideoPanel>().Init(newInteractionPoint.title, url);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.MultipleChoice:
            {
                var split   = newInteractionPoint.body.Split(new[] { '\f' }, 2);
                int correct = Int32.Parse(split[0]);
                var panel   = Instantiate(multipleChoicePrefab, Canvass.sphereUIPanelWrapper.transform);
                panel.GetComponent <MultipleChoicePanelSphere>().Init(newInteractionPoint.title, correct, split[1].Split('\f'));
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.Audio:
            {
                var    panel = Instantiate(audioPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                string url   = Path.Combine(Application.persistentDataPath, data.meta.guid.ToString(), newInteractionPoint.filename);
                panel.GetComponent <AudioPanel>().Init(newInteractionPoint.title, url);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.FindArea:
            {
                var panel = Instantiate(findAreaPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                var areas = Area.ParseFromSave(newInteractionPoint.filename, newInteractionPoint.body);

                panel.GetComponent <FindAreaPanelSphere>().Init(newInteractionPoint.title, areas);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.MultipleChoiceArea:
            {
                var    split    = newInteractionPoint.body.Split(new[] { '\f' }, 2);
                int    correct  = Int32.Parse(split[0]);
                string areaJson = split[1];
                var    panel    = Instantiate(multipleChoiceAreaPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                var    areas    = Area.ParseFromSave(newInteractionPoint.filename, areaJson);

                panel.GetComponent <MultipleChoiceAreaPanelSphere>().Init(newInteractionPoint.title, areas, correct);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.MultipleChoiceImage:
            {
                var panel     = Instantiate(multipleChoiceImagePanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                var filenames = newInteractionPoint.filename.Split('\f');
                int correct   = Int32.Parse(newInteractionPoint.body);
                var urls      = new List <string>();
                foreach (string file in filenames)
                {
                    string url = Path.Combine(Application.persistentDataPath, Path.Combine(data.meta.guid.ToString(), file));
                    urls.Add(url);
                }
                panel.GetComponent <MultipleChoiceImagePanelSphere>().Init(newInteractionPoint.title, urls, correct);
                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.TabularData:
            {
                var      panel   = Instantiate(tabularDataPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                string[] body    = newInteractionPoint.body.Split(new[] { '\f' }, 3);
                int      rows    = Int32.Parse(body[0]);
                int      columns = Int32.Parse(body[1]);

                panel.GetComponent <TabularDataPanelSphere>().Init(newInteractionPoint.title, rows, columns, body[2].Split('\f'));

                newInteractionPoint.panel = panel;
                break;
            }

            case InteractionType.Chapter:
            {
                var panel     = Instantiate(chapterPanelPrefab, Canvass.sphereUIPanelWrapper.transform);
                int chapterId = Int32.Parse(newInteractionPoint.body);
                panel.GetComponent <ChapterPanelSphere>().Init(newInteractionPoint.title, chapterId, this);
                newInteractionPoint.panel = panel;
                break;
            }

            default:
            {
                isValidPoint = false;
                Debug.LogError("Invalid interactionPoint encountered");
                break;
            }
            }

            if (isValidPoint)
            {
                if (newInteractionPoint.mandatory)
                {
                    mandatoryInteractionPoints.Add(newInteractionPoint);
                }

                AddInteractionPoint(newInteractionPoint);
            }
            else
            {
                Destroy(newPoint);
            }
        }

        //NOTE(Simon): For mandatoryInteractionPoints it makes more sense to sort by endTime
        mandatoryInteractionPoints.Sort((x, y) => x.endTime.CompareTo(y.endTime));

        StartCoroutine(UpdatePointPositions());

        if (VRDevices.loadedSdk == VRDevices.LoadedSdk.None)
        {
            Seekbar.instance.compass.SetActive(true);
        }
        else
        {
            Seekbar.instanceVR.compass.SetActive(true);
        }

        return(true);
    }
Exemplo n.º 5
0
    public void Save()
    {
        if (!FinishedSaving.ContainsKey(gameObject))
        {
            FinishedSaving.Add(gameObject, false);
        }
        FinishedSaving[gameObject] = false;
        List <GameObject> Keys = new List <GameObject>(FinishedSaving.Keys);

        foreach (GameObject key in Keys)
        {
            FinishedSaving[key] = false;
        }
        SaveScreenScript.SaveScreen.SetActive(true);
        if (!Directory.Exists(Application.persistentDataPath + "/" + CurrentSaveFile.ToString()))
        {
            Directory.CreateDirectory(Application.persistentDataPath + "/" + CurrentSaveFile.ToString());
        }
        if (StartSave != null)
        {
            StartSave();
        }


        GameObject[]  Players     = GameObject.FindGameObjectsWithTag("Player");
        List <string> PlayerNames = new List <string>();

        foreach (GameObject player in Players)
        {
            if (player.activeInHierarchy)
            {
                PlayerNames.Add(player.name);
            }
        }

        Debug.Log("StartSave");
        BinaryFormatter bf       = new BinaryFormatter();
        FileStream      file     = File.Create(Application.persistentDataPath + "/" + CurrentSaveFile.ToString() + "/SaveFile.dat");
        FileStream      nameFile = File.Create(Application.persistentDataPath + "/" + CurrentSaveFile.ToString() + "name.tic");

        bf.Serialize(nameFile, saveName);

        GameObject cam  = CameraScript.GameController.gameObject;
        Vector3    cPos = CameraScript.GameController.transform.position;

        SaveFileData mySaveData = new SaveFileData()
        {
            orthoSize = cam.GetComponent <Camera>().orthographicSize,

            cameraPosition = new float[3] {
                cPos.x, cPos.y, cPos.z
            },

            ActiveDungeon = DungeonScript.CurrentDungeon.DungeonName,

            CurrentLivingCharacters = PlayerNames.ToArray()
        };

        bf.Serialize(file, mySaveData);
        file.Close();
        Debug.Log("FinishedSave");
        FinishedSaving[gameObject] = true;
    }
Exemplo n.º 6
0
 public static void SetSFD(SaveFileData sfd)
 {
     Console.WriteLine("Received savefile data for game " + sfd.partial_name + " with length of " + sfd.tcontext.Length);
     m_sfd = sfd;
 }
Exemplo n.º 7
0
 public SaveFile(int index)
 {
     this.data  = new SaveFileData();
     this.index = index;
 }
Exemplo n.º 8
0
    /*
     * public static List<string> GetExtraFiles(string metaFileName)
     * {
     *      var str = GetSaveFileContents(metaFileName);
     * }
     */
    public static SaveFileData OpenFile(string path)
    {
        var str = GetSaveFileContents(path);

        var level  = 0;
        var start  = 0;
        var count  = 0;
        var rising = true;

        var saveFileData = new SaveFileData();

        var result = new ParsedJsonLine();

        result = JsonGetValueFromLine(str, result.endindex);
        saveFileData.meta.guid = new Guid(result.value);

        result = JsonGetValueFromLine(str, result.endindex);
        saveFileData.meta.title = result.value;

        result = JsonGetValueFromLine(str, result.endindex);
        saveFileData.meta.description = result.value;

        result = JsonGetValueFromLine(str, result.endindex);
        saveFileData.meta.perspective = (Perspective)Enum.Parse(typeof(Perspective), result.value);

        //Note(Simon): Value "length" is only used server side, but we still need to skip over the text in the file.
        result = JsonGetValueFromLine(str, result.endindex);

        var stringObjects = new List <string>();

        for (var i = result.endindex; i < str.Length; i++)
        {
            if (str[i] == '{')
            {
                if (level == 0)
                {
                    start = i;
                }
                rising = true;
                level++;
            }
            if (str[i] == '}')
            {
                level--;
                rising = false;
            }

            count++;

            if (level == 0 && !rising)
            {
                stringObjects.Add(str.Substring(start, count - 1));
                count  = 0;
                rising = true;
            }
            if (level < 0)
            {
                Debug.Log("Corrupted save file. Aborting");
                return(null);
            }
        }


        saveFileData.points = new List <InteractionpointSerialize>();

        foreach (var obj in stringObjects)
        {
            saveFileData.points.Add(JsonUtility.FromJson <InteractionpointSerialize>(obj));
        }

        return(saveFileData);
    }