Edit Page
Source Editor

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:
   
 
To use it:
 
To use it:
# Create a new C# script named DontDestroyMe.cs, and paste in the contents below
+
# Create a new C# script named SyncContainers.cs, and paste in the contents below
# Drop a new Container in your game's first scene and add the new Dont Destroy Me component
+
# Drop a new Container in the scene and add the new Sync Containers component
# Make sure there is a Remember Container component attached
+
# Check '''Retain in prefab?''' in the Remember Container Inspector and make a new prefab from it
  +
# Place an instance of this prefab in each scene.
   
DontDestroyMe.cs:
+
SyncContainers.cs:
using UnityEngine;<br>using System.Collections;<br>using AC;<br>
+
using UnityEngine;<br>
  +
using System.Collections;<br>
 
  +
using AC;<br>
public class DontDestroyMe : MonoBehaviour<br>{<br>
 
  +
<br>
private void Start ()<br> {
 
  +
[RequireComponent (typeof(RememberContainer))]<br>
DontDestroyOnLoad (gameObject);
 
 
public class SyncContainers : MonoBehaviour<br>
  +
{<br>
  +
<br>
  +
private int constantID = 0;<br>
  +
private RememberContainer rememberContainer;<br>
  +
<br>
  +
<br>
 
private void OnEnable ()<br>
  +
{<br>
  +
rememberContainer = GetComponent <RememberContainer>();<br>
  +
constantID = rememberContainer.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>
  +
rememberContainer.LoadData (_scriptData.data);<br>
  +
}<br>
  +
}<br>
  +
}<br>
  +
}<br>
  +
}<br>
  +
}<br>
  +
  +
<br>
 
}
 
}
 
[[Category:General]]
 
[[Category:General]]

Please note that all contributions to the Adventure Creator Wikia are considered to be released under the CC-BY-SA

Cancel Editing help (opens in new window)