protected void initialize() { if (childrenWithPath == null) { childrenWithPath = new HirachyTree <ISaveableGameObject>(); } }
/// <summary> /// will iterate the list of registered inGameISaveableGameObject and have them create a /// SaveableObject which are saved within this list or referenced by other SaveableObjects. /// However this function just stores the data temporary and does not write it into the scene file! /// "DirtyData" is set to true, so this scene will be saved to fíle upon next game save. /// </summary> /// <param name="saveState"></param> /// <param name="ignoreForSave">hand any gameobject over that shall not be saved. /// instead their theirs trees of restoreableGameobejcts are returned /// usefull to take gameobject to the next scene</param> /// <returns>this functions returns the unsaved objects, since its very /// likely that they shall be transfered to another scene</returns> public List <IRestorableGameObject> saveScene(PersistentGameDataController.SaveType saveState, List <ISaveableGameObject> ignoreForSave) { List <IRestorableGameObject> result = new List <IRestorableGameObject>(); ///clear current list, and fill it with current objects RestoreableObjectTree.clear(); HirachyTree <ISaveableGameObject> saveableObjectTree = new HirachyTree <ISaveableGameObject>(); Stack <int> currentHirachy; ///reset the hirachy tree before saving again foreach (ISaveableGameObject gameObject in AllInGameObjects) { gameObject.ResetChildNodes(); } ///set parent and children of all objects ///also adds all objects with no saveable parent to root list foreach (ISaveableGameObject gameObject in AllInGameObjects) { ///if the objects should not be saved in the current scene they ///are just ignored for now. since the objects dont use this tree to find ///their parent, the hirachy of the non saved objects are not lost if (!ignoreForSave.Contains(gameObject)) { if (!gameObject.findAndSetParent(out currentHirachy)) { saveableObjectTree.add(gameObject, currentHirachy); } } } ///all the gameObjects with no saveableParent are returning their saveable object, ///which are added to the list. childrens are recursivly added aswell foreach (ITreeNode <ISaveableGameObject> gameObject in saveableObjectTree.getAllNodesWithValues()) { RestoreableObjectTree.add (gameObject.Value.saveObjectAndPrepareScripts(), gameObject.getFullTreePath()); } ///even though the object is not saved in this scene the restoreable objects are ///still created and returned as result so they can be used in other scenes foreach (ISaveableGameObject gameObject in ignoreForSave) { result.Add(gameObject.saveObjectAndPrepareScripts()); } IList <ISaveableGameObject> savedObjects = saveableObjectTree.getValues(); ///after all object with their scripts were initiated the scripts values are saved foreach (ISaveableGameObject gameObject in savedObjects) { gameObject.saveAllBehaviours(saveState); } ///all not saved objects are saved aswell. however their restoreable references ///will not be associated with the current scene. Instead they are returned ///so they can be used in other scenes foreach (ISaveableGameObject gameObject in ignoreForSave) { gameObject.saveAllBehaviours(saveState); } ///deleting all children for next save saveableObjectTree.clear(); ///since the scene is saved, it needs to be stored to file on the ///next game save DirtyData = true; return(result); }
public void ResetChildNodes() { childrenWithPath = new HirachyTree <ISaveableGameObject>(); }