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);
}
}
}