Example #1
0
        public static void LoadAndConstruct <T>(ModelBlobs modelBlobs, Action <float> onProgress, Action <T> onDone, Action <string> onError) where T : Model
        {
            if (!modelBlobs.ContainsKey("manifest"))
            {
                if (onError != null)
                {
                    onError("Failed to load modelBlobs as it does not contain a manifest.");
                }
                return;
            }

            instance = modelBlobs["manifest"].XmlDeserializeFromString <Manifest>();
            if (instance == null)
            {
                if (onError != null)
                {
                    onError("Failed to deserialize manifest.");
                }
                return;
            }

            LoadModelDelegate loadModelCallback = delegate(ModelEntry entry) {
                return(modelBlobs[entry.Id].XmlDeserializeFromString(TypeHelper.GetGlobalType(entry.Type)) as Model);
            };

            Coroutiner.Start(ConstructAsync <T>(loadModelCallback, onProgress, onDone, onError));
        }
Example #2
0
        public static void LoadAndConstruct <T>(string dir, Action <float> onProgress, Action <T> onDone, Action <string> onError) where T : Model
        {
            try {
                var serializer = new XmlSerializer(typeof(Manifest));
                var stream     = new FileStream(dir + "/manifest.xml", FileMode.Open);
                instance = serializer.Deserialize(stream) as Manifest;
                stream.Close();
            } catch {
                if (onError != null)
                {
                    onError("Failed to deserialize manifest.");
                }
                return;
            }

            LoadModelDelegate loadModelCallback = delegate(ModelEntry entry) {
                try {
                    Type  type            = TypeHelper.GetGlobalType(entry.Type);
                    var   entrySerializer = new XmlSerializer(type);
                    var   entryStream     = new FileStream(dir + "/" + entry.Id + ".xml", FileMode.Open);
                    Model model           = entrySerializer.Deserialize(entryStream) as Model;
                    entryStream.Close();
                    return(model);
                } catch {
                    return(null);
                }
            };

            Coroutiner.Start(ConstructAsync <T>(loadModelCallback, onProgress, onDone, onError));
        }
Example #3
0
 private static Coroutiner GetInstance()
 {
     if (instance == null)
     {
         GameObject go = new GameObject("Coroutiner");
         instance = go.AddComponent <Coroutiner>();
     }
     return(instance);
 }