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.
 
 
 

114 lines
4.3 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. using UnityEngine.UI;
  5. using System.IO;
  6. using System.Collections.Generic;
  7. using System.Text.RegularExpressions;
  8. using System;
  9. using System.Linq;
  10. [CustomEditor(typeof(PrefabsTools))]
  11. public class PrefabsTools : ScriptableWizard
  12. {
  13. [UnityEditor.MenuItem("Tools/Apply Selected Prefabs")]
  14. static void ApplySelectedPrefabs()
  15. {
  16. //获取选中的gameobject对象
  17. GameObject[] selectedsGameobject = Selection.gameObjects;
  18. for (int i = 0; i < selectedsGameobject.Length; i++)
  19. {
  20. GameObject obj = selectedsGameobject[i];
  21. UnityEngine.Object newsPref = PrefabUtility.GetPrefabObject(obj);
  22. //判断选择的物体,是否为预设
  23. if (PrefabUtility.GetPrefabType(obj) == PrefabType.PrefabInstance)
  24. {
  25. UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(obj);
  26. //获取路径
  27. //string path = AssetDatabase.GetAssetPath(parentObject);
  28. //Debug.Log("path:"+path);
  29. //替换预设
  30. PrefabUtility.ReplacePrefab(obj, parentObject, ReplacePrefabOptions.ConnectToPrefab);
  31. //刷新
  32. AssetDatabase.Refresh();
  33. }
  34. }
  35. }
  36. [UnityEditor.MenuItem("Tools/SetAllChild")]
  37. static void SetAllChild()
  38. {
  39. GameObject terrain = GameObject.Find("StaticEnvironment");
  40. SetAllChild(terrain.transform);
  41. }
  42. static void SetAllChild(Transform tf)
  43. {
  44. List<string> ls = new List<string>() { "Building", "road", "ISLAND", "Island", "dirt", "SeaBottom", "pavement", "GrassTerrain", "BigMountain", "tunnel", "skaly", "t20", "pesok", "beach", "Borders", "t33", "MilitaryBase", "Pavements", "t30", "t32", "t17", "Steps", "Roof", "Obelisk", "piramid", "SphereHolder","WireObject", "Concrete_Roadblock","Pavement", "otboy","BridgeSideBlock", /*"road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road","road", "road",*/ };
  45. foreach (var mc in tf.GetComponentsInChildren<MeshCollider>(true))
  46. {
  47. MeshFilter mf = mc.GetComponent<MeshFilter>();
  48. if (mf != null)
  49. {
  50. bool b = true;
  51. foreach (var lss in ls)
  52. {
  53. if (mf.name.Contains(lss))
  54. {
  55. b = false;
  56. }
  57. }
  58. if (b)
  59. {
  60. continue;
  61. }
  62. }
  63. else
  64. {
  65. continue;
  66. }
  67. if (mc.transform.localScale.x < 0 && mc.transform.localScale.y < 0 && mc.transform.localScale.z < 0)
  68. {
  69. mc.transform.localScale = new Vector3(-mc.transform.localScale.x, -mc.transform.localScale.y, -mc.transform.localScale.z);
  70. GameObject go = new GameObject();
  71. go.transform.parent = mc.transform;
  72. go.transform.localPosition = Vector3.zero;
  73. go.transform.localEulerAngles = Vector3.zero;
  74. go.transform.localScale = new Vector3(-1, -1, -1);
  75. go.layer = mc.gameObject.layer;
  76. UnityEditorInternal.ComponentUtility.CopyComponent(mc);
  77. UnityEditorInternal.ComponentUtility.PasteComponentAsNew(go);
  78. GameObject.DestroyImmediate(mc);
  79. }
  80. }
  81. }
  82. [UnityEditor.MenuItem("Tools/SetAllChild222222")]
  83. static void SetAllChild2222222222()
  84. {
  85. GameObject terrain = GameObject.Find("StaticEnvironment");
  86. SetAllChild2222222222(terrain.transform);
  87. }
  88. static void SetAllChild2222222222(Transform tf)
  89. {
  90. foreach (var mc in tf.GetComponentsInChildren<MeshCollider>(true))
  91. {
  92. MeshFilter mf = mc.GetComponent<MeshFilter>();
  93. if (mf == null)
  94. {
  95. continue;
  96. }
  97. if (mc.transform.localScale.x < 0 && mc.transform.localScale.y < 0 && mc.transform.localScale.z < 0)
  98. {
  99. Debug.LogError( mc.name);
  100. }
  101. }
  102. }
  103. }