private static void GenerateExtension() { IDictionary <string, DataTableProcessor.DataProcessor> datableDataProcessors = new SortedDictionary <string, DataTableProcessor.DataProcessor>(); IDictionary <string, DataTableProcessor.DataProcessor> binaryReaderDataProcessors = new SortedDictionary <string, DataTableProcessor.DataProcessor>(); var dataProcessorBaseType = typeof(DataTableProcessor.DataProcessor); var types = GetTypeNames(dataProcessorBaseType); for (var i = 0; i < types.Count; i++) { if (!types[i].IsClass || types[i].IsAbstract || types[i].ContainsGenericParameters) { continue; } if (dataProcessorBaseType.IsAssignableFrom(types[i])) { DataTableProcessor.DataProcessor dataProcessor = null; dataProcessor = (DataTableProcessor.DataProcessor)Activator.CreateInstance(types[i]); if (dataProcessor.IsComment || dataProcessor.IsId || dataProcessor.IsEnum) { continue; } datableDataProcessors.Add(dataProcessor.LanguageKeyword, dataProcessor); } } AddEnumType(datableDataProcessors); NameSpaces.Add("System"); NameSpaces.Add("System.IO"); NameSpaces.Add("System.Collections.Generic"); NameSpaces.Add("UnityEngine"); NameSpaces = NameSpaces.Distinct().ToList(); GenerateDataTableExtensionArray(datableDataProcessors); GenerateDataTableExtensionList(datableDataProcessors); GenerateBinaryReaderExtensionList(datableDataProcessors); GenerateBinaryReaderExtensionArray(datableDataProcessors); GenerateDataTableExtensionDictionary(datableDataProcessors); GenerateBinaryReaderExtensionDictionary(datableDataProcessors); AssetDatabase.Refresh(); }
private static void GenerateExtensionByAnalysis() { List <string> types = new List <string>(32); foreach (var dataTableFileName in DataTableConfig.DataTablePaths) { var lines = File.ReadAllLines(dataTableFileName, Encoding.UTF8); var rawRowCount = lines.Length; var rawColumnCount = 0; var rawValues = new List <string[]>(); for (var i = 0; i < lines.Length; i++) { var rawValue = lines[i].Split('\t'); for (var j = 0; j < rawValue.Length; j++) { rawValue[j] = rawValue[j].Trim('\"'); } if (i == 0) { rawColumnCount = rawValue.Length; } else if (rawValue.Length != rawColumnCount) { throw new GameFrameworkException(Utility.Text.Format( "Data table file '{0}', raw Column is '{2}', but line '{1}' column is '{3}'.", dataTableFileName, i.ToString(), rawColumnCount.ToString(), rawValue.Length.ToString())); } rawValues.Add(rawValue); } types.AddRange(rawValues.ToArray()[2]); types = types.Distinct().ToList(); } types.Remove("Id"); types.Remove("#"); types.Remove(""); types.Remove("comment"); List <DataTableProcessor.DataProcessor> datableDataProcessors = types.Select(DataTableProcessor.DataProcessorUtility.GetDataProcessor).ToList(); NameSpaces.Add("System"); NameSpaces.Add("System.IO"); NameSpaces.Add("System.Collections.Generic"); NameSpaces.Add("UnityEngine"); NameSpaces = NameSpaces.Distinct().ToList(); var dataProcessorsArray = datableDataProcessors .Where(_ => _.LanguageKeyword.ToLower().EndsWith("[]")) .Select(_ => DataTableProcessor.DataProcessorUtility.GetDataProcessor(_.LanguageKeyword.ToLower() .Replace("[]", ""))) .ToDictionary(_ => _.LanguageKeyword, _ => _); var dataProcessorsList = datableDataProcessors .Where(_ => _.LanguageKeyword.ToLower().StartsWith("list")) .Select(_ => DataTableProcessor.DataProcessorUtility.GetDataProcessor(_.LanguageKeyword.ToLower() .Replace("list", "").Replace("<", "").Replace(">", ""))) .ToDictionary(_ => _.LanguageKeyword, _ => _); var dataProcessorsDictionary = datableDataProcessors .Where(_ => _.LanguageKeyword.ToLower().StartsWith("dictionary")) .Select(_ => { var keyValue = _.LanguageKeyword.ToLower() .Replace("dictionary", "").Replace("<", "").Replace(">", "").Split(','); return(new[] { DataTableProcessor.DataProcessorUtility.GetDataProcessor(keyValue[0]), DataTableProcessor.DataProcessorUtility.GetDataProcessor(keyValue[1]) }); } ).ToList(); if (dataProcessorsArray.Count > 0) { GenerateDataTableExtensionArray(dataProcessorsArray); GenerateBinaryReaderExtensionArray(dataProcessorsArray); } if (dataProcessorsList.Count > 0) { GenerateDataTableExtensionList(dataProcessorsList); GenerateBinaryReaderExtensionList(dataProcessorsList); } if (dataProcessorsDictionary.Count > 0) { GenerateDataTableExtensionDictionary(dataProcessorsDictionary); GenerateBinaryReaderExtensionDictionary(dataProcessorsDictionary); } AssetDatabase.Refresh(); }