Archived
74 lines
1.4 KiB
C#
74 lines
1.4 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 生成节点纯方法
|
|
/// </summary>
|
|
public class GenMethod : BaseGenerate<WeaklyObject>
|
|
{
|
|
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<Collider>(script.gameObject, out var outobj);
|
|
|
|
if(GUILayout.Button("销毁所有渲染组件"))
|
|
DestroyAllMesh(script.transform);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销毁所有模型组件
|
|
/// </summary>
|
|
public void DestroyAllMesh(Transform transform)
|
|
{
|
|
MeshFilter fl = null;
|
|
MeshRenderer mr;
|
|
|
|
Action<Component> 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<MeshFilter>();
|
|
destroycomponent(fl);
|
|
mr = item.GetComponent<MeshRenderer>();
|
|
destroycomponent(mr);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|