123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using LitJson;
- using System.IO;
- public class ImportMaterial : MonoBehaviour
- {
- static int id = 0;
- static int tempId = 0;
- static string notImportMat;
- static string savePath = "Assets/Bundles/Materials/";
- static string loadPath = "Assets/GameResources/d3Assets/cloth/texture/";
- static string json;
- [MenuItem("Tools/导入材质")]
- public static void Import()
- {
- json = File.ReadAllText("Assets/GameResources/d3Assets/cloth/DressItemConfig.txt");
- Data data = JsonMapper.ToObject<Data>(json);
- for (int i = 0; i < data.list.Count; i++)
- {
- if (data.list[i].dressType != 1)
- {
- continue;
- }
- if (data.list[i]._id / 10000 == 8)
- {
- id = data.list[i]._id;
- }
- else if (data.list[i]._id / 100000 == 1)
- {
- if (id != data.list[i]._id / 100 * 100 + 1)
- {
- id = data.list[i]._id / 100 * 100 + 1;
- }
- }
- else if (data.list[i]._id / 10000 == 31)
- {
- id = data.list[i]._id/10*10+1;
- }
- else
- {
- continue;
- }
- if (id == 0) continue;
- if (!File.Exists("Assets/GameResources/d3Assets/cloth/texture/" + id + "_" + data.list[i]._id + "_BaseMap.jpg"))
- {
- string fileName = id + "_" + data.list[i]._id;
- notImportMat += fileName + "_BaseMap\n" + fileName + "_MaskMap\n" + fileName + "_Normal\n";
- continue;
- }
- Texture2D baseMap = AssetDatabase.LoadAssetAtPath(loadPath + id + "_" + data.list[i]._id + "_BaseMap.jpg", typeof(Texture2D)) as Texture2D;
- Texture2D maskMap = AssetDatabase.LoadAssetAtPath(loadPath + id + "_" + data.list[i]._id + "_MaskMap.png", typeof(Texture2D)) as Texture2D;
- Texture2D normalMap = AssetDatabase.LoadAssetAtPath(loadPath + id + "_" + data.list[i]._id + "_Normal.png", typeof(Texture2D)) as Texture2D;
- Material material = new Material(Shader.Find("Universal Render Pipeline/Lit"));
- material.SetTexture("_BaseMap", baseMap);
- material.SetTexture("_DetailMask", maskMap);
- material.SetTexture("_DetailNormalMap", normalMap);
- AssetDatabase.CreateAsset(material, savePath + data.list[i]._id +"_mat"+ ".mat");
- }
- WriteTextFile("Assets/GameResources/d3Assets/cloth/NotImportMat.txt", notImportMat);
- // 刷新资源数据库
- AssetDatabase.Refresh();
- }
- //public static void LoadTexture(string path,out Texture2D texture)
- //{
- // Texture2D texture = new Texture2D(100,100);
- // byte[] imageData = File.ReadAllBytes(path);
- // texture.LoadImage(imageData);
- // Debug.LogWarning(texture.LoadImage(imageData));
- // //Debug.Log(texture.ToString());
- //}
- public static void WriteTextFile(string path, string text)
- {
- StreamWriter writer = new StreamWriter(path, false);
- writer.Write(text);
- writer.Close();
- Debug.Log("Text file written and saved at: " + path);
- }
- [MenuItem("Tools/丢失")]
- static void SaveName()
- {
- json = File.ReadAllText("Assets/GameResources/d3Assets/cloth/DressItemConfig.txt");
- Data data = JsonMapper.ToObject<Data>(json);
- for (int i = 0; i < data.list.Count; i++)
- {
- //if (data.list[i].dressType != 1)
- //{
- // continue;
- //}
- if (data.list[i]._id / 10000 == 8)
- {
- id = data.list[i]._id;
- }
- else if (data.list[i]._id / 100000 == 1)
- {
- if (id != data.list[i]._id / 100 * 100 + 1)
- {
- id = data.list[i]._id / 100 * 100 + 1;
- }
- }
- else if(data.list[i]._id / 10000 == 4)
- {
- id = data.list[i]._id;
- }
- else if (data.list[i].dressType == 3)
- {
- id = data.list[i]._id;
- }
- else if(data.list[i]._id / 10000 == 2)
- {
- continue;
- }
- else
- {
- id = data.list[i]._id;
- }
- switch (data.list[i].dressType)
- {
- case 1:
- if (!File.Exists("Assets/GameResources/d3Assets/cloth/texture/" + id + "_" + data.list[i]._id + "_BaseMap.jpg"))
- {
- notImportMat += $"{id}\n";
- }
- break;
- case 2:
- break;
- case 3:
- if (!File.Exists("Assets/GameResources/d3Assets/cloth/texture/" + id + ".jpg"))
- {
- notImportMat += $"{id}\n";
- }
- break;
- case 4:
- if (!File.Exists("Assets/GameResources/d3Assets/cloth/texture/" + id +"L.jpg"))
- {
- notImportMat += $"{id}\n";
- }
- break;
- case 5:
- if (!File.Exists("Assets/GameResources/d3Assets/cloth/texture/" + id + ".jpg"))
- {
- notImportMat += $"{id}\n";
- }
- break;
- }
- }
- WriteTextFile("Assets/GameResources/d3Assets/cloth/NotImportMat.txt", notImportMat);
- // 刷新资源数据库
- AssetDatabase.Refresh();
- }
- }
- public class Data
- {
- public List<DressItem> list;
- }
- public class DressItem
- {
- public int _id { get; set; }
- public int dressType { get; set; }
- }
|