コード例 #1
0
        private static void ProcessConfigConvert(string fileName)
        {
            string configName = Path.GetFileNameWithoutExtension(fileName);

            if (string.IsNullOrEmpty(configName))
            {
                return;
            }
            // 转换为二进制文件
            FileStream srcStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            try {
                if (srcStream.Length <= 0)
                {
                    return;
                }
                byte[] buffer = new byte[srcStream.Length];
                if (buffer == null || buffer.Length <= 0)
                {
                    return;
                }
                srcStream.Read(buffer, 0, buffer.Length);
                string json = System.Text.Encoding.UTF8.GetString(buffer);
                if (string.IsNullOrEmpty(json))
                {
                    return;
                }
                ConfigConvertManager.ConvertToBinaryFile(fileName, configName, json);
            } finally {
                srcStream.Close();
                srcStream.Dispose();
            }

            AssetDatabase.Refresh();
        }
コード例 #2
0
        public static void TestReadConfig()
        {
            TextAsset asset = (Selection.activeObject as TextAsset);

            if (asset == null)
            {
                return;
            }
            byte[] buffer = asset.bytes;
            if (buffer == null || buffer.Length <= 0)
            {
                return;
            }

            string fileName = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            string configName = Path.GetFileNameWithoutExtension(fileName);

            ConfigConvertManager.BuildConfigConvert();
            var info = ConfigConvertManager.GetTargetConvert(configName);

            if (info == null)
            {
                return;
            }

            IDictionary map = ConfigWrap.TestCommonToObject(buffer, info.type, info.DictionaryType, true);

            if (map != null)
            {
                Debug.Log("二进制配置读取正确");
            }
            else
            {
                Debug.LogError("二进制配置读取错误");
            }
        }
コード例 #3
0
 public static void TestBuildConfigConvertMap()
 {
     ConfigConvertManager.BuildConfigConvert();
 }