博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unity编辑器学习,创建自己的窗口
阅读量:4700 次
发布时间:2019-06-09

本文共 3612 字,大约阅读时间需要 12 分钟。

又是一个体力活,资源搬家的。具体的任务我就不透漏了,反正是底层的资管管理之类的东东。

为了简化操作,我还是坚持写了一个插件,然后感觉做个自己的小窗口也不错,就写了个小小的编辑器插件。

OK,这个小窗口完成的功能很简单,就是移动资源到某一文件夹的。好了,代码分享如下,

看效果的话,直接放到项目文件里面重启unity就行了。代码很简单,注释就不写了:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using UnityEditor;using UnityEngine;using System.IO;public class OneKeyMove : EditorWindow{    public ResPath resPath;    void Start(){        if(resPath==null){            resPath = new ResPath();        }        }    [MenuItem("MyUtil/一键移动")]    public static void Init()    {               if (Resources.FindObjectsOfTypeAll
().Length == 0) { var win = ScriptableObject.CreateInstance
(); win.title = "一键移动"; win.Show(); } } public void OnGUI() { if (resPath == null) { resPath = new ResPath(); } EditorGUILayout.LabelField("移动文件", EditorStyles.boldLabel); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("当前文件", GUILayout.Width(80)); Rect firstRect = EditorGUILayout.GetControlRect(GUILayout.Width(200)); resPath._FirstFile = EditorGUI.TextField(firstRect, resPath._FirstFile); if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragExited) && firstRect.Contains(Event.current.mousePosition)) { if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0) { string sfxPath = DragAndDrop.paths[0]; if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragUpdated) { DragAndDrop.AcceptDrag(); resPath._FirstFile = sfxPath; } } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("目标", GUILayout.Width(80)); Rect secondRect = EditorGUILayout.GetControlRect(GUILayout.Width(200)); resPath._SecondFile = EditorGUI.TextField(secondRect, resPath._SecondFile); if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragExited) && secondRect.Contains(Event.current.mousePosition)) { if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0) { string sfxPath = DragAndDrop.paths[0]; if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragUpdated) { DragAndDrop.AcceptDrag(); resPath._SecondFile = sfxPath; } } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("一键移动")) { string resName = resPath._FirstFile.Remove(0, resPath._FirstFile.LastIndexOf('/') + 1); Debug.Log(resName); string targetPath = resPath._SecondFile + "/layout/" + resName; string realPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/'))+"/"+resPath._SecondFile + "/layout"; if (!Directory.Exists(realPath)) { Directory.CreateDirectory(realPath); } AssetDatabase.Refresh(); Debug.Log(targetPath); AssetDatabase.MoveAsset(resPath._FirstFile, targetPath); } EditorGUILayout.Space(); } }[Serializable]public class ResPath { public string _FirstFile=""; public string _SecondFile="";}

 

转载于:https://www.cnblogs.com/jqg-aliang/p/4885429.html

你可能感兴趣的文章
mini2440 U-boot 编译
查看>>
学习ThreadLocal
查看>>
在 Visual Studio 调试器中指定符号 (.pdb) 和源文件
查看>>
直接量
查看>>
leetcode 115. 不同的子序列(Distinct Subsequences)
查看>>
三元表达式
查看>>
Oauth支持的5类 grant_type 及说明
查看>>
客户端第一天学习的相关知识
查看>>
LeetCode - Same Tree
查看>>
Python dict get items pop update
查看>>
[置顶] 程序员必知(二):位图(bitmap)
查看>>
130242014036-(2)-体验敏捷开发
查看>>
constexpr
查看>>
Nginx 流量和连接数限制
查看>>
课堂作业1
查看>>
IE8/9 本地预览上传图片
查看>>
Summary of CRM 2011 plug-in
查看>>
Eclipse+Maven环境下java.lang.OutOfMemoryError: PermGen space及其解决方法
查看>>
安全漏洞之Java
查看>>
Oracle 组函数count()
查看>>