12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEngine;
- [ExecuteInEditMode]
- public class EditorManipulator : MonoBehaviour
- {
- public void SetEnableColliders(bool enabled)
- {
- Collider[] colls = GetComponentsInChildren<Collider>();
- foreach(Collider c in colls)
- {
- c.enabled = enabled;
- }
- Debug.LogFormat("set {0} colliders", colls.Length);
- }
- public void SetEnableMeshRenderer(bool enabled)
- {
- MeshRenderer[] meshs = GetComponentsInChildren<MeshRenderer>();
- foreach(MeshRenderer m in meshs)
- {
- m.enabled = enabled;
- }
- Debug.LogFormat("set {0} meshs", meshs.Length);
- }
- }
- [CustomEditor(typeof(EditorManipulator))] //1
- public class EditorManipulatorEditor : Editor
- {
- // OnInspector GUI
- public override void OnInspectorGUI() //2
- {
- base.DrawDefaultInspector();
- EditorManipulator script = (EditorManipulator)target;
- if (GUILayout.Button("Enable colliders")) //8
- {
- script.SetEnableColliders(true);
- }
- if (GUILayout.Button("Disable colliders")) //8
- {
- script.SetEnableColliders(false);
- }
- if(GUILayout.Button("Enable Meshs"))
- {
- script.SetEnableMeshRenderer(true);
- }
- if(GUILayout.Button("Disable Meshs"))
- {
- script.SetEnableMeshRenderer(false);
- }
- }
- }
|