Page 1 of 1

[HOWTO] How To: Integrate with Horror FPS Kit

Posted: Thu Dec 05, 2019 12:01 pm
by Tony Li
To use the Dialogue System with Horror FPS Kit, add this script to the Dialogue Manager:

SaveDS.cs

Code: Select all

using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using UnityEngine;

public class SaveDS : MonoBehaviour, ISaveable
{
    public void OnLoad(JToken token)
    {
        string data = token["dialoguesystem"].ToObject<string>();
        if (string.IsNullOrEmpty(data))
        {
            PixelCrushers.DialogueSystem.DialogueManager.ResetDatabase();
        }
        else
        {
            PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData(data);
        }
    }
    
    public Dictionary<string, object> OnSave()
    {
        return new Dictionary<string, object>()
        {
            { "dialoguesystem", PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData() }
        };
    }
}
You may want to use a Dialogue System Events component to disable the player's movement and camera control during conversations. See the second half of the Interaction Tutorial for instructions on that.

Re: How To: Integrate with Horror FPS Kit

Posted: Thu Dec 05, 2019 8:36 pm
by Tony Li
The method above saves only the Dialogue System's dialogue database data. If you want to include the entire save system, add the script below instead.

Then add these 4 additional scripts to the Dialogue Manager:

1. SaveSystem
2. JsonDataSerializer
3. PlayerPrefsSavedGameDataStorer (this one is not used, but it quiets a warning message)
4. DialogueSystemSaver

Then inspect the SaveSystem component and untick Save Current Scene.

SavePixelCrushers.cs

Code: Select all

using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using UnityEngine;

public class SavePixelCrushers : MonoBehaviour, ISaveable
{
    public void OnLoad(JToken token)
    {
        string data = token["dialoguesystem"].ToObject<string>();
        if (string.IsNullOrEmpty(data))
        {
            PixelCrushers.SaveSystem.RestartGame("");
        }
        else
        {
            PixelCrushers.SaveSystem.LoadGame(PixelCrushers.SaveSystem.Deserialize<PixelCrushers.SavedGameData>(data));
        }
    }
    
    public Dictionary<string, object> OnSave()
    {
        return new Dictionary<string, object>()
        {
            { "dialoguesystem", PixelCrushers.SaveSystem.Serialize(PixelCrushers.SaveSystem.RecordSavedGameData()) }
        };
    }
}
You can also use this script if you're using Quest Machine, since they use the same save system. In this case, if you're not also using the Dialogue System skip step 4 (add Dialogue System Saver). On your Quest Journal, set the Save Settings section's unique Key value, and tick Include In Saved Games.