Exemplo n.º 1
0
        /**
         * Combs the scene for data to store, combines it into a SingleLevelData variable, and adds it to the SingleLevelData List, allLevelData.
         */
        public void StoreCurrentLevelData()
        {
            List <TransformData> thisLevelTransforms = PopulateTransformData();
            List <ScriptData>    thisLevelScripts    = PopulateScriptData();

            SingleLevelData thisLevelData = new SingleLevelData();

            thisLevelData.sceneNumber = UnityVersionHandler.GetCurrentSceneNumber();

            thisLevelData.activeLists = KickStarter.actionListManager.GetSaveData();

            if (KickStarter.sceneSettings)
            {
                if (KickStarter.sceneSettings.navMesh && KickStarter.sceneSettings.navMesh.GetComponent <ConstantID>())
                {
                    thisLevelData.navMesh = Serializer.GetConstantID(KickStarter.sceneSettings.navMesh.gameObject);
                }
                if (KickStarter.sceneSettings.defaultPlayerStart && KickStarter.sceneSettings.defaultPlayerStart.GetComponent <ConstantID>())
                {
                    thisLevelData.playerStart = Serializer.GetConstantID(KickStarter.sceneSettings.defaultPlayerStart.gameObject);
                }
                if (KickStarter.sceneSettings.sortingMap && KickStarter.sceneSettings.sortingMap.GetComponent <ConstantID>())
                {
                    thisLevelData.sortingMap = Serializer.GetConstantID(KickStarter.sceneSettings.sortingMap.gameObject);
                }
                if (KickStarter.sceneSettings.cutsceneOnLoad && KickStarter.sceneSettings.cutsceneOnLoad.GetComponent <ConstantID>())
                {
                    thisLevelData.onLoadCutscene = Serializer.GetConstantID(KickStarter.sceneSettings.cutsceneOnLoad.gameObject);
                }
                if (KickStarter.sceneSettings.cutsceneOnStart && KickStarter.sceneSettings.cutsceneOnStart.GetComponent <ConstantID>())
                {
                    thisLevelData.onStartCutscene = Serializer.GetConstantID(KickStarter.sceneSettings.cutsceneOnStart.gameObject);
                }
                if (KickStarter.sceneSettings.tintMap && KickStarter.sceneSettings.tintMap.GetComponent <ConstantID>())
                {
                    thisLevelData.tintMap = Serializer.GetConstantID(KickStarter.sceneSettings.tintMap.gameObject);
                }
            }

            thisLevelData.localVariablesData = SaveSystem.CreateVariablesData(KickStarter.localVariables.localVars, false, VariableLocation.Local);
            thisLevelData.allTransformData   = thisLevelTransforms;
            thisLevelData.allScriptData      = thisLevelScripts;

            bool found = false;

            for (int i = 0; i < allLevelData.Count; i++)
            {
                if (allLevelData[i].sceneNumber == UnityVersionHandler.GetCurrentSceneNumber())
                {
                    allLevelData[i] = thisLevelData;
                    found           = true;
                    break;
                }
            }

            if (!found)
            {
                allLevelData.Add(thisLevelData);
            }
        }
Exemplo n.º 2
0
        private void LoadSceneData(SingleLevelData levelData, SubScene subScene = null)
        {
            Scene scene = (subScene) ? subScene.gameObject.scene : SceneChanger.CurrentScene;

            SceneSettings  sceneSettings  = (subScene == null) ? KickStarter.sceneSettings : subScene.SceneSettings;
            LocalVariables localVariables = (subScene == null) ? KickStarter.localVariables : subScene.LocalVariables;

            KickStarter.actionListManager.LoadData(levelData.activeLists, subScene);

            if (sceneSettings)
            {
                UnloadCutsceneOnLoad(levelData.onLoadCutscene, sceneSettings);
                UnloadCutsceneOnStart(levelData.onStartCutscene, sceneSettings);
                UnloadNavMesh(levelData.navMesh, sceneSettings);
                UnloadPlayerStart(levelData.playerStart, sceneSettings);
                UnloadSortingMap(levelData.sortingMap, sceneSettings);
                UnloadTintMap(levelData.tintMap, sceneSettings);
            }

            UnloadTransformData(levelData.allTransformData, scene);
            UnloadScriptData(levelData.allScriptData, scene);

            if (localVariables)
            {
                localVariables.localVars = SaveSystem.UnloadVariablesData(levelData.localVariablesData, localVariables.localVars);
            }
        }
Exemplo n.º 3
0
 /**
  * <summary>Checks if a given SingleLevelData class instance matches this own instance's intended scene</summary>
  * <param name = "otherLevelData">The other class instance to check</param>
  * <returns>True if the two instances match the same scene</returns>
  */
 public bool DataMatchesScene(SingleLevelData otherLevelData)
 {
     if (otherLevelData.sceneNumber == sceneNumber)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        /**
         * <summary>Returns a sub-scene's save data to the appropriate Remember components.</summary>
         * <param name = "subScene">The SubScene component associated with the sub-scene</param>
         */
        public void ReturnSubSceneData(SubScene subScene)
        {
            SingleLevelData levelData = GetLevelData(subScene.SceneIndex);

            if (levelData == null)
            {
                return;
            }

            LoadSceneData(levelData, subScene);
            AssetLoader.UnloadAssets();
        }
Exemplo n.º 5
0
        /** Returns the currently-loaded scene's save data to the appropriate Remember components. */
        public void ReturnCurrentLevelData()
        {
            SingleLevelData levelData = GetLevelData();

            if (levelData == null)
            {
                return;
            }

            LoadSceneData(levelData);
            AssetLoader.UnloadAssets();
        }
Exemplo n.º 6
0
        /**
         * <summary>Returns a sub-scene's save data to the appropriate Remember components.</summary>
         * <param name = "subScene">The SubScene component associated with the sub-scene</param>
         * <param name = "restoringSaveFile">True if the game is currently loading a saved game file, as opposed to just switching scene</param>
         */
        public void ReturnSubSceneData(SubScene subScene, bool restoringSaveFile)
        {
            SingleLevelData levelData = GetLevelData(subScene.SceneInfo.number);

            if (levelData == null)
            {
                return;
            }

            SendDataToScene(levelData, restoringSaveFile, subScene);
            AssetLoader.UnloadAssets();
        }
Exemplo n.º 7
0
        /**
         * <summary>Returns the currently-loaded scene's save data to the appropriate Remember components.</summary>
         * <param name = "restoringSaveFile">True if the game is currently loading a saved game file, as opposed to just switching scene</param>
         */
        public void ReturnCurrentLevelData(bool restoringSaveFile)
        {
            SingleLevelData levelData = GetLevelData();

            if (levelData == null)
            {
                return;
            }

            SendDataToScene(levelData, restoringSaveFile);
            AssetLoader.UnloadAssets();
        }
Exemplo n.º 8
0
        private void SendDataToScene(SingleLevelData levelData, bool restoringSaveFile, SubScene subScene = null)
        {
            SceneSettings  sceneSettings  = (subScene == null) ? KickStarter.sceneSettings : subScene.SceneSettings;
            LocalVariables localVariables = (subScene == null) ? KickStarter.localVariables : subScene.LocalVariables;

            KickStarter.actionListManager.LoadData(levelData.activeLists, subScene);

            UnloadCutsceneOnLoad(levelData.onLoadCutscene, sceneSettings);
            UnloadCutsceneOnStart(levelData.onStartCutscene, sceneSettings);
            UnloadNavMesh(levelData.navMesh, sceneSettings);
            UnloadPlayerStart(levelData.playerStart, sceneSettings);
            UnloadSortingMap(levelData.sortingMap, sceneSettings);
            UnloadTintMap(levelData.tintMap, sceneSettings);

            UnloadTransformData(levelData.allTransformData, subScene);

            foreach (ScriptData _scriptData in levelData.allScriptData)
            {
                if (_scriptData.data != null && _scriptData.data.Length > 0)
                {
                    // Get objects in active scene, and "DontDestroyOnLoad" scene
                    Remember[] saveObjects = Serializer.returnComponents <Remember> (_scriptData.objectID);

                    foreach (Remember saveObject in saveObjects)
                    {
                        if (saveObject != null && UnityVersionHandler.ObjectIsInActiveScene(saveObject.gameObject))
                        {
                            // May have more than one Remember script on the same object, so check all
                            Remember[] saveScripts = saveObject.gameObject.GetComponents <Remember>();
                            foreach (Remember saveScript in saveScripts)
                            {
                                saveScript.LoadData(_scriptData.data, restoringSaveFile);
                            }
                        }
                    }
                }

                /*Remember saveObject = Serializer.returnComponent <Remember> (_scriptData.objectID, sceneSettings.gameObject);
                 * if (saveObject != null && _scriptData.data != null && _scriptData.data.Length > 0)
                 * {
                 *      // May have more than one Remember script on the same object, so check all
                 *      Remember[] saveScripts = saveObject.gameObject.GetComponents <Remember>();
                 *      foreach (Remember saveScript in saveScripts)
                 *      {
                 *              saveScript.LoadData (_scriptData.data, restoringSaveFile);
                 *      }
                 * }*/
            }

            UnloadVariablesData(levelData.localVariablesData, localVariables);
            KickStarter.sceneSettings.UpdateAllSortingMaps();
        }
Exemplo n.º 9
0
        public List <SingleLevelData> DeserializeAllRoomData(string dataString)
        {
            // Can't serialize a list, so split by delimeter
            List <SingleLevelData> allLevelData = new List <SingleLevelData>();

            string[] stringSeparators = new string[] { roomDelimiter };
            string[] levelDataStrings = dataString.Split(stringSeparators, StringSplitOptions.None);
            foreach (string levelDataString in levelDataStrings)
            {
                SingleLevelData levelData = DeserializeObject <SingleLevelData> (levelDataString);
                allLevelData.Add(levelData);
            }
            return(allLevelData);
        }
Exemplo n.º 10
0
        /**
         * <summary>De-serializes a List of SingleLevelData object from a string, according to the game's SaveMethod.</summary>
         * <param name = "dataString">The object, serialized into a string</param>
         * <param name = "delimieter">If using Json, then this string is used to separate each SingleLevelData instance.</param>
         * <returns>The object, deserialized</returns>
         */
        public static List <SingleLevelData> DeserializeAllRoomData(string dataString, string delimiter = "|ROOMDELIMITER|")
        {
            if (SaveSystem.GetSaveMethod() == SaveMethod.Json)
            {
                // Can't serialize a list, so split by delimeter
                List <SingleLevelData> allLevelData = new List <SingleLevelData>();
                string[] stringSeparators           = new string[] { delimiter };
                string[] levelDataStrings           = dataString.Split(stringSeparators, StringSplitOptions.None);
                foreach (string levelDataString in levelDataStrings)
                {
                    SingleLevelData levelData = DeserializeObject <SingleLevelData> (levelDataString);
                    allLevelData.Add(levelData);
                }
                return(allLevelData);
            }

            return((List <SingleLevelData>)Serializer.DeserializeObject <List <SingleLevelData> > (dataString));
        }
Exemplo n.º 11
0
        /**
         * <summary>Returns the currently-loaded scene's save data to the appropriate Remember components, provided they are on the Player.</summary>
         */
        public void ReturnCurrentLevelPlayerData()
        {
            SingleLevelData levelData = GetLevelData();

            if (levelData == null)
            {
                return;
            }

            foreach (ScriptData _scriptData in levelData.allScriptData)
            {
                if (_scriptData.data != null && _scriptData.data.Length > 0)
                {
                    // Get objects in active scene, and "DontDestroyOnLoad" scene
                    Remember[] saveObjects = Serializer.returnComponents <Remember> (_scriptData.objectID);

                    foreach (Remember saveObject in saveObjects)
                    {
                        if (saveObject != null)
                        {
                            if ((saveObject.transform.parent == null && saveObject.tag == Tags.player) ||
                                (saveObject.transform.parent != null && saveObject.transform.root != null && saveObject.transform.root.tag == Tags.player))
                            {
                                // May have more than one Remember script on the same object, so check all
                                Remember[] saveScripts = saveObject.gameObject.GetComponents <Remember>();
                                foreach (Remember saveScript in saveScripts)
                                {
                                    saveScript.LoadData(_scriptData.data, true);
                                }
                            }
                        }
                    }
                }
            }

            AssetLoader.UnloadAssets();
        }
Exemplo n.º 12
0
        public void StoreCurrentLevelData()
        {
            List<TransformData> thisLevelTransforms = PopulateTransformData ();
            List<ScriptData> thisLevelScripts = PopulateScriptData ();

            SingleLevelData thisLevelData = new SingleLevelData ();
            thisLevelData.sceneNumber = Application.loadedLevel;

            if (KickStarter.sceneSettings)
            {
                if (KickStarter.sceneSettings.navMesh && KickStarter.sceneSettings.navMesh.GetComponent <ConstantID>())
                {
                    thisLevelData.navMesh = Serializer.GetConstantID (KickStarter.sceneSettings.navMesh.gameObject);
                }
                if (KickStarter.sceneSettings.defaultPlayerStart && KickStarter.sceneSettings.defaultPlayerStart.GetComponent <ConstantID>())
                {
                    thisLevelData.playerStart = Serializer.GetConstantID (KickStarter.sceneSettings.defaultPlayerStart.gameObject);
                }
                if (KickStarter.sceneSettings.sortingMap && KickStarter.sceneSettings.sortingMap.GetComponent <ConstantID>())
                {
                    thisLevelData.sortingMap = Serializer.GetConstantID (KickStarter.sceneSettings.sortingMap.gameObject);
                }
                if (KickStarter.sceneSettings.cutsceneOnLoad && KickStarter.sceneSettings.cutsceneOnLoad.GetComponent <ConstantID>())
                {
                    thisLevelData.onLoadCutscene = Serializer.GetConstantID (KickStarter.sceneSettings.cutsceneOnLoad.gameObject);
                }
                if (KickStarter.sceneSettings.cutsceneOnStart && KickStarter.sceneSettings.cutsceneOnStart.GetComponent <ConstantID>())
                {
                    thisLevelData.onStartCutscene = Serializer.GetConstantID (KickStarter.sceneSettings.cutsceneOnStart.gameObject);
                }
            }

            thisLevelData.localVariablesData = SaveSystem.CreateVariablesData (KickStarter.localVariables.localVars, false, VariableLocation.Local);
            thisLevelData.allTransformData = thisLevelTransforms;
            thisLevelData.allScriptData = thisLevelScripts;

            bool found = false;
            for (int i=0; i<allLevelData.Count; i++)
            {
                if (allLevelData[i].sceneNumber == Application.loadedLevel)
                {
                    allLevelData[i] = thisLevelData;
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                allLevelData.Add (thisLevelData);
            }
        }
Exemplo n.º 13
0
        private void SendSceneToData(SubScene subScene = null)
        {
            SceneSettings  sceneSettings  = (subScene == null) ? KickStarter.sceneSettings : subScene.SceneSettings;
            LocalVariables localVariables = (subScene == null) ? KickStarter.localVariables : subScene.LocalVariables;

            List <TransformData> thisLevelTransforms = PopulateTransformData(subScene);
            List <ScriptData>    thisLevelScripts    = PopulateScriptData(subScene);

            SingleLevelData thisLevelData = new SingleLevelData();

            thisLevelData.sceneNumber = (subScene == null) ? UnityVersionHandler.GetCurrentSceneNumber() : subScene.SceneInfo.number;

            thisLevelData.activeLists = KickStarter.actionListManager.GetSaveData(subScene);

            if (sceneSettings != null)
            {
                if (sceneSettings.navMesh && sceneSettings.navMesh.GetComponent <ConstantID>())
                {
                    thisLevelData.navMesh = Serializer.GetConstantID(sceneSettings.navMesh.gameObject);
                }
                if (sceneSettings.defaultPlayerStart && sceneSettings.defaultPlayerStart.GetComponent <ConstantID>())
                {
                    thisLevelData.playerStart = Serializer.GetConstantID(sceneSettings.defaultPlayerStart.gameObject);
                }
                if (sceneSettings.sortingMap && sceneSettings.sortingMap.GetComponent <ConstantID>())
                {
                    thisLevelData.sortingMap = Serializer.GetConstantID(sceneSettings.sortingMap.gameObject);
                }
                if (sceneSettings.cutsceneOnLoad && sceneSettings.cutsceneOnLoad.GetComponent <ConstantID>())
                {
                    thisLevelData.onLoadCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnLoad.gameObject);
                }
                if (sceneSettings.cutsceneOnStart && sceneSettings.cutsceneOnStart.GetComponent <ConstantID>())
                {
                    thisLevelData.onStartCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnStart.gameObject);
                }
                if (sceneSettings.tintMap && sceneSettings.tintMap.GetComponent <ConstantID>())
                {
                    thisLevelData.tintMap = Serializer.GetConstantID(sceneSettings.tintMap.gameObject);
                }
            }

            thisLevelData.localVariablesData = SaveSystem.CreateVariablesData(localVariables.localVars, false, VariableLocation.Local);
            thisLevelData.allTransformData   = thisLevelTransforms;
            thisLevelData.allScriptData      = thisLevelScripts;

            bool found = false;

            for (int i = 0; i < allLevelData.Count; i++)
            {
                if (allLevelData[i].sceneNumber == thisLevelData.sceneNumber)
                {
                    allLevelData[i] = thisLevelData;
                    found           = true;
                    break;
                }
            }

            if (!found)
            {
                allLevelData.Add(thisLevelData);
            }
        }
Exemplo n.º 14
0
        private void SaveSceneData(SubScene subScene = null)
        {
            Scene scene = (subScene) ? subScene.gameObject.scene : SceneChanger.CurrentScene;

            SceneSettings  sceneSettings  = (subScene == null) ? KickStarter.sceneSettings : subScene.SceneSettings;
            LocalVariables localVariables = (subScene == null) ? KickStarter.localVariables : subScene.LocalVariables;

            List <TransformData> thisLevelTransforms = PopulateTransformData(scene);
            List <ScriptData>    thisLevelScripts    = PopulateScriptData(scene);

            SingleLevelData thisLevelData = new SingleLevelData();

            thisLevelData.sceneNumber = (subScene == null) ? SceneChanger.CurrentSceneIndex : subScene.SceneIndex;

            thisLevelData.activeLists = KickStarter.actionListManager.GetSaveData(subScene);

            if (sceneSettings)
            {
                if (sceneSettings.navMesh)
                {
                    thisLevelData.navMesh = Serializer.GetConstantID(sceneSettings.navMesh.gameObject, false);
                }
                if (sceneSettings.defaultPlayerStart)
                {
                    thisLevelData.playerStart = Serializer.GetConstantID(sceneSettings.defaultPlayerStart.gameObject, false);
                }
                if (sceneSettings.sortingMap)
                {
                    thisLevelData.sortingMap = Serializer.GetConstantID(sceneSettings.sortingMap.gameObject, false);
                }
                if (sceneSettings.cutsceneOnLoad)
                {
                    thisLevelData.onLoadCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnLoad.gameObject, false);
                }
                if (sceneSettings.cutsceneOnStart)
                {
                    thisLevelData.onStartCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnStart.gameObject, false);
                }
                if (sceneSettings.tintMap)
                {
                    thisLevelData.tintMap = Serializer.GetConstantID(sceneSettings.tintMap.gameObject, false);
                }
            }

            if (localVariables)
            {
                thisLevelData.localVariablesData = SaveSystem.CreateVariablesData(localVariables.localVars, false, VariableLocation.Local);
            }
            thisLevelData.allTransformData = thisLevelTransforms;
            thisLevelData.allScriptData    = thisLevelScripts;

            if (allLevelData == null)
            {
                allLevelData = new List <SingleLevelData>();
            }
            for (int i = 0; i < allLevelData.Count; i++)
            {
                if (allLevelData[i].DataMatchesScene(thisLevelData))
                {
                    allLevelData[i] = thisLevelData;
                    return;
                }
            }

            allLevelData.Add(thisLevelData);
        }
Exemplo n.º 15
0
		public void StoreCurrentLevelData ()
		{
			List<ColliderData> thisLevelColliders = PopulateColliderData ();
			List<ConversationData> thisLevelConversations = PopulateConversationData ();
			List<ContainerData> thisLevelContainers = PopulateContainerData ();
			List<NavMesh2DData> thisLevelNavMesh2Ds = PopulateNavMesh2DData ();
			List<ShapeableData> thisLevelShapeables = PopulateShapeableData ();
			List<MoveableData> thisLevelMoveables = PopulateMoveableData ();
			List<HotspotData> thisLevelHotspots = PopulateHotspotData ();
			List<TriggerData> thisLevelTriggers = PopulateTriggerData ();
			List<NameData> thisLevelNames = PopulateNameData ();
			List<NPCData> thisLevelNPCs = PopulateNPCData ();
			List<TransformData> thisLevelTransforms = PopulateTransformData ();
			List<VisibilityData> thisLevelVisibilitys = PopulateVisibilityData ();

			SingleLevelData thisLevelData = new SingleLevelData ();
			thisLevelData.sceneNumber = Application.loadedLevel;
			
			SceneSettings sceneSettings = GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>();
			if (sceneSettings)
			{
				if (sceneSettings.navMesh && sceneSettings.navMesh.GetComponent <ConstantID>())
				{
					thisLevelData.navMesh = Serializer.GetConstantID (sceneSettings.navMesh.gameObject);
				}
				if (sceneSettings.defaultPlayerStart && sceneSettings.defaultPlayerStart.GetComponent <ConstantID>())
				{
					thisLevelData.playerStart = Serializer.GetConstantID (sceneSettings.defaultPlayerStart.gameObject);
				}
				if (sceneSettings.sortingMap && sceneSettings.sortingMap.GetComponent <ConstantID>())
				{
					thisLevelData.sortingMap = Serializer.GetConstantID (sceneSettings.sortingMap.gameObject);
				}
				if (sceneSettings.cutsceneOnLoad && sceneSettings.cutsceneOnLoad.GetComponent <ConstantID>())
				{
					thisLevelData.onLoadCutscene = Serializer.GetConstantID (sceneSettings.cutsceneOnLoad.gameObject);
				}
				if (sceneSettings.cutsceneOnStart && sceneSettings.cutsceneOnStart.GetComponent <ConstantID>())
				{
					thisLevelData.onStartCutscene = Serializer.GetConstantID (sceneSettings.cutsceneOnStart.gameObject);
				}
			}

			thisLevelData.localVariablesData = SaveSystem.CreateVariablesData (GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>().localVars, false, VariableLocation.Local);

			thisLevelData.conversations = thisLevelConversations;
			thisLevelData.visibilitys = thisLevelVisibilitys;
			thisLevelData.transforms = thisLevelTransforms;
			thisLevelData.containers = thisLevelContainers;
			thisLevelData.navMesh2Ds = thisLevelNavMesh2Ds;
			thisLevelData.colliders = thisLevelColliders;
			thisLevelData.shapeables = thisLevelShapeables;
			thisLevelData.moveables = thisLevelMoveables;
			thisLevelData.hotspots = thisLevelHotspots;
			thisLevelData.triggers = thisLevelTriggers;
			thisLevelData.names = thisLevelNames;
			thisLevelData.npcs = thisLevelNPCs;
			
			bool found = false;
			for (int i=0; i<allLevelData.Count; i++)
			{
				if (allLevelData[i].sceneNumber == Application.loadedLevel)
				{
					allLevelData[i] = thisLevelData;
					found = true;
					break;
				}
			}
			
			if (!found)
			{
				allLevelData.Add (thisLevelData);
			}
		}