qq交流群:106864335
加群连接:<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=7701e50a9c5f4ce04348cc37f8ff732615c0b6435ad7ef32c15ead9315561a09"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="Unity-不疯魔,不成活" title="Unity-不疯魔,不成活"></a>
q群初建,欢迎大家加入交流。
微信公众号:zhimeng-1314 名称:Unity不疯魔不成活
开发mmoarpg项目很长时间了,现在总结一些项目中自写的一些工具作为记录和分享。
本篇介绍工具:通用编辑器工具(持续完善中),代码如下。
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
/// 我的工具库--通用编辑器工具
/// 注:可以用,不可以改
/// 所有的相似工具类在此下添加
/// <summary>
/// 编辑器通用工具
/// </summary>
public class WEditorTools : EditorWindow
{
/// <summary>
/// 编辑器功能--查找选定对象下所有的组件
/// </summary>
public static List<T> SelectCompount<T>() where T : Component
{
int num = 0;
Object[] Tcs = Selection.GetFiltered(typeof(T), SelectionMode.Deep);
List<T> list = new List<T>();
foreach (UnityEngine.Object item in Tcs)
{
T tc = (T)item;
if (tc != null)
{
list.Add(tc);
num++;
}
}
Debug.Log("查找的组件为:" + typeof(T) + " 查找完成,共找到的数量为" + num);
return list;
}
/// <summary>
/// 查找项目中所有的组件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static List<T> FindAssets_Compount<T>() where T : Component
{
List<T> list = new List<T>();
string[] paths = AssetDatabase.GetAllAssetPaths();
foreach (string path in paths)
{
T t = (T)AssetDatabase.LoadAssetAtPath(path, typeof(T));
if (t != null)
{
Debug.Log(t.name);
list.Add(t);
}
}
return list;
}
//标记为预设修改状态,否则预设不会保存
//EditorUtility.SetDirty(gos[i]);
}