/// <summary> /// 根据灯具名称开始加载配置信息 /// </summary> public void LoadConfig() { // 如果 fixtureName 为空 或者 Dictionary 中没有该灯具信息 则跳出函数 if (gdtfFileName == null || gdtfFileName == string.Empty) { return; } if (!GDTF_ResourcesLoader.GetFixtures().ContainsKey(gdtfFileName)) { return; } // 获取该灯具的所有资源文件信息 fileInfo = GDTF_ResourcesLoader.GetFileInfo(gdtfFileName); // 添加灯具缩略图 fixtureThumbanil = Resources.Load <Texture2D>(fileInfo.thumbnail.filePath); // 添加灯具灯库信息 descriptionData = GDTF_DescriptionReader.GetGdtfData(fileInfo.description.filePath); // 添加灯具基本信息 model = descriptionData.fixtureType.ShortName; gdtfDataVer = descriptionData.fixtureType.GDTFDataVersion; fixtureType = descriptionData.fixtureType.FixtureType; fixtureTypeID = descriptionData.fixtureType.FixtureTypeID; manufacturer = descriptionData.fixtureType.Manufacturer; descriptionData.dmxModes.ForEach(mode => { if (mode.dmxModeName == dmxModeName) { dmxMode = mode; } }); if (goboTextures.Count > 0) { goboTextures.Clear(); } for (int i = 0; i < fileInfo.wheels.Length; i++) { goboTextures.Add(fileInfo.wheels[i].fileName, Resources.Load <Texture2D>(fileInfo.wheels[i].filePath)); } }
public static void UnZipAllGdtf() { // 如果该路径存在 if (Directory.Exists(path)) { // 获取文件夹信息 DirectoryInfo direction = new DirectoryInfo(path); // 获取该路径下所有后缀名为 .gdtf 文件 FileInfo[] gdtfFiles = direction.GetFiles("*.gdtf", SearchOption.AllDirectories); Debug.LogWarning($"Find {gdtfFiles.Length} GDTF Files!"); // 存放所有 GDTF 资源文件索引信息 List <GDTF_FileInfo> fileInfos = new List <GDTF_FileInfo>(); for (int i = 0; i < gdtfFiles.Length; i++) { GDTF_FileInfo resInfo = new GDTF_FileInfo(); // 截取 GDTF 文件名(不包含扩展名) string gdtfFileName = Path.GetFileNameWithoutExtension(gdtfFiles[i].ToString()); // GDTF 文件绝对路径 string gdtfPath = gdtfFiles[i].ToString(); // 目标解压缩路径 string unZipPath = path + "GDTF_Unzip/" + gdtfFileName + "/"; // 解压 GDTF 文件到指定目录 if (!UnzipGDTF(gdtfPath, unZipPath)) { Debug.Log($"UnZip GDTF File :{gdtfFiles[i].Name} Error!!!"); continue; } resInfo.name = gdtfFileName; // 开始索引解压目录下的资源文件 DirectoryInfo unZipPathInfo = new DirectoryInfo(unZipPath); if (unZipPathInfo.Exists) { // 查找 xml 配置文件以及缩略图 foreach (var item in unZipPathInfo.GetFiles("*", SearchOption.TopDirectoryOnly)) { if (item.Extension.Equals(".png", StringComparison.OrdinalIgnoreCase)) { resInfo.thumbnail = new FileNameAndPath(Path.GetFileNameWithoutExtension(item.Name), ResourcesApiPath(item)); } if (item.Name.Equals("description.xml", StringComparison.OrdinalIgnoreCase)) { resInfo.description = new FileNameAndPath(Path.GetFileNameWithoutExtension(item.Name), item.ToString()); } } // 查找 Wheel 图片以及 Model 模型 foreach (var item in unZipPathInfo.GetDirectories()) { if (item.Name.Equals("wheels", StringComparison.OrdinalIgnoreCase)) { List <FileNameAndPath> wheelsNameAndPath = new List <FileNameAndPath>(); foreach (var wheel in item.GetFiles("*.png", SearchOption.AllDirectories)) { string asstePath = AssetImpoterApiPath(wheel); TextureImporter texture = AssetImporter.GetAtPath(asstePath) as TextureImporter; if (texture != null) { texture.textureType = TextureImporterType.Cookie; texture.alphaSource = TextureImporterAlphaSource.FromGrayScale; texture.wrapMode = TextureWrapMode.Clamp; AssetDatabase.ImportAsset(asstePath); } wheelsNameAndPath.Add(new FileNameAndPath(Path.GetFileNameWithoutExtension(wheel.Name), ResourcesApiPath(wheel))); } resInfo.wheels = wheelsNameAndPath.ToArray(); } if (item.Name.Equals("models", StringComparison.OrdinalIgnoreCase)) { List <FileNameAndPath> modelsNameAndPath = new List <FileNameAndPath>(); foreach (var model in item.GetFiles("*.3ds", SearchOption.AllDirectories)) { modelsNameAndPath.Add(new FileNameAndPath(Path.GetFileNameWithoutExtension(model.Name), ResourcesApiPath(model))); } resInfo.models = modelsNameAndPath.ToArray(); } } } fileInfos.Add(resInfo); } // 将对象转换成 JSON 格式别生成文件 GDTF_ResourcesFiles resourcesFiles = new GDTF_ResourcesFiles() { Fixtures = fileInfos.ToArray() }; string json = JsonUtility.ToJson(resourcesFiles); File.WriteAllText("Assets/eDmx.ArtNet/Resources/GDTF_Configs/" + configFileName, json); } AssetDatabase.Refresh(); GDTF_ResourcesLoader.LoadGdtfResourcesFiles(); }