Unity Editor(三)Resources目录限制不能出现中文
来源:互联网 发布:数控车宏程序编程入门 编辑:程序博客网 时间:2024/06/06 06:31
Unity Editor(三)Resources目录限制不能出现中文
在UnityEditor下,使用AssetPostprocessor类,来实现对Resources下的文件名进行限制,让文件名不能是中文。下面是实现的代码:
using UnityEngine;using System.Collections;using UnityEditor;using System.Text.RegularExpressions;using System.IO;using System.Collections.Generic;public class ResourcesCanNotBeChinese : AssetPostprocessor{ public enum CheckState { success,failure} /// <summary> /// 该方法是由AssetPostprocessor的回调方法 /// </summary>static void OnPostprocessAllAssets (string[] importedAssets ,string[] deletedAssets ,string[] movedAssets ,string[] movedFromAssetPaths){ foreach (var importedAsset in importedAssets) { Debug.Log("importedAssets:"+ importedAsset); if (ChekFileIsResourceAndNotChianese(importedAsset) == CheckState.failure) { //删除文件 AssetDatabase.DeleteAsset(importedAsset); EditorUtility.DisplayDialog("error", "Resource下的文件均不能为中文", "ok"); } } for (int i = 0; i < movedAssets.Length; i++) { if (ChekFileIsResourceAndNotChianese(movedAssets[i]) == CheckState.failure) { //删除文件 // AssetDatabase.DeleteAsset(str); EditorUtility.DisplayDialog("error", "Resource下的文件均不能为中文", "ok"); AssetDatabase.MoveAsset(movedAssets[i], movedFromAssetPaths[i]); } } foreach (var str in movedFromAssetPaths) Debug.Log("movedFromAssetPaths:" + str);} /// <summary> /// 检查文件是否属于Resources目录,并且文件为中文 /// </summary> public static CheckState ChekFileIsResourceAndNotChianese(string path) { string fileName = Path.GetFileName(path); string filePath = Path.GetDirectoryName(path); filePath = Path.GetFileName(filePath); if (filePath == "Resources") { if (Regex.Match(fileName, "^[a-zA-Z\0-9]+$").Success) { return CheckState.success; } else { return CheckState.failure; } } return CheckState.success; }}
=======================================================================
结束。
0 0
- Unity Editor(三)Resources目录限制不能出现中文
- Unity Editor 编辑器扩展三 Unity Editor 数据持久化及Editor窗口的初识
- Unity出现中文乱码
- 限制EditText 不能输入中文
- 【代码挖掘】创建unity工程常用目录的editor编辑器
- Layout Editor中不能显示中文控件信息
- ubuntu中text editor不能显示中文 ubuntu14.04
- 【Unity】Unity Editor Tips
- 网页程序设计中限制不能输入中文
- 限制EditText不能输入中文的监听器
- Unity Editor 基础篇(三):自定义窗口
- Unity Editor 基础篇(三):自定义窗口
- Unity教程之-制作闪亮的星星Star(三):给Star创建Unity Editor编辑器
- XAMPP安装不能有中文目录
- 【Unity】Resources加载
- UNITY 5.2 Resources类
- 【Unity 插件】 Shader Editor
- Unity学习 - Editor扩张
- java基础知识-继承
- 项目总结(FDL)(一)ListView单选和多项
- 《Wide & Deep Learning for Recommender Systems 》笔记
- javascript高级程序设计第三版 第4章 基本类型和引用类型的值 学习笔记
- java基础知识-内部类
- Unity Editor(三)Resources目录限制不能出现中文
- C++Primer(第八章课后习题程序题源代码)
- java基础知识-包装器类
- java基础知识-反射机制
- Android 优雅的为RecyclerView添加HeaderView和FooterView
- VS2008和VS2010再次修改菜单栏时显示修改无效
- MongoDB的基本使用
- java基础知识-异常
- Ubuntu 15.04下安装Node.JS的不同方式