示例#1
0
        private static void PlatformBuildAllAssetBundles(BuildTarget target, string platformName)
        {
            const string assetBundlesBasePath     = "Assets/AssetBundles/";
            var          platformAssetBundlesPath = assetBundlesBasePath + platformName;

            Directory.CreateDirectory(platformAssetBundlesPath);
            BuildPipeline.BuildAssetBundles(platformAssetBundlesPath, DefaultOptions, target);

            // Assuming all files has extension ".unity3d"

            var knownAssetBundleFilePaths = Directory.GetFiles(platformAssetBundlesPath, "*.unity3d", SearchOption.TopDirectoryOnly);

            var desBuilder = new DeserializerBuilder();
            var des        = desBuilder.IgnoreUnmatchedProperties()
                             .WithNamingConvention(new NullNamingConvention())
                             .Build();

            foreach (var knownAssetBundleFilePath in knownAssetBundleFilePaths)
            {
                var assetBundlePath = Path.GetFullPath(knownAssetBundleFilePath);
                var manifestPath    = assetBundlePath + ".manifest";

                var assetBundleFileInfo = new FileInfo(assetBundlePath);

                var manifestContent = File.ReadAllText(manifestPath, Encoding.UTF8);
                var manifest        = des.Deserialize <AssetBundleManifestClass>(manifestContent);

                Debug.Log(string.Format("{0} # {1}", manifest.Hashes.AssetFileHash.Hash, assetBundleFileInfo.Name));
            }
        }
示例#2
0
        static UpgradeGuides()
        {
            var builder = new DeserializerBuilder();

            builder.IgnoreUnmatchedProperties();
            builder.WithNamingConvention(CamelCaseNamingConvention.Instance);
            deserializer = builder.Build();
        }
示例#3
0
        public void IgnoreExtraPropertiesIfWantedBefore()
        {
            var text = Lines("bbb: [200,100]", "aaa: hello");

            DeserializerBuilder.IgnoreUnmatchedProperties();
            var actual = Deserializer.Deserialize <Simple>(UsingReaderFor(text));

            actual.aaa.Should().Be("hello");
        }
示例#4
0
        public static Deserializer CreateDeserializer()
        {
            var builder = new DeserializerBuilder();

            builder.IgnoreUnmatchedProperties();
            builder.WithNamingConvention(namingConvention);

            return(builder.Build());
        }
示例#5
0
        public static T Deserialize <T>(string str)
        {
            DeserializerBuilder db = new DeserializerBuilder();

            db.IgnoreUnmatchedProperties();
            Deserializer d = db.Build();

            return(d.Deserialize <T>(str));
        }
示例#6
0
        public static T Deserialize <T>(TextReader reader, bool ignoreUnmatchedProperties = true)
        {
            DeserializerBuilder builder = new DeserializerBuilder();

            if (ignoreUnmatchedProperties)
            {
                builder.IgnoreUnmatchedProperties();
            }
            Deserializer deserializer = builder.Build();

            return(deserializer.Deserialize <T>(reader));
        }
示例#7
0
        public static BasicOptions Load(string filepath)
        {
            var yaml    = File.ReadAllText(filepath);
            var builder = new DeserializerBuilder();

            builder.WithNamingConvention(new HyphenatedNamingConvention());
            builder.IgnoreUnmatchedProperties();
            var deserializer = builder.Build();
            var options      = deserializer.Deserialize <BasicOptions>(yaml);

            return(options ?? new BasicOptions());
        }
示例#8
0
        private static Dictionary <object, object> ReadYaml(string filePath)
        {
            var builder      = new DeserializerBuilder();
            var deserializer = builder.IgnoreUnmatchedProperties()
                               .WithNamingConvention(new CamelCaseNamingConvention())
                               .Build();

            using (var reader = File.OpenText(filePath))
            {
                return(deserializer.Deserialize <Dictionary <object, object> >(reader));
            }
        }
示例#9
0
 public static T Deserialize <T>(string yaml, bool ignoreUnmatchedProperties = true)
 {
     using (StringReader reader = new StringReader(yaml))
     {
         DeserializerBuilder builder = new DeserializerBuilder();
         if (ignoreUnmatchedProperties)
         {
             builder.IgnoreUnmatchedProperties();
         }
         Deserializer deserializer = builder.Build();
         return(deserializer.Deserialize <T>(reader));
     }
 }
示例#10
0
 public static T Parse <T>(string readText, string debugFilename, ErrorHandler handle_error = null, List <Tuple <string, Type> > tagMappings = null)
 {
     try
     {
         if (handle_error == null)
         {
             handle_error = LogError;
         }
         readText = readText.Replace("\t", "    ");
         Action <string> unmatchedLogFn = delegate(string error)
         {
             handle_error(new Error
             {
                 file = new FileHandle
                 {
                     full_path = debugFilename
                 },
                 text     = readText,
                 message  = error,
                 severity = Error.Severity.Recoverable
             }, false);
         };
         DeserializerBuilder deserializerBuilder = new DeserializerBuilder();
         deserializerBuilder.IgnoreUnmatchedProperties(unmatchedLogFn);
         if (tagMappings != null)
         {
             foreach (Tuple <string, Type> tagMapping in tagMappings)
             {
                 deserializerBuilder = deserializerBuilder.WithTagMapping(tagMapping.first, tagMapping.second);
             }
         }
         Deserializer deserializer = deserializerBuilder.Build();
         StringReader input        = new StringReader(readText);
         return(deserializer.Deserialize <T>(input));
     }
     catch (Exception ex)
     {
         handle_error(new Error
         {
             file = new FileHandle
             {
                 full_path = debugFilename
             },
             text            = readText,
             message         = ex.Message,
             inner_exception = ex.InnerException,
             severity        = Error.Severity.Fatal
         }, false);
     }
     return(default(T));
 }
示例#11
0
        /// <summary>
        ///     Loads a .qua file from a stream
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="checkValidity"></param>
        /// <returns></returns>
        public static Qua Parse(byte[] buffer, bool checkValidity = true)
        {
            var input = new StringReader(Encoding.UTF8.GetString(buffer, 0, buffer.Length));

            var deserializer = new DeserializerBuilder();

            deserializer.IgnoreUnmatchedProperties();
            var qua = (Qua)deserializer.Build().Deserialize(input, typeof(Qua));

            RestoreDefaultValues(qua);
            AfterLoad(qua, checkValidity);

            return(qua);
        }
        internal void LoadPlugins()
        {
            var deserializerBuilder = new DeserializerBuilder();
            var deserializer        = deserializerBuilder
                                      .IgnoreUnmatchedProperties()
                                      .WithNamingConvention(new UnderscoredNamingConvention())
                                      .Build();

            PluginsConfig pluginsConfig;

            using (var fileStream = File.Open(PluginListFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                using (var reader = new StreamReader(fileStream)) {
                    pluginsConfig = deserializer.Deserialize <PluginsConfig>(reader);
                }
            }

            InstancingFactoryIDs = pluginsConfig.ComponentFactories;

            string[] filters;

            switch (pluginsConfig.Loading.Mode)
            {
            case PluginSearchMode.Default:
                filters = null;
                break;

            case PluginSearchMode.Exclusive:
                filters = pluginsConfig.Loading.Lists.BlackList;
                break;

            case PluginSearchMode.Inclusive:
                filters = pluginsConfig.Loading.Lists.WhiteList;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var startupPath = ApplicationHelper.StartupPath;
            var searchPaths = new string[SubSearchPaths.Count + 1];

            searchPaths[0] = startupPath;

            for (var i = 1; i <= SubSearchPaths.Count; ++i)
            {
                searchPaths[i] = Path.Combine(startupPath, SubSearchPaths[i - 1]);
            }

            LoadAssemblies(pluginsConfig.Loading.Mode, filters, searchPaths);
        }
示例#13
0
        public static object LoadFile(string filePath, Type type, Format format)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            object result = null;

            using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(file, new UTF8Encoding(false)))
                {
                    switch (format)
                    {
                    case Format.Json:
                    {
                        using (var jsonTextReader = new JsonTextReader(reader))
                        {
                            var jsonSerializer = new JsonSerializer()
                            {
                                Formatting        = Formatting.Indented,
                                NullValueHandling = NullValueHandling.Ignore,
                            };

                            result = jsonSerializer.Deserialize(jsonTextReader, type);
                        }
                    }
                    break;

                    case Format.Yaml:
                    {
                        var contents = reader.ReadToEnd();

                        var builder = new DeserializerBuilder();

                        builder.IgnoreUnmatchedProperties();

                        var yamlDeserializer = builder.Build();

                        result = yamlDeserializer.Deserialize(contents, type);
                    }
                    break;
                    }
                }
            }

            return(result);
        }
示例#14
0
        public static T LoadFile <T>(string filePath, Format format) where T : class
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            T result = null;

            using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(file, new UTF8Encoding(false)))
                {
                    switch (format)
                    {
                    case Format.Json:
                    {
                        using (var jsonTextReader = new JsonTextReader(reader))
                        {
                            var jsonSerializer = new JsonSerializer()
                            {
                                NullValueHandling     = NullValueHandling.Ignore,
                                MissingMemberHandling = MissingMemberHandling.Ignore,
                            };

                            result = jsonSerializer.Deserialize <T>(jsonTextReader);
                        }
                    }
                    break;

                    case Format.Yaml:
                    {
                        var contents = reader.ReadToEnd();

                        var builder = new DeserializerBuilder();

                        builder.IgnoreUnmatchedProperties();

                        var yamlDeserializer = builder.Build();

                        result = yamlDeserializer.Deserialize <T>(contents);
                    }
                    break;
                    }
                }
            }

            return(result);
        }
示例#15
0
        public static void LoadData(string path)
        {
            var location  = System.Reflection.Assembly.GetEntryAssembly().Location;
            var directory = System.IO.Path.GetDirectoryName(location);

            Console.WriteLine("正在加载EVE数据库");
            var file = File.ReadAllText(directory + "/" + path);
            DeserializerBuilder bu = new DeserializerBuilder();

            bu.IgnoreUnmatchedProperties();
            var deserializer = bu.Build();

            ShipNames = deserializer.Deserialize <Dictionary <int, typeIDs> >(file);
            Console.WriteLine("加载完成");
        }
示例#16
0
        private static T DeserializeYaml <T>(
            string yaml,
            bool ignoreUnmatchedProperties)
        {
            var deserializerBuilder = new DeserializerBuilder()
                                      .WithNamingConvention(new CamelCaseNamingConvention());

            if (ignoreUnmatchedProperties)
            {
                deserializerBuilder.IgnoreUnmatchedProperties();
            }

            var deserializer = deserializerBuilder.Build();

            return(deserializer.Deserialize <T>(yaml));
        }
示例#17
0
        public static T DeserializeFile <T>(string path, bool ignoreUnmatchedProperties = true) where T : class
        {
            T ssc = null;

            using (StreamReader reader = new StreamReader(path))
            {
                DeserializerBuilder builder = new DeserializerBuilder();
                if (ignoreUnmatchedProperties)
                {
                    builder.IgnoreUnmatchedProperties();
                }
                Deserializer deserializer = builder.Build();
                ssc = deserializer.Deserialize <T>(reader);
            }
            return(ssc);
        }
示例#18
0
        /// <summary>
        ///     Takes in a path to a .qua file and attempts to parse it.
        ///     Will throw an error if unable to be parsed.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="checkValidity"></param>
        public static Qua Parse(string path, bool checkValidity = true)
        {
            Qua qua;

            using (var file = File.OpenText(path))
            {
                var deserializer = new DeserializerBuilder();
                deserializer.IgnoreUnmatchedProperties();
                qua = (Qua)deserializer.Build().Deserialize(file, typeof(Qua));

                RestoreDefaultValues(qua);
            }

            AfterLoad(qua, checkValidity);

            return(qua);
        }
        public static T Deserialize <T>(TextReader reader, bool ignoreUnmatchedProperties = true, IYamlTypeConverter converter = null)
        {
            DeserializerBuilder builder = new DeserializerBuilder();

            if (ignoreUnmatchedProperties)
            {
                builder.IgnoreUnmatchedProperties();
            }

            if (converter != null)
            {
                builder.WithTypeConverter(converter);
            }

            Deserializer deserializer = builder.Build() as Deserializer;

            return(deserializer.Deserialize <T>(reader));
        }
示例#20
0
        public static T Deserialize <T>(string yaml, bool ignoreUnmatchedProperties = true, IYamlTypeConverter converter = null)
        {
            using (StringReader reader = new StringReader(yaml))
            {
                DeserializerBuilder builder = new DeserializerBuilder();

                if (ignoreUnmatchedProperties)
                {
                    builder.IgnoreUnmatchedProperties();
                }

                if (converter != null)
                {
                    builder.WithTypeConverter(converter);
                }

                Deserializer deserializer = builder.Build();
                return(deserializer.Deserialize <T>(reader));
            }
        }
示例#21
0
 public static DeserializerBuilder WithIgnoreUnmatchedProperties(this DeserializerBuilder deserializerBuilder, bool ignoreUnmatchedProperties)
 {
     return(ignoreUnmatchedProperties
         ? deserializerBuilder.IgnoreUnmatchedProperties()
         : deserializerBuilder);
 }