FANDOM


(Created page with "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 crea...")
 
 
Line 3: Line 3:
 
To use it:
 
To use it:
   
# Create a new C# script named SyncConversations.cs, and paste in the contents below
+
# Create a new C# script named DontDestroy.cs, and paste in the contents below
# Drop a new Conversation in the scene and add the new Sync Conversations component
+
# Drop a new Conversation in the game's first scene and add the new Dont Destroy Me component
 
# 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.
 
# 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.
# Check '''Retain in prefab?''' in the Remember Conversation Inspector and make a new prefab from it
 
# Place an instance of this prefab in each scene.
 
   
SyncConversations.cs:
+
DontDestroyMe.cs:
 
using UnityEngine;<br>
 
using UnityEngine;<br>
 
using System.Collections;<br>
 
using System.Collections;<br>
 
using AC;<br>
 
using AC;<br>
<br>
+
[RequireComponent (typeof(RememberConversation))]<br>
+
public class SyncConversations : MonoBehaviour<br>
+
public class DontDestroyMe : MonoBehaviour<br>
 
{<br>
 
{<br>
<br>
+
private int constantID = 0;<br>
+
private void Start ()<br>
private RememberConversation rememberConversation;<br>
+
{
<br>
+
DontDestroyOnLoad (gameObject);
<br>
 
private void OnEnable ()<br>
 
{<br>
 
rememberConversation = GetComponent <RememberConversation>();<br>
 
constantID = rememberConversation.constantID;<br>
 
<br>
 
EventManager.OnAfterChangeScene += OnAfterChangeScene;<br>
 
 
}<br>
 
}<br>
<br>
+
<br>
 
private void OnDisable ()<br>
 
{<br>
 
EventManager.OnAfterChangeScene -= OnAfterChangeScene;<br>
 
}<br>
 
<br>
 
<br>
 
private void OnAfterChangeScene (LoadingGame loadingGame)<br>
 
{<br>
 
if (constantID == 0)<br>
 
{<br>
 
return;<br>
 
}<br>
 
<br>
 
if (loadingGame == LoadingGame.No || loadingGame == LoadingGame.JustSwitchingPlayer)<br>
 
{<br>
 
SceneInfo previousSceneInfo = KickStarter.sceneChanger.GetPreviousSceneInfo (false);<br>
 
Debug.Log ("Load data for scene " + previousSceneInfo.name + " - " + previousSceneInfo.number + ", Searching for data ID: " + constantID);<br>
 
<br>
 
foreach (SingleLevelData levelData in KickStarter.levelStorage.allLevelData)<br>
 
{<br>
 
if (levelData.sceneNumber == previousSceneInfo.number)<br>
 
{<br>
 
foreach (ScriptData _scriptData in levelData.allScriptData)<br>
 
{<br>
 
if (_scriptData.data != null && _scriptData.data.Length > 0 && _scriptData.objectID == constantID)<br>
 
{<br>
 
Debug.Log ("Found save data in last scene, applying to self.", gameObject);<br>
 
rememberConversation.LoadData (_scriptData.data);<br>
 
}<br>
 
}<br>
 
}<br>
 
}<br>
 
}<br>
 
}<br>
 
 
<br>
 
 
}
 
}
 
[[Category:General]]
 
[[Category:General]]

Latest revision as of 11:04, May 7, 2020

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 DontDestroy.cs, and paste in the contents below
  2. Drop a new Conversation in the game's first scene and add the new Dont Destroy Me 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.

DontDestroyMe.cs:

using UnityEngine;
using System.Collections;
using AC;
public class DontDestroyMe : MonoBehaviour
{
private void Start ()
{ DontDestroyOnLoad (gameObject); }
}
Community content is available under CC-BY-SA unless otherwise noted.