Unity在Project视图里面显示文件的拓展名

功能脚本如下:

using System.IO;
using System.Reflection;
using UnityEngine;
using UnityEditor; [InitializeOnLoad]
public static class ShowFileExtensions
{
static ShowFileExtensions()
{
EditorApplication.projectWindowItemOnGUI += ProjectWindowItemOnGUI;
} private static void ProjectWindowItemOnGUI(string guid, Rect rect)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
Object obj = AssetDatabase.LoadAssetAtPath<Object>(assetPath); if (obj != null && AssetDatabase.IsMainAsset(obj) && !IsDirectory(obj))
{
if (showBigIcon)
{
string extension = Path.GetExtension(assetPath);
GUI.Label(rect, extension, EditorStyles.boldLabel);
}
else
{
var fileName = Path.GetFileName(assetPath);
var labelRect = rect.Translate();
GUI.Label(labelRect, fileName);
}
} EditorApplication.RepaintProjectWindow();
} private static bool showBigIcon
{
get { return IsTwoColumnMode && listAreaGridSize > 16f; }
} private static bool IsTwoColumnMode
{
get
{
var projectWindow = GetProjectWindow();
var projectWindowType = projectWindow.GetType();
var modeFileInfo = projectWindowType.GetField("m_ViewMode", BindingFlags.Instance | BindingFlags.NonPublic);
int mode = (int) modeFileInfo.GetValue(projectWindow);
return mode == 1;
}
} private static float listAreaGridSize
{
get
{
var projectWindow = GetProjectWindow();
var projectWindowType = projectWindow.GetType();
var propertyInfo = projectWindowType.GetProperty("listAreaGridSize", BindingFlags.Instance | BindingFlags.Public);
return (float) propertyInfo.GetValue(projectWindow, null);
}
} private static EditorWindow GetProjectWindow()
{
if (EditorWindow.focusedWindow != null && EditorWindow.focusedWindow.titleContent.text == "Project")
{
return EditorWindow.focusedWindow;
} return GetExistingWindowByName("Project");
} private static EditorWindow GetExistingWindowByName(string name)
{
EditorWindow[] windows = Resources.FindObjectsOfTypeAll<EditorWindow>();
foreach (var item in windows)
{
if (item.titleContent.text == name)
{
return item;
}
} return default(EditorWindow);
} private static Rect Translate(this Rect rect)
{
rect.x += 15.8f;
rect.y += 0.9f;
return rect;
} private static bool IsDirectory(Object obj)
{
if (obj == null)
{
return false;
} return obj is DefaultAsset && !AssetDatabase.IsForeignAsset(obj);
}
}

  

Unity在Project视图里面显示文件的拓展名的更多相关文章

  1. Animator窗口视图Project视图PlayerIdleAnimation和PlayerWalkingAnimation

    Animator窗口视图Project视图PlayerIdleAnimation和PlayerWalkingAnimation 通过上一小节的操作,我们新建了2个动画:PlayerIdleAnimat ...

  2. C# 之 获取文件名及拓展名

    1.用Path类的方法(最常用) string fullPath = @"\WebSite\Default.aspx"; string filename = System.IO.P ...

  3. 用SQL脚本移除视图中存在的机器名

    用SQL脚本移除视图中存在的机器名 例子: msccdr.cdr.DimRMAReturnMethod CREATE VIEW CDR.DimRMAReturnMethod ( ReturnMetho ...

  4. Win7怎么显示文件的后缀名

    Win7怎么显示文件的后缀名.. --------------- -------------- --------------- -------------- --------------- ----- ...

  5. 关于Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't available. Compilation of Maven projects is supported only&

    总是出现Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't avai ...

  6. Win10下默认显示文件的扩展名

    默认不显示文件的后缀名 1.右击此电脑,点击属性 2.点击控制面板主页 3.点击文件资源管理器选项 4.切换到查看选项卡,取消勾选“隐藏已知文件类型的扩展名”,应用->确定 结果:

  7. Linux学习笔记:split切分文件并按规律命名及添加拓展名

    基础知识 功能:使用 shell 的 split 可以将一个大文件分割成很多个小文件,有时文件太大处理起来不方便就需要使用到了. 在默认情况下将按照每1000行切割成一个小文件. 语法: split ...

  8. PHP获取文件拓展名的方法

    1.用strrchar()函数,查找字符串在另一字符串中最后出现的位置,并返回该位置到字符串最后的所有字符(返回结果包括点).即返回拓展名前  点  到结尾的字符,即为扩展名.注意与strchar() ...

  9. Unity查找Editor下Project视图中特定的资源

    [MenuItem("Tools/Check Text Count")] public static void CheckText () { //查找指定路径下指定类型的所有资源, ...

随机推荐

  1. HDOJ1022(模拟栈)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. Python:easygui的安装、导入、使用、设置

    转于:https://blog.csdn.net/sinat_37390744/article/details/55211652 博主:钏的博客 一.下载安装 1)下载0.96的easygui.htt ...

  3. mybatis---demo1--(缓存)----bai

    News-mapper.xml 配置: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ma ...

  4. project online get approvals task data 获取审批待办任务接口

    调用接口地址:重要 http://xxxx/sites/pwa/_vti_bin/PSI/ProjectServer.svc Header 三个必要参数: 其中SOAPAction写死就行,如果是on ...

  5. assert.equal()

    assert.equal(actual, expected[, message]) 使用相等运算符(==)测试 actual 参数与 expected 参数是否相等(通俗解释equal方法接受三个参数 ...

  6. oracle上课 学习2 oracle 游标 存储过程 有用

    1.1. 训练描述 使用游标,打印emp中20号部门的所有员工的信息 操作步骤答案 declare cursor c_emp  is select * from emp where deptno=10 ...

  7. 卡特兰数&错排&一个一直记不住的公式

    卡特兰数 公式:f(x)=f(2)*f(x-1)+f(3)*f(x-2)+......+f(x-1)*f(2) #include<iostream>#include<cstdlib& ...

  8. Cygwin install apt-cyg

    1. UPDATE CYGWIN First of all you will need to ensure that Cygwin has the necessary binaries require ...

  9. Git error: unable to create file xxx: Filename too long

    一.问题描述 在使用 git 时,提示 error: unable to create file xxx: Filename too long error: unable to create file ...

  10. 测试merge效率

    测试说明: MERGE是oracle提供的一种特殊的sql语法,非常适用于数据同步场景,即: (把A表数据插到B表,如果B表存在相同主键的记录则使用A表数据对B表进行更新) 数据同步的常规做法是先尝试 ...