public void PostLoadWorkspace(ISVR_MetaData metaData) { //now that all the actors exist in the scene and have their IDs and names //we can stitch the hierarchy back together foreach (var actor in _actorCollection) { //Debug.Log("about to postload the actor " + actor.GetName()); actor.PostLoad(); } }
public virtual void LoadWorkspace(ISVR_MetaData metaData) { if (metaData == null) { Debug.LogWarning("Loading Workspace with null metadata -- impossible!"); return; } //clear out all the crap that might be in the scene hierarchy under the workspace root ClearWorkspace(); foreach (var rec in metaData.ActorRecordCollection) { //first, retrieve the prefab that constitutes this type of actor //prefabID is a genetic record, what prefab is common to all actors of this 'kind' //as opposed to ActorID, which is unique to an actor individual var prefab = PrefabFromActorRecord(rec); if (prefab == null) { Debug.LogWarning("bad prefab in workspaceBase LoadWorkspace"); continue; } //TODO, it would be great to overload the ctor of EventActorCreate to take the prefabID and do all //of the above work internally to the ActorFactory subscriber var createData = new EventActorCreate.Data(prefab); EventManager.TriggerEvent(new EventActorCreate(createData)); var newActor = createData._newActor; if (newActor == null) { Debug.LogWarning("could not get an actor back from EventCreateActor"); continue; } //actor takes on ID and gameobject name //and has a chance to instantiate other stuff it needs newActor.OnLoad(rec); AddActor(newActor); } }
public virtual bool LoadWorkspace(string pathToISVRContainer) { Debug.Log("loading workspace..." + name); //clear out whatever schmutz is in the staging area ISVR_WorkingTree.PurgeStagingRootPath(ISVR_WorkingTree.StagingRootPath); //make a decorated pathToISVRContainer by adding the workspace's suffix just before the file extension pathToISVRContainer = DecorateFilePathByWorkspaceType(pathToISVRContainer); //TODO this unzips the "ContainerStaging" folder right into the temporary cachePath // which may have been monkeyed around with by Designer Dan between the save //and the load... so this is potentially destructive.. hmm if (!ISVR_ContainerZip.Unzip(pathToISVRContainer, Application.temporaryCachePath)) { return(false); } //the json file (metaData file) is located in the staging root //under the same name as the container (isvr) //LoadMetaData will append the .json extension var metaFileName = Path.GetFileNameWithoutExtension(pathToISVRContainer); var data = ISVR_MetaDataFile.LoadMetaData(metaFileName); if (data == null) { Debug.LogWarning("could not load metafile " + metaFileName + " for workspace of type, " + GetWorkspaceTypeName()); return(false); } MetaData = data; //make a bunch of actors LoadWorkspace(MetaData);//uses the actor records in metadata //then another step to allow every actor and actorcomponent //a chance to fix up PostLoadWorkspace(MetaData);//uses the actor records in metadata ISVR_WorkingTree.PurgeStagingRootPath(ISVR_WorkingTree.StagingRootPath); return(true); }
public static bool SaveMetaData(ISVR_MetaData metaData, string metaDataFileName) { Debug.Log("Saving MetaData file: " + metaDataFileName); string path = MakeMetaDataFilePath(metaDataFileName); if (metaData != null && metaData.Validate()) { var dataText = ISVR_MetaData_Serializer.Serialize(metaData); FileStream stream; if (!File.Exists(path)) { stream = File.Create(path); } else { stream = File.OpenWrite(path); } //clear out the previous contents of the metadata file stream.SetLength(0); byte[] info = new System.Text.UTF8Encoding(true).GetBytes(dataText); stream.Write(info, 0, info.Length); stream.Close(); //OpenFolder(Path.GetDirectoryName(path)); return(true); } Debug.LogError("Cannot save metadata at " + path); return(false); }
public static string Serialize(ISVR_MetaData data) { string json = JsonUtility.ToJson(data, true); return(json); }