EditorManipulator.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. [ExecuteInEditMode]
  6. public class EditorManipulator : MonoBehaviour
  7. {
  8. public void SetEnableColliders(bool enabled)
  9. {
  10. Collider[] colls = GetComponentsInChildren<Collider>();
  11. foreach(Collider c in colls)
  12. {
  13. c.enabled = enabled;
  14. }
  15. Debug.LogFormat("set {0} colliders", colls.Length);
  16. }
  17. public void SetEnableMeshRenderer(bool enabled)
  18. {
  19. MeshRenderer[] meshs = GetComponentsInChildren<MeshRenderer>();
  20. foreach(MeshRenderer m in meshs)
  21. {
  22. m.enabled = enabled;
  23. }
  24. Debug.LogFormat("set {0} meshs", meshs.Length);
  25. }
  26. }
  27. [CustomEditor(typeof(EditorManipulator))] //1
  28. public class EditorManipulatorEditor : Editor
  29. {
  30. // OnInspector GUI
  31. public override void OnInspectorGUI() //2
  32. {
  33. base.DrawDefaultInspector();
  34. EditorManipulator script = (EditorManipulator)target;
  35. if (GUILayout.Button("Enable colliders")) //8
  36. {
  37. script.SetEnableColliders(true);
  38. }
  39. if (GUILayout.Button("Disable colliders")) //8
  40. {
  41. script.SetEnableColliders(false);
  42. }
  43. if(GUILayout.Button("Enable Meshs"))
  44. {
  45. script.SetEnableMeshRenderer(true);
  46. }
  47. if(GUILayout.Button("Disable Meshs"))
  48. {
  49. script.SetEnableMeshRenderer(false);
  50. }
  51. }
  52. }