using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using XericLibrary.Runtime.MacroLibrary; using XericLibrary.Runtime.Type; namespace XericLibrary.Runtime.Generation { /// /// 生成节点纯方法 /// public class GenMethod : BaseGenerate { public string NewNodeName = "GEN_NODE_METHOD"; } #if UNITY_EDITOR [CustomEditor(typeof(GenMethod))] public class GenMethodEditor : BaseGenerateEditor { public override void OnInspectorGUI() { base.OnInspectorGUI(); var script = (GenMethod)target; // 在Inspector窗口上显示按钮 if(GUILayout.Button($"复制所有碰撞体到{script.NewNodeName}")) GenMethod.CopyComponentToNew(script.gameObject, out var outobj); if(GUILayout.Button("销毁所有渲染组件")) DestroyAllMesh(script.transform); } /// /// 销毁所有模型组件 /// public void DestroyAllMesh(Transform transform) { MeshFilter fl = null; MeshRenderer mr; Action destroycomponent = comp => { #if UNITY_EDITOR if(fl != null) DestroyImmediate(fl); #else if(fl != null) Destroy(fl); #endif }; foreach(var item in transform.GetChildrenRecursion(10)) { Debug.Log(item.name); fl = item.GetComponent(); destroycomponent(fl); mr = item.GetComponent(); destroycomponent(mr); } } } #endif }