源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

137 行
5.1 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEngine.UI;
  6. using System.IO;
  7. public class BatchModify
  8. {
  9. //要处理的目录
  10. private static string modify_path = "D:/_mrzj/develop/code/u3d/Assets/LuaFramework/AssetBundleRes/scene/terrain/map";
  11. static bool isChange = false;
  12. [MenuItem("MixTool/BatchModifyPrefab")]
  13. static void BatchModifyPrefab()
  14. {
  15. string[] cacheLog = { "已经处理的按钮记录:" };
  16. string[] curPrefabs = { "", "", "" };
  17. int startIndex = 0;
  18. string[] files = Directory.GetFiles(modify_path, "*.prefab", SearchOption.AllDirectories);
  19. EditorApplication.update = delegate ()
  20. {
  21. string filePath = GetRelativeAssetsPath(files[startIndex]);
  22. GameObject _prefab = AssetDatabase.LoadAssetAtPath(filePath, typeof(GameObject)) as GameObject;
  23. if (_prefab == null)
  24. {
  25. Debug.Log("该路径不能正常加载预制体 = >>> " + filePath);
  26. return;
  27. }
  28. GameObject find_obj = PrefabUtility.InstantiatePrefab(_prefab) as GameObject;
  29. if (find_obj == null)
  30. {
  31. Debug.Log("该路径不实例化预制体 = >>> " + filePath);
  32. return;
  33. }
  34. isChange = false;
  35. bool isCancel = EditorUtility.DisplayCancelableProgressBar(string.Format("资源处理中({0}/{1})", startIndex, files.Length), find_obj.name, (float)startIndex / (float)files.Length);
  36. CloseLightData(find_obj);
  37. //这里是修改带Text的RecTransform大小
  38. // ChangeTransformDeltaSize(find_obj.transform);
  39. if (isChange)
  40. {
  41. PrefabUtility.ReplacePrefab(find_obj, _prefab, ReplacePrefabOptions.Default);
  42. cacheLog[0] = CacheLog(cacheLog[0], "已经处理" + find_obj.gameObject.name, curPrefabs[0], find_obj.gameObject.name);
  43. }
  44. MonoBehaviour.DestroyImmediate(find_obj);
  45. startIndex++;
  46. if (isCancel || startIndex >= files.Length)
  47. {
  48. AssetDatabase.Refresh();
  49. AssetDatabase.SaveAssets();
  50. EditorUtility.ClearProgressBar();
  51. EditorApplication.update = null;
  52. startIndex = 0;
  53. Debug.Log("处理完成");
  54. foreach (var item in cacheLog)
  55. {
  56. Debug.Log(item);
  57. }
  58. }
  59. };
  60. }
  61. static private string CacheLog(string cacheLog, string log, string lastPrefab, string curPrefab)
  62. {
  63. string str = "";
  64. if (lastPrefab != curPrefab)
  65. {
  66. str = "\n\n[" + curPrefab + "]\n" + log;
  67. }
  68. else
  69. str = "\n" + log;
  70. str = cacheLog + str;
  71. return str;
  72. }
  73. static private string GetRelativeAssetsPath(string path)
  74. {
  75. return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
  76. }
  77. static private void ChangeTransformDeltaSize(Transform transform)
  78. {
  79. Text tx = transform.GetComponent<Text>();
  80. if (tx != null)
  81. {
  82. RectTransform rt = transform.GetComponent<RectTransform>();
  83. if (rt != null)
  84. {
  85. if (rt.sizeDelta.y > 20 && rt.sizeDelta.y < 30)
  86. {
  87. rt.sizeDelta = new Vector2(rt.sizeDelta.x, 30);
  88. isChange = true;
  89. Debug.Log("==>" + transform.name + " delta y = " + rt.sizeDelta);
  90. }
  91. }
  92. }
  93. int child_num = transform.childCount;
  94. if (child_num > 0)
  95. {
  96. for(int i = 0; i< child_num; ++i)
  97. {
  98. Transform temp_tf = transform.GetChild(i);
  99. if (temp_tf != null)
  100. {
  101. ChangeTransformDeltaSize(temp_tf);
  102. }
  103. }
  104. }
  105. }
  106. static private void CloseLightData(GameObject go)
  107. {
  108. MeshRenderer img2 = go.GetComponent<MeshRenderer>();
  109. if (img2 != null)
  110. {
  111. img2.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
  112. isChange = true;
  113. // 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)
  114. // {
  115. // img2.receiveShadows = false;
  116. // img2.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
  117. // img2.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
  118. // img2.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
  119. // img2.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
  120. // isChange = true;
  121. // }
  122. }
  123. }
  124. }