示例#1
0
        public static AssetStorage FromJson(string json)
        {
            var res = new AssetStorage();

            if (json == string.Empty)
            {
                return(res);
            }
            var    serializer = new JSONSerializer();
            string assetName  = string.Empty;

            foreach (var el in (JsonArray)JsonParser.Parse(json))
            {
                if (el.GetType() == typeof(JsonString))
                {
                    assetName = el.ToString().Trim(new char[] { '\"' });
                }
                else
                {
                    res.componentConfigurations[assetName] = el.ToString(true);
                }
            }

            return(res);
        }
示例#2
0
        public static T CreateInstance(AssetStorage storage)
        {
            var config = storage.GetComponentConfiguration(typeof(T).Name);

            if (config == null)
            {
                var res = new T();
                res.storage = storage;
                res.Save();
                return(res);
            }
            else
            {
                var aux = (JsonObject)JsonParser.Parse(config);
                var res = SERIALIZER.DeserializeFromJson <T>(aux);
                res.storage = storage;
                return(res);
            }
        }