版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/osuckseed/article/details/84874621
1.编辑器实用方法汇总
//1.编辑器内物体查找(指定路径下搜索类型是scene/object.. ,并且名字中包含unity的文件)
var mlist = new List<string>(AssetDatabase.FindAssets("unity t:scene", new string[] { "Assets/path" }));
//2. 定位
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath("filePath",typeof(UnityEngine.Object)));
//3.搜集编辑器引用
AssetDatabase.GetDependencies("pathName");
EditorUtility.CollectDependencies("Objects[]");
//4.选中查找 只有Object类型好使
UnityEditor.Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets)
//持续更新中... ...
2.Inspector_PopList:将指定文件目录内资源条目已pop类型展示在inspector面板中
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
//自定义Tset脚本
[CustomEditor(typeof(BossBulletManager))]
public class Inspector_PopList : Editor
{
static public string DrawList(string field, string[] list, string selection, params GUILayoutOption[] options)
{
if (list != null && list.Length > 0)
{
int index = 0;
if (string.IsNullOrEmpty(selection)) selection = list[0];
// We need to find the sprite in order to have it selected
if (!string.IsNullOrEmpty(selection))
{
for (int i = 0; i < list.Length; ++i)
{
if (selection.Equals(list[i], StringComparison.OrdinalIgnoreCase))
{
index = i;
break;
}
}
}
// Draw the sprite selection popup
//EditorGUILayout.BeginHorizontal(EditorStyles.toolbarPopup);
index = string.IsNullOrEmpty(field) ?
EditorGUILayout.Popup(index, list) :
EditorGUILayout.Popup(field, index, list);
//EditorGUILayout.EndHorizontal();
return list[index];
}
return null;
}
//在这里方法中就可以绘制面板。
public override void OnInspectorGUI()
{
//得到Test对象
var test = (BossBulletManager)target;
test.bossBulletType = DrawList("", ThreeToOneManager.Inst.ListToEnum("/Resources/BossBullet/ShotPattern/"), test.bossBulletType);
if (GUILayout.Button("播放当前子弹类型"))
{
BossBulletManager.Inst.AddBossBullet(test.bossBulletType);
}
if (GUILayout.Button("增加当前子弹类型"))
{
BossBulletManager.Inst.AddBulletType(test.bossBulletType);
}
if (GUILayout.Button("演示队列子弹类型"))
{
BossBulletManager.Inst.PalyBulletTypeList();
}
base.OnInspectorGUI();
for (int i = 0; i < test.bulletTypeList.Count; i++)
{
test.bulletTypeList[i] = DrawList("", ThreeToOneManager.Inst.ListToEnum("/Resources/BossBullet/ShotPattern/"), test.bulletTypeList[i]);
}
}
}
获取文件夹条目方法:
public string[] ListToEnum(string _path)
{
var path = UnityEngine.Application.dataPath + _path;//"/Resources/BossBullet/ShotPattern/";
var paras = Directory.GetFiles(path, "*.prefab")
.Select(s => s.Substring(s.LastIndexOf('/') + 1, s.Length - s.LastIndexOf('/') - 1))
.Select(b=> b.Substring(0,b.LastIndexOf('.')) ).ToArray();
return paras;
}