U3D编辑器


namespace MiliP
{
    using UnityEngine;
    using UnityEditor;
    using UnityEngine.UI;
    using System.IO;
    using HuoYun;

    public class MiliPEditer
    {
        const string MenuPath = "Tools/MiliP/";

        [MenuItem(MenuPath +"删除碰撞器", true)]
        [MenuItem(MenuPath + "删除不可见对象", true)]
        [MenuItem(MenuPath + "删除Animation", true)]
        [MenuItem(MenuPath + "删除Animator", true)]
        //[MenuItem("Tools/MiliP/删除丢失的脚本", true)]

        static bool IsSelection()
        {
            object obj = Selection.activeObject;
            return obj != null && obj.GetType() == typeof(GameObject);
        }


        [MenuItem(MenuPath + "删除丢失的脚本")]
        static void CleanupMissingScript()
        {
            GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));
            int ObjectCount = pAllObjects.Length;
            int r;
            int j;
            int count = 0;
            for (int i = 0; i < ObjectCount; i++)
            {
                if (pAllObjects[i].hideFlags == HideFlags.None)//HideFlags.None 获取Hierarchy面板所有Object
                {
                    var components = pAllObjects[i].GetComponents<Component>();
                    var serializedObject = new SerializedObject(pAllObjects[i]);
                    var prop = serializedObject.FindProperty("m_Component");
                    r = 0;
                    for (j = 0; j < components.Length; j++)
                    {
                        if (components[j] == null)
                        {
                            Debug.Log(pAllObjects[i].transform.GetPath()); // *** 输出丢失的脚本位置
                            //prop.DeleteArrayElementAtIndex(j - r); // *** 移除丢失的脚本
                            r++;
                            count++;
                        }
                    }

                    serializedObject.ApplyModifiedProperties();
                }
            }
            Debug.Log("删除丢失的挂载脚本,数量:" + count.ToString());
        }


        [MenuItem(MenuPath + "删除碰撞器")]
        static void DeleteCollider()
        {
            GameObject theSelect = Selection.activeObject as GameObject;
            Collider[] items = theSelect.GetComponentsInChildren<Collider>();
            int itemcount = items.Length;
            int docount = 0;
            for (int i = 0; i < itemcount; i++)
            {
                GameObject.DestroyImmediate(items[itemcount - i - 1]);
                docount++;
            }
            Debug.Log("删除碰撞器,数量:" + docount.ToString());
        }


        //[MenuItem(MenuPath +"删除不可见对象")]
        //static void DeleteUnActive()
        //{
        //    GameObject theSelect = Selection.activeObject as GameObject;
        //    Transform[] items = theSelect.GetComponentsInChildren<Transform>();
        //    Debug.Log(items.Length);
        //    List<GameObject> gos = new List<GameObject>();
        //    foreach (var item in items)
        //    {
        //        if (item.gameObject.activeSelf == false)
        //        {
        //            gos.Add(item.gameObject);
        //        }
        //    }
        //    Debug.Log(gos.Count);
        //    int itemcount = gos.Count;
        //    int docount = 0;
        //    for (int i = 0; i < itemcount; i++)
        //    {
        //        if (!gos[itemcount - i - 1].gameObject.activeSelf)
        //        {
        //            GameObject.DestroyImmediate(gos[itemcount - i - 1].gameObject);
        //            docount++;
        //        }
        //    }
        //    Debug.Log("删除不可见对象,数量:" + docount.ToString());
        //}


        [MenuItem(MenuPath + "删除Animation")]
        static void DeleteAnimation()
        {
            GameObject theSelect = Selection.activeObject as GameObject;
            Animation[] items = theSelect.GetComponentsInChildren<Animation>();
            int itemcount = items.Length;
            int docount = 0;
            for (int i = 0; i < itemcount; i++)
            {
                GameObject.DestroyImmediate(items[itemcount - i - 1]);
                docount++;
            }
            Debug.Log("删除Animation,数量:" + docount.ToString());
        }


        [MenuItem(MenuPath + "删除Animator")]
        static void DeleteAnimator()
        {
            GameObject theSelect = Selection.activeObject as GameObject;
            Animator[] items = theSelect.GetComponentsInChildren<Animator>();
            int itemcount = items.Length;
            int docount = 0;
            for (int i = 0; i < itemcount; i++)
            {
                GameObject.DestroyImmediate(items[itemcount - i - 1]);
                docount++;
            }
            Debug.Log("删除Animator,数量:" + docount.ToString());
        }


        //[MenuItem(MenuPath +"设置GraphicRaycaster")]
        //static void SetGraphicRaycaster()
        //{
        //    int docount = 0;

        //    GraphicRaycaster[] objs = Extensions.FindObjectsOfType<GraphicRaycaster>();
        //    foreach (var item in objs)
        //    {
        //        if (item.blockingObjects!= GraphicRaycaster.BlockingObjects.All)
        //        {
        //            item.blockingObjects = GraphicRaycaster.BlockingObjects.All;
        //            docount++;
        //        }
        //    }
        //    Debug.Log("设置GraphicRaycaster,数量:" + docount.ToString());
        //}


        [MenuItem(MenuPath + "OpenFolder")]
        public static void Test()
        {
            //string output = @"D:/ZP/Test";
            string output = Application.dataPath;
            if (!Directory.Exists(output))
            {
                Directory.CreateDirectory(output);
            }
            output = output.Replace("/", "\\");
            System.Diagnostics.Process.Start("explorer.exe", output);
        }

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值