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


    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);
        }
    }
    

      

  • 相关阅读:
    spring与springmvc父子容器
    spring容器BeanFactory简单例子
    spring整体架构
    css中".",",",“~”和“>”符号的意义
    CSS中的块级元素与行级元素
    java反射和动态代理
    thymeleaf的fragment例子
    编写一个简单的 JDBC 程序
    http://localhost/ 或 http://127.0.0.1/ 报错:HTTP 404 的解决办法
    教你如何清除 MyEclipse/Eclipse 中 Web Browser 和 Switch Workspace 的历史记录
  • 原文地址:https://www.cnblogs.com/kanekiken/p/10550931.html
Copyright © 2020-2023  润新知