FANDOM


Conversations are GameObjects that store a list of dialogue options that the Player can choose from. They are typically a per-scene object, but this script allows you to create a Conversation whose state is the same in all scenes.

To use it:

  1. Create a new C# script named SyncConversations.cs, and paste in the contents below
  2. Drop a new Conversation in the scene and add the new Sync Conversations component
  3. Set the Conversation component's Interaction source field to Asset File, so that responses are determined by ActionList assets, as opposed to those that live in a scene.
  4. Check Retain in prefab? in the Remember Conversation Inspector and make a new prefab from it
  5. Place an instance of this prefab in each scene.

SyncConversations.cs:

using UnityEngine;
using System.Collections;
using AC;

[RequireComponent (typeof(RememberConversation))]
public class SyncConversations : MonoBehaviour
{

private int constantID = 0;
private RememberConversation rememberConversation;


private void OnEnable ()
{
rememberConversation = GetComponent <RememberConversation>();
constantID = rememberConversation.constantID;

EventManager.OnAfterChangeScene += OnAfterChangeScene;
}


private void OnDisable ()
{
EventManager.OnAfterChangeScene -= OnAfterChangeScene;
}


private void OnAfterChangeScene (LoadingGame loadingGame)
{
if (constantID == 0)
{
return;
}

if (loadingGame == LoadingGame.No || loadingGame == LoadingGame.JustSwitchingPlayer)
{
SceneInfo previousSceneInfo = KickStarter.sceneChanger.GetPreviousSceneInfo (false);
Debug.Log ("Load data for scene " + previousSceneInfo.name + " - " + previousSceneInfo.number + ", Searching for data ID: " + constantID);

foreach (SingleLevelData levelData in KickStarter.levelStorage.allLevelData)
{
if (levelData.sceneNumber == previousSceneInfo.number)
{
foreach (ScriptData _scriptData in levelData.allScriptData)
{
if (_scriptData.data != null && _scriptData.data.Length > 0 && _scriptData.objectID == constantID)
{
Debug.Log ("Found save data in last scene, applying to self.", gameObject);
rememberConversation.LoadData (_scriptData.data);
}
}
}
}
}
}

}
Community content is available under CC-BY-SA unless otherwise noted.