Unity Editor工具开发小抄

Unity Editor工具开发小抄

工具开发的需求不是天天有,这些冷门的api总是在用到的时候要翻之前的代码才回忆得起来,为了节约时间做个汇总,方便cv,持续更新。

Editor Windows模板

	public class MeshVertexTool : EditorWindow
	{
        [MenuItem("Tools/OpenMeshVertex %q")]
        public static void OpenMeshVertexWindows()
        {
            MeshVertexTool windows = (MeshVertexTool)EditorWindow.GetWindow(typeof(MeshVertexTool));
            windows.titleContent = new GUIContent("模型顶点冗余数据优化工具");
            windows.minSize = new Vector2(500f, 300f);
        }
		public void OnGUI()
		{
			//UI方法
		}
    }

Inspector扩展

[CustomEditor(typeof(UIRebuildChecker))] 
public class UIRebuilderCheckerEditor : Editor 
{ 
	UIRebuildChecker checker; 

	private void OnEnable() 
	{ 
		checker = (UIRebuildChecker)target;
	}
	
	public override void OnInspectorGUI()
	{
	}
}

Editor下加载资源

AssetDatabase.LoadAssetAtPath的路劲必须以Asset开头,有时可能需要加一步绝对路径到相对路径的转换

path = path.Replace(Application.dataPath, "Assets");
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(path);

进度条

EditorUtility.DisplayProgressBar("查找中", string.Format("{0}/{1}", i, paths.Length), 1.0f * i / paths.Length);

EditorUtility.ClearProgressBar();

//可中途取消的进度条
bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)i / (float)files.Length);
if (isCancel)
{
	break;
}

ScrollView

scrollVec = EditorGUILayout.BeginScrollView(scrollVec);

EditorGUILayout.EndScrollView();

查找指定后缀的文件

string[] paths = Directory.GetFiles(searchPath, "*.fbx", SearchOption.AllDirectories);

保存修改后的资源

EditorUtility.SetDirty
AssetDatabase.SaveAssets
AssetDatabase.Refresh

路径选择

string selectPath = EditorUtility.OpenFolderPanel("请选择补丁生成的路径", Application.dataPath, "");

if (string.IsNullOrEmpty(selectPath))
{
	return;
}
PlayerPrefs.SetString(IFixPatchConfig.PLAYERPREFS_PATH, selectPath );

下拉列表

private string[] options = new string[] { "选项1", "选项2", "选项3" };    
private int index;

index = EditorGUILayout.Popup("下拉列表: ", index, options);

GUILayout.FlexibleSpace()

创建一个自适应的空白区域,也即是填满本次布局中的这部分空间


弹出消息提示

 ShowNotification(new GUIContent("弹出消息提示"));

二次确认框

string content = string.Format("确认要删除区域配置{0}吗?", cur.Name);
if (EditorUtility.DisplayDialog("二次确认", content, "确定", "取消"))
{

}

EditorUtility.DisplayDialog("错误", "必须选择路径", "确定");

打开文件目录

EditorUtility.RevealInFinder(GetLuaPath());
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值