zoukankan      html  css  js  c++  java
  • unity中project视图下,Alt+左键显示文件扩展名

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEditor;
    using System.IO;
    using System.Reflection;
    
    [InitializeOnLoad]
    public static class ShowFileExtensions
    {
        // ================================================================================
        //  static constructor
        // --------------------------------------------------------------------------------
    
        static ShowFileExtensions()
        {
            EditorApplication.projectWindowItemOnGUI += ProjectWindowItemOnGUI;
        }
    
        // ================================================================================
        //  checking editor events
        // --------------------------------------------------------------------------------
    
        private static void ProjectWindowItemOnGUI(string guid, Rect rect)
        {
            if (Event.current.alt)
            {
                EditorWindow window = GetProjectWindow();            
    
                string assetPath = AssetDatabase.GUIDToAssetPath(guid);
                UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
    
                if (obj != null && AssetDatabase.IsMainAsset(obj) && !IsDirectory(obj))
                {
                    if (showsBigIcons)
                    {
                        // just draw it bold in upper left
                        string extension = Path.GetExtension(assetPath);
                        GUI.Label(rect, extension, EditorStyles.boldLabel);
                    }
                    else
                    {
                        // we overpaint the filename here, does look a bit dirty and might need adjustment of the offset
                        var labelRect = rect.Translate(new Vector2(16f, 1f));
                        var fileName = Path.GetFileName(assetPath);
                        GUI.Label(labelRect, fileName);
                    }
                }
    
                EditorApplication.RepaintProjectWindow();
            }
        }
    
        // ================================================================================
        //  getting infos about the project window
        // --------------------------------------------------------------------------------
    
        private static bool showsBigIcons
        {
            get
            {
                return isTwoColumnMode && listAreaGridSize > 16f;
            }
        }
    
        private static bool isTwoColumnMode
        {
            get
            {
                var projectWindow = GetProjectWindow();
    
                var projectWindowType = projectWindow.GetType();
                var modeFieldInfo = projectWindowType.GetField("m_ViewMode", BindingFlags.Instance | BindingFlags.NonPublic);
    
                int mode = (int)modeFieldInfo.GetValue(projectWindow);
    
                // 0 == ViewMode.OneColumn
                // 1 == ViewMode.TwoColum
    
                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);
            }
        }
    
        /// <summary>
        /// there's a chance here we get the wrong one when two project windows are open
        /// </summary>
        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);
        }
    
        // ================================================================================
        //  utilities
        // --------------------------------------------------------------------------------
    
        private static Rect Translate(this Rect rect, Vector2 delta)
        {
            rect.x += delta.x;
            rect.y += delta.y;
    
            return rect;
        }
    
        private static bool IsDirectory(UnityEngine.Object obj)
        {
            if (obj == null)
            {
                return false;
            }
    
            return obj is DefaultAsset && !AssetDatabase.IsForeignAsset(obj);
        }
    }

    转自:https://gist.github.com/talecrafter/1009efa95cbcf6e01958efb887def90b

  • 相关阅读:
    sql sever外网映射后链接,端口号用,号区分
    zentao事故,慢sql查询
    阿里云镜像加速器配置
    对产品不同指标维度分组求和
    burp抓包https请求
    mysql获取当天,昨天,本周,本月,上周,上月的起始时间
    查询不同sql,插入同一个sheet
    按分类查找缺陷并输出到EXCEL
    循环导出所有行和列
    查询某字段等于当天的日期sql:select count(*) from zt_bug WHERE date_format(openedDate,'%Y-%m-%d')=date_format(NOW(),'%Y-%m-%d')
  • 原文地址:https://www.cnblogs.com/Yellow0-0River/p/6513192.html
Copyright © 2011-2022 走看看