源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 rivejä
24 KiB

4 viikkoa sitten
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6. using UnityEngine.UI;
  7. using LuaFramework;
  8. using System;
  9. using System.IO;
  10. using System.Collections;
  11. public class MixTool : MonoBehaviour
  12. {
  13. static List<string> files = new List<string>();
  14. static string destDir = "TextureNeedChange/texture/";
  15. static string cacheEffectFilePath = "TextureNeedChange/EffectPathCache.txt";
  16. static string cacheModelFilePath = "TextureNeedChange/ModelPathCache.txt";
  17. static string cacheSceneFilePath = "TextureNeedChange/ScenePathCache.txt";
  18. static string cacheIconFilePath = "TextureNeedChange/IconPathCache.txt";
  19. static Dictionary<string,string> cachePaths;
  20. static string[] allPath;
  21. static long startTimeMs = 0;
  22. static int startIndex = 0;
  23. static int count = 0;
  24. static List<string> prefabsPath;
  25. static public string GetCacheFilePath(string textureType)
  26. {
  27. string cacheFilePath = "";
  28. if(textureType == "effect")
  29. cacheFilePath = cacheEffectFilePath;
  30. if(textureType == "model")
  31. cacheFilePath = cacheModelFilePath;
  32. if(textureType == "scene")
  33. cacheFilePath = cacheSceneFilePath;
  34. if(textureType == "icon")
  35. cacheFilePath = cacheIconFilePath;
  36. return cacheFilePath;
  37. }
  38. static public void OnReadCachePath(string textureType)
  39. {
  40. string cacheFilePath = GetCacheFilePath(textureType);
  41. if (File.Exists(cacheFilePath))
  42. {
  43. cachePaths = new Dictionary<string,string>();
  44. var infoContent = File.ReadAllLines(cacheFilePath);
  45. foreach (var item in infoContent)
  46. {
  47. var kvParts = item.Split(',');
  48. cachePaths.Add(kvParts[0], kvParts[1]);
  49. }
  50. }
  51. }
  52. static public void OnWriteCachePath(string textureType)
  53. {
  54. string cacheFilePath = GetCacheFilePath(textureType);
  55. List<string> cacheList = new List<string>();
  56. foreach (var item in cachePaths)
  57. {
  58. cacheList.Add(item.Key+","+item.Value);
  59. }
  60. File.WriteAllLines(cacheFilePath, cacheList.ToArray());
  61. }
  62. static public string GetFileName(string filePath)
  63. {
  64. int pos = filePath.LastIndexOf("/");
  65. string fileName = "";
  66. if(pos > 0)
  67. {
  68. fileName = filePath.Remove(0, pos+1);
  69. // Debug.Log("fileName = " + fileName);
  70. }
  71. return fileName;
  72. }
  73. static void OnCopyTexture(string textTurePath, string textureType, int maxSize)
  74. {
  75. files.Clear();
  76. FindFileContentWithContain(textTurePath, ".meta", "tga");
  77. FindFileContentWithContain(textTurePath, ".meta", "png");
  78. FindFileContentWithContain(textTurePath, ".meta", "jpg");
  79. Dictionary<string, string> resList = new Dictionary<string, string>();
  80. cachePaths = new Dictionary<string,string>();
  81. for (int z = 0; z < files.Count; z++)
  82. {
  83. string filePath = files[z];
  84. filePath = filePath.Substring(0, filePath.Length - 5);
  85. filePath = filePath.Replace('\\', '/');
  86. bool is_tga = false;
  87. if (filePath.Contains(".tga"))
  88. {
  89. is_tga = true;
  90. }
  91. Texture2D t = LoadByIO(filePath);
  92. int curMinSize = t.width;
  93. if(t.height < curMinSize)
  94. curMinSize = t.height;
  95. if (is_tga || curMinSize > maxSize)
  96. {
  97. string fileName = GetFileName(filePath);
  98. string tempPath = GetParmPath(filePath, textureType);
  99. string parmPath = "/" + tempPath;
  100. string desFile = destDir + textureType + parmPath + fileName;
  101. string path = Path.GetDirectoryName(desFile);
  102. if (!Directory.Exists(path)) Directory.CreateDirectory(path);
  103. if (File.Exists(filePath))
  104. {
  105. cachePaths[fileName] = filePath;
  106. // Debug.Log("filePath = " + filePath);
  107. // Debug.Log("desFile = " + desFile);
  108. File.Copy(filePath, desFile, true);
  109. }
  110. }
  111. DestroyImmediate(t);
  112. }
  113. OnWriteCachePath(textureType);
  114. files.Clear();
  115. EditorUtility.DisplayDialog("提示", "抽取贴图完成", "确定");
  116. }
  117. static void OnPasteTexture(string textureType)
  118. {
  119. OnReadCachePath(textureType);
  120. foreach (var item in cachePaths)
  121. {
  122. string fileName = item.Key;
  123. string desFilePath = item.Value;
  124. string tempPath = GetParmPath(desFilePath, textureType);
  125. string parmPath = "/" + tempPath;
  126. string curFilePath = destDir + textureType + parmPath + fileName;
  127. if (File.Exists(curFilePath))
  128. {
  129. File.Copy(curFilePath, desFilePath, true);
  130. }
  131. }
  132. AssetDatabase.SaveAssets();
  133. AssetDatabase.Refresh();
  134. EditorUtility.DisplayDialog("提示", "替换贴图完成", "确定");
  135. }
  136. public static string GetParmPath(string filePath, string textureType)
  137. {
  138. string parmPath = "";
  139. if (textureType == "model")
  140. {
  141. // alphatexture后续要手动排查
  142. int alpha_name_pos = filePath.LastIndexOf("object/alphatexture");
  143. int role_name_pos = filePath.LastIndexOf("object/role");
  144. int pet_name_pos = filePath.LastIndexOf("object/pet");
  145. int mount_name_pos = filePath.LastIndexOf("object/mount");
  146. int npc_name_pos = filePath.LastIndexOf("object/npc");
  147. int boss_name_pos = filePath.LastIndexOf("object/monster/boss");
  148. // Debug.Log("filePath = " + filePath + alpha_name_pos +";" + role_name_pos +";" + pet_name_pos +";" + mount_name_pos +";" + boss_name_pos +";");
  149. if (alpha_name_pos>0 || role_name_pos>0 || pet_name_pos>0 || mount_name_pos>0 || npc_name_pos>0 || boss_name_pos>0)
  150. {
  151. parmPath = "512/";
  152. }
  153. else
  154. {
  155. parmPath = "256/";
  156. }
  157. }
  158. return parmPath;
  159. }
  160. public static Texture2D LoadByIO(string path) {
  161. float time = Time.time;
  162. FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
  163. fs.Seek(0, SeekOrigin.Begin);
  164. byte[] bytes = new byte[fs.Length];
  165. fs.Read(bytes, 0, (int)fs.Length);
  166. fs.Close();
  167. fs.Dispose();
  168. fs = null;
  169. Texture2D t = new Texture2D(1,1);
  170. t.LoadImage(bytes);
  171. return t;
  172. }
  173. // [MenuItem("MixTool/DeleteFile _F4", false, 150)]
  174. // public static void DeleteFile()
  175. // {
  176. // String path = AppConst.AppDataPath + "/Assets/LuaFramework/AssetBundleRes/ui/common/comon_delete";
  177. // var files = Directory.GetFiles(path, "*.png");
  178. // foreach (var file in files)
  179. // {
  180. // string path1 = file.Replace("comon_delete", "texture");
  181. // if (File.Exists(path1))
  182. // {
  183. // Debug.Log(path1);
  184. // File.Delete(path1);
  185. // }
  186. // }
  187. // EditorUtility.DisplayDialog("提示", "DeleteFile完成", "确定");
  188. // }
  189. public static void FindFileContentWithContain(string root_path, string extstr, string contain)
  190. {
  191. string[] names = Directory.GetFiles(root_path);
  192. string[] dirs = Directory.GetDirectories(root_path);
  193. foreach (string filename in names)
  194. {
  195. string ext = Path.GetExtension(filename);
  196. if (ext.Equals(extstr))
  197. {
  198. if (filename.Contains(contain))
  199. {
  200. files.Add(filename);
  201. }
  202. }
  203. }
  204. foreach (string dir in dirs)
  205. {
  206. FindFileContentWithContain(dir, extstr, contain);
  207. }
  208. }
  209. [MenuItem("MixTool/OptimizeBatch _F5", false, 151)]
  210. public static void OptimizeBatchForMenu()
  211. {
  212. OptimizeBatch(Selection.activeTransform);
  213. }
  214. public static void OptimizeBatch(Transform trans)
  215. {
  216. if (trans == null)
  217. return;
  218. Dictionary<string, List<Transform>> imageGroup = new Dictionary<string, List<Transform>>();
  219. Dictionary<string, List<Transform>> textGroup = new Dictionary<string, List<Transform>>();
  220. Dictionary<string, List<Transform>> tmpGroup = new Dictionary<string, List<Transform>>();
  221. List<List<Transform>> sortedImgageGroup = new List<List<Transform>>();
  222. List<List<Transform>> sortedTextGroup = new List<List<Transform>>();
  223. List<List<Transform>> sortedTMPGroup = new List<List<Transform>>();
  224. for (int i = 0; i < trans.childCount; i++)
  225. {
  226. Transform child = trans.GetChild(i);
  227. Texture cur_texture = null;
  228. Image img = child.GetComponent<Image>();
  229. if (img != null)
  230. {
  231. cur_texture = img.mainTexture;
  232. }
  233. else
  234. {
  235. RawImage rimg = child.GetComponent<RawImage>();
  236. if (rimg != null)
  237. cur_texture = rimg.mainTexture;
  238. }
  239. if (cur_texture != null)
  240. {
  241. string cur_path = AssetDatabase.GetAssetPath(cur_texture);
  242. TextureImporter importer = AssetImporter.GetAtPath(cur_path) as TextureImporter;
  243. // Debug.Log("cur_path : " + cur_path + " importer:"+(importer!=null).ToString());
  244. if (importer != null)
  245. {
  246. string atlas = importer.spritePackingTag;
  247. // Debug.Log("atlas : " + atlas);
  248. if (atlas != "")
  249. {
  250. if (!imageGroup.ContainsKey(atlas))
  251. {
  252. List<Transform> list = new List<Transform>();
  253. sortedImgageGroup.Add(list);
  254. imageGroup.Add(atlas, list);
  255. }
  256. imageGroup[atlas].Add(child);
  257. }
  258. }
  259. }
  260. else
  261. {
  262. Text text = child.GetComponent<Text>();
  263. if (text != null)
  264. {
  265. string fontName = text.font.name;
  266. //Debug.Log("fontName : " + fontName);
  267. if (!textGroup.ContainsKey(fontName))
  268. {
  269. List<Transform> list = new List<Transform>();
  270. sortedTextGroup.Add(list);
  271. textGroup.Add(fontName, list);
  272. }
  273. textGroup[fontName].Add(child);
  274. }
  275. else
  276. {
  277. TMPro.TextMeshProUGUI tmp = child.GetComponent<TMPro.TextMeshProUGUI>();
  278. if (tmp != null)
  279. {
  280. string fontName = tmp.font.name;
  281. //Debug.Log("fontName : " + fontName);
  282. if (!tmpGroup.ContainsKey(fontName))
  283. {
  284. List<Transform> list = new List<Transform>();
  285. sortedTMPGroup.Add(list);
  286. tmpGroup.Add(fontName, list);
  287. }
  288. tmpGroup[fontName].Add(child);
  289. }
  290. }
  291. }
  292. OptimizeBatch(child);
  293. }
  294. //同一图集的Image间层级顺序继续保留,不同图集的顺序就按每组第一张的来
  295. for (int i = sortedImgageGroup.Count - 1; i >= 0; i--)
  296. {
  297. List<Transform> children = sortedImgageGroup[i];
  298. for (int j = children.Count - 1; j >= 0; j--)
  299. {
  300. children[j].SetAsFirstSibling();
  301. }
  302. }
  303. foreach (var item in sortedTextGroup)
  304. {
  305. List<Transform> children = item;
  306. for (int i = 0; i < children.Count; i++)
  307. {
  308. children[i].SetAsLastSibling();
  309. }
  310. }
  311. foreach (var item in sortedTMPGroup)
  312. {
  313. List<Transform> children = item;
  314. for (int i = 0; i < children.Count; i++)
  315. {
  316. children[i].SetAsLastSibling();
  317. }
  318. }
  319. }
  320. [MenuItem("MixTool/" + "effect - 抽取特效贴图")]
  321. static void CopyEffectTexture()
  322. {
  323. string textTurePath = "Assets/LuaFramework/AssetBundleRes/scene/effect/texture";
  324. string textureType = "effect";
  325. int maxSize = 256;
  326. OnCopyTexture(textTurePath, textureType, maxSize);
  327. }
  328. [MenuItem("MixTool/" + "effect - 替换特效贴图")]
  329. static void PasteEffectTexture()
  330. {
  331. OnPasteTexture("effect");
  332. }
  333. [MenuItem("MixTool/" + "model - 抽取模型贴图")]
  334. static void CopyModelTexture()
  335. {
  336. string textTurePath = "Assets/LuaFramework/AssetBundleRes/scene/object";
  337. string textureType = "model";
  338. int maxSize = 256;
  339. OnCopyTexture(textTurePath, textureType, maxSize);
  340. }
  341. [MenuItem("MixTool/" + "model - 替换模型贴图")]
  342. static void PasteModelTexture()
  343. {
  344. OnPasteTexture("model");
  345. }
  346. [MenuItem("MixTool/" + "scene - 抽取场景贴图")]
  347. static void CopySceneTexture()
  348. {
  349. // string textTurePath = "Assets/LuaFramework/AssetBundleRes/scene/terrain";
  350. string textTurePath = "Assets/LuaFramework/AssetBundleRes/scene/terrain/map/1003_new/Textures";
  351. string textureType = "scene";
  352. int maxSize = 512;
  353. OnCopyTexture(textTurePath, textureType, maxSize);
  354. }
  355. [MenuItem("MixTool/" + "scene - 替换场景贴图")]
  356. static void PasteSceneTexture()
  357. {
  358. OnPasteTexture("scene");
  359. }
  360. [MenuItem("MixTool/" + "scene - 抽取icon贴图")]
  361. static void CopyIconTexture()
  362. {
  363. string textTurePath = "Assets/LuaFramework/AssetBundleRes/icon";
  364. string textureType = "icon";
  365. int maxSize = 1024;
  366. OnCopyTexture(textTurePath, textureType, maxSize);
  367. }
  368. [MenuItem("MixTool/" + "测试信息 ")]
  369. static void TestInfo()
  370. {
  371. // GameObject[] tempObject;
  372. // if (Selection.activeGameObject)
  373. // {
  374. // tempObject = Selection.gameObjects;
  375. // for (int i = 0; i < tempObject.Length; i++)
  376. // {
  377. // Debug.Log("Object name: " + tempObject[i].name);
  378. // Debug.Log("Lightmaping Index: " + tempObject[i].GetComponent<MeshRenderer>().lightmapIndex);
  379. // Debug.Log("Lightmaping Offset: " + tempObject[i].GetComponent<MeshRenderer>().lightmapScaleOffset);
  380. // }
  381. // }
  382. string filePath = "object/texture/talisman/res/model_talisman_1003/model/model_talisman_1003_mask.jpg";
  383. int pos = filePath.LastIndexOf('/');
  384. string fileName = "";
  385. if(pos > 0)
  386. {
  387. fileName = filePath.Remove(0, pos+1);
  388. Debug.Log("fileName = " + fileName);
  389. }
  390. }
  391. [MenuItem("MixTool/" + "ResetTerrainLayer ")]
  392. static void ResetTerrainLayer()
  393. {
  394. Time.timeScale = 1;
  395. List<string> prefabsPath = new List<string>();
  396. string path = "Assets/LuaFramework/AssetBundleRes/scene/terrain/map/";
  397. //string path = "Assets/LuaFramework/AssetBundleRes/scene/terrain/map/1001_new/";
  398. allPath = Directory.GetFiles(path, "*prefab*", SearchOption.AllDirectories);
  399. EditorApplication.update += EditorUpdateLayer;
  400. }
  401. public static void EditorUpdateLayer()
  402. {
  403. long curTimeMs = GetTimeMs();
  404. //Debug.Log("curTimeMs = " + curTimeMs);
  405. if (Math.Abs(curTimeMs - startTimeMs) >= 0.1*1000)
  406. {
  407. string filePath = allPath[startIndex];
  408. if (filePath.EndsWith(".prefab"))
  409. {
  410. GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(filePath);
  411. if (prefab)
  412. {
  413. startTimeMs = GetTimeMs();
  414. //Debug.Log("prefab.name = " + prefab.name + ",prefab.layer = " + prefab.layer);
  415. if (prefab.layer == 0)
  416. {
  417. count++;
  418. SetSceneObjLayer(prefab, 30);
  419. AssetDatabase.SaveAssets();
  420. }
  421. }
  422. }
  423. bool isCancel = EditorUtility.DisplayCancelableProgressBar(string.Format("资源处理中({0}/{1})", startIndex, allPath.Length), filePath, (float)startIndex / (float)allPath.Length);
  424. startIndex++;
  425. if (isCancel || startIndex >= allPath.Length)
  426. {
  427. AssetDatabase.Refresh();
  428. AssetDatabase.SaveAssets();
  429. EditorUtility.ClearProgressBar();
  430. EditorApplication.update = null;
  431. Debug.Log("处理完成, 处理数量:"+ count);
  432. startIndex = 0;
  433. count = 0;
  434. }
  435. }
  436. }
  437. public static void SetSceneObjLayer(GameObject obj, int layer)
  438. {
  439. obj.layer = layer;
  440. if (obj.transform.childCount <= 0)
  441. {
  442. return;
  443. }
  444. foreach (Transform child in obj.transform)
  445. {
  446. SetSceneObjLayer(child.gameObject, layer);
  447. }
  448. }
  449. public static long GetTimeMs()
  450. {
  451. long currentTicks = DateTime.Now.Ticks;
  452. DateTime dtFrom = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  453. long currentMillis = (currentTicks - dtFrom.Ticks) / 10000;
  454. return currentMillis;
  455. }
  456. [MenuItem("MixTool/" + "CloseLightData ")]
  457. static void CloseLightData()
  458. {
  459. startIndex = 0;
  460. count = 0;
  461. Time.timeScale = 1;
  462. prefabsPath = new List<string>();
  463. //string path = "Assets/LuaFramework/AssetBundleRes/scene/object";
  464. //var files = Directory.GetFiles(path, "*prefab*", SearchOption.AllDirectories);
  465. //foreach (var file in files)
  466. //{
  467. // if (file.EndsWith(".prefab"))
  468. // {
  469. // prefabsPath.Add(file);
  470. // }
  471. //}
  472. //string path = "Assets/LuaFramework/AssetBundleRes/scene/effect/objs";
  473. //var files = Directory.GetFiles(path, "*prefab*", SearchOption.AllDirectories);
  474. //foreach (var file in files)
  475. //{
  476. // if (file.EndsWith(".prefab"))
  477. // {
  478. // prefabsPath.Add(file);
  479. // }
  480. //}
  481. string path = "Assets/LuaFramework/AssetBundleRes/scene/terrain/map/";
  482. //string path = "Assets/LuaFramework/AssetBundleRes/scene/terrain/map/1001_new";
  483. var files = Directory.GetFiles(path, "*prefab*", SearchOption.AllDirectories);
  484. foreach (var file in files)
  485. {
  486. if (file.EndsWith(".prefab"))
  487. {
  488. prefabsPath.Add(file);
  489. }
  490. }
  491. allPath = prefabsPath.ToArray();
  492. EditorApplication.update += EditorUpdateLightData;
  493. }
  494. public static void EditorUpdateLightData()
  495. {
  496. long curTimeMs = GetTimeMs();
  497. //Debug.Log("curTimeMs = " + curTimeMs);
  498. if (Math.Abs(curTimeMs - startTimeMs) >= 0.1 * 1000)
  499. {
  500. string singlePaht = allPath[startIndex];
  501. int map_1000_index = singlePaht.LastIndexOf("map/1000");
  502. if (map_1000_index <= 0 )
  503. {
  504. var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(singlePaht);
  505. if (prefab)
  506. {
  507. startTimeMs = GetTimeMs();
  508. CheckSingPrefab(prefab);
  509. AssetDatabase.SaveAssets();
  510. }
  511. }
  512. bool isCancel = EditorUtility.DisplayCancelableProgressBar(string.Format("资源处理中({0}/{1})", startIndex, allPath.Length), singlePaht, (float)startIndex / (float)allPath.Length);
  513. startIndex++;
  514. if (isCancel || startIndex >= allPath.Length)
  515. {
  516. AssetDatabase.Refresh();
  517. AssetDatabase.SaveAssets();
  518. EditorUtility.ClearProgressBar();
  519. EditorApplication.update = null;
  520. Debug.Log("处理完成, 处理数量:" + count);
  521. startIndex = 0;
  522. count = 0;
  523. }
  524. }
  525. }
  526. public static void CheckSingPrefab(GameObject go)
  527. {
  528. CheckSingGameObject(go);
  529. foreach (Transform child in go.transform)
  530. {
  531. if (child.childCount > 0)
  532. {
  533. CheckSingPrefab(child.gameObject);
  534. }
  535. CheckSingGameObject(child.gameObject);
  536. }
  537. }
  538. public static void CheckSingGameObject(GameObject go)
  539. {
  540. var img = go.GetComponentInChildren<SkinnedMeshRenderer>();
  541. if (img != null)
  542. {
  543. if (img.receiveShadows || img.lightProbeUsage != UnityEngine.Rendering.LightProbeUsage.Off || img.reflectionProbeUsage != UnityEngine.Rendering.ReflectionProbeUsage.Off || img.shadowCastingMode != UnityEngine.Rendering.ShadowCastingMode.Off || img.motionVectorGenerationMode != MotionVectorGenerationMode.ForceNoMotion || img.skinnedMotionVectors == true)
  544. {
  545. img.receiveShadows = false;
  546. img.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
  547. img.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
  548. img.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
  549. img.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
  550. img.skinnedMotionVectors = false;
  551. count++;
  552. }
  553. }
  554. else
  555. {
  556. var img2 = go.GetComponentInChildren<MeshRenderer>();
  557. if (img2 != null)
  558. {
  559. if (img2.receiveShadows || img2.lightProbeUsage != UnityEngine.Rendering.LightProbeUsage.Off || img2.reflectionProbeUsage != UnityEngine.Rendering.ReflectionProbeUsage.Off || img2.shadowCastingMode != UnityEngine.Rendering.ShadowCastingMode.Off || img2.motionVectorGenerationMode != MotionVectorGenerationMode.ForceNoMotion)
  560. {
  561. img2.receiveShadows = false;
  562. img2.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
  563. img2.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
  564. img2.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
  565. img2.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
  566. count++;
  567. }
  568. }
  569. }
  570. }
  571. [MenuItem("MixTool/" + "ResetAlphaMaterial-1001 ")]
  572. public static void ResetAlphaMaterial()
  573. {
  574. Dictionary<string, string> path = new Dictionary<string, string>();
  575. path.Add("special/XSCCZ_CWJ01_11_Alpha", "XSCCZ_CWJ01_01_D2_ALPHA.mat");
  576. path.Add("special/XSCCZ_CWJ01_12_Alpha", "XSCCZ_CWJ01_02_ALPHA.mat");
  577. path.Add("special/XSCCZ_CWJ01_08_Alpha", "XSCCZ_CWJ01_02_ALPHA.mat");
  578. path.Add("special/XSCCZ_CWJ01_01_Alpha", "XSCCZ_CWJ01_01_D_ALPHA.mat");
  579. path.Add("special/XSCCZ_JZ01_02_Alpha", "XSCCZ_JZ01_01_ALPHA.mat");
  580. path.Add("special/XSCCZ_JZ02_01_Alpha", "XSCCZ_JZ02_01_ALPHA.mat");
  581. path.Add("special/XSCCZ_WJ03_05_Alpha", "XSCCZ_WJ03_01_ALPHA.mat");
  582. path.Add("special/XSCCZ_WJ02_07_Alpha", "XSCCZ_WJ02_01_ALPHA.mat");
  583. path.Add("special/XSCCZ_CWJ01_13_Alpha", "XSCCZ_CWJ01_01_D2_ALPHA.mat");
  584. foreach (var item in path)
  585. {
  586. string prefab_path = item.Key;
  587. var obj = GameObject.Find(prefab_path);
  588. Debug.Log("obj = " + obj);
  589. if(obj)
  590. {
  591. MeshRenderer render = obj.GetComponent<MeshRenderer>();
  592. Debug.Log("render = " + render);
  593. if (render)
  594. {
  595. string root_path = "Assets/LuaFramework/AssetBundleRes/scene/terrain/map/1001_new/Materials/";
  596. string mat_path = root_path + item.Value;
  597. Debug.Log("mat_path = " + mat_path);
  598. var mat = AssetDatabase.LoadAssetAtPath<Material>(mat_path);
  599. if(mat)
  600. {
  601. Debug.Log("mat = " + mat);
  602. render.material = mat;
  603. }
  604. }
  605. }
  606. AssetDatabase.Refresh();
  607. AssetDatabase.SaveAssets();
  608. }
  609. }
  610. }
  611. #endif