/// <summary> /// Reads the given ModelBlobs and constructs models accordingly. Returns the loaded root Model of type T in the onDone callback. /// </summary> /// <typeparam name="T">The type of instance that will be outputted in the onDone callback.</typeparam> /// <param name="data">The modelBlobs that will be read.</param> /// <param name="onStart">Called when the loading process starts.</param> /// <param name="onProgress">Called every frame during the loading process. Outputs the progression on a scale of 0.0f to 1.0f.</param> /// <param name="onDone">Called when the loading process is done, outputting the loaded instance of the given type.</param> /// <param name="onError">Called when the an error occurs during the loading process. Outputs the reason of the error.</param> public static void Load <T>(ModelBlobs data, Action onStart, Action <float> onProgress, Action <T> onDone, Action <string> onError) where T : Model { if (onStart != null) { onStart(); } if (data == null) { if (onError != null) { onError("Failed to load modelBlobs because it is null."); } return; } Manifest.LoadAndConstruct <T>(data, onProgress, delegate(T rootModel) { foreach (Model model in instances) { model.CollectReferences(); } if (onDone != null) { onDone(rootModel); } }, onError); }
/// <summary> /// Saves the given models and potentially all models referenced by the given models into modelBlobs. /// </summary> /// <param name="models">The models that will be saved, potentially along with the models they have references to.</param> /// <param name="saveReferenced">Whether the given models should also save their referenced models.</param> /// <returns>All models in form of modelBlobs, xml formatted strings order by id.</returns> public static ModelBlobs Save(List <Model> models, bool saveReferenced) { if (models == null) { UnityEngine.Debug.LogError("Can't save Models if the given list is null"); return(null); } models.Distinct <Model>(); if (saveReferenced) { foreach (Model model in models) { models.AddList <Model>(model.GetReferences()); } } models.Distinct <Model>(); ModelBlobs modelBlobs = new ModelBlobs(); modelBlobs.Add("manifest", Manifest.Save(models)); isSerializing = true; foreach (Model model in models) { modelBlobs.Add(model.Id, model.XmlSerializeToString()); } isSerializing = false; return(modelBlobs); }
/// <summary> /// Reads the given ModelBlobs and constructs models accordingly. /// </summary> /// <param name="data">The modelBlobs that will be read.</param> /// <param name="onStart">Called when the loading process starts.</param> /// <param name="onProgress">Called every frame during the loading process. Outputs the progression on a scale of 0.0f to 1.0f.</param> /// <param name="onDone">Called when the loading process is done.</param> /// <param name="onError">Called when the an error occurs during the loading process. Outputs the reason of the error.</param> public static void Load(ModelBlobs data, Action onStart, Action <float> onProgress, Action onDone, Action <string> onError) { Load <Model>(data, onStart, onProgress, delegate(Model model) { if (onDone != null) { onDone(); } }, onError); }
private static ModelBlobs FromStringArray(string[] splittedData) { ModelBlobs modelBlobs = new ModelBlobs(); string id = null; foreach (string blob in splittedData) { if (string.IsNullOrEmpty(id)) { id = blob; } else { modelBlobs.Add(id, blob); id = null; } } return(modelBlobs); }