Unity的内置Icon使用
EditorGUIUtility.TrIconContent(string iconName, string tooltip = null)
来获取,可以丰富自己的编辑器,这里撸了一个简单的Icon查看器,代码如下
using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; public class UnityInternalIconsReader : EditorWindow { List<GUIContent> m_Icons = new List<GUIContent>(); List<GUIContent> m_ShowIcons = new List<GUIContent>(); Vector2 m_ScrollPos; string m_FindStr; string m_Desc; void OnOpen() { //var texs = Resources.FindObjectsOfTypeAll(); //foreach (var tex in texs) //{ // var icon = new GUIContent(tex.name); // icon.image= tex; // m_Icons.Add(icon); //} var textAsset = Resources.Load("AllIcons") as TextAsset; var IconNames = textAsset.text.Split('\n'); Debug.unityLogger.logEnabled = false; for (int i = 0; i < IconNames.Length; i++) { var icon = EditorGUIUtility.TrIconContent(IconNames[i].Trim()); if (icon.image != null) m_Icons.Add(icon); } Debug.unityLogger.logEnabled = true; FilterIcon(null); } [MenuItem(("Tools/Unity Internal Icons Reader"))] static void Init() { UnityInternalIconsReader window = EditorWindow.GetWindow<UnityInternalIconsReader>("Unity Internal Icons Reader"); window.minSize = new Vector2(200, 400); window.OnOpen(); } void FilterIcon(string filterStr) { m_ShowIcons.Clear(); if (string.IsNullOrEmpty(filterStr)) m_ShowIcons.AddRange(m_Icons); else { for (int i = 0; i < m_Icons.Count; i++) { if (m_Icons[i].image.name.Contains(filterStr)) m_ShowIcons.Add(m_Icons[i]); } } m_Desc = string.Format("Icon count:{0}", m_ShowIcons.Count); } void OnGUI() { GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label(m_Desc); m_FindStr = GUILayout.TextField(m_FindStr, GUILayout.Width(200)); if ((GUILayout.Button("Filter",GUILayout.Width(50)))) { FilterIcon(m_FindStr); } GUILayout.EndHorizontal(); m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos); foreach (var icon in m_ShowIcons) { GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Box(icon); EditorGUILayout.Space(); GUILayout.Label(icon.image.name); if ((GUILayout.Button("Copy", GUILayout.Width(50)))) { GUIUtility.systemCopyBuffer = icon.image.name; this.ShowNotification(new GUIContent("已复制到剪切板")); } if ((GUILayout.Button("Save", GUILayout.Width(50)))) { var imgSavePath = EditorUtility.SaveFilePanel("Save As ...", Application.dataPath, icon.image.name, "png"); if (!string.IsNullOrEmpty(imgSavePath)) { var texture = icon.image; RenderTexture tmp = RenderTexture.GetTemporary( texture.width, texture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear); Graphics.Blit(icon.image, tmp); RenderTexture previous = RenderTexture.active; RenderTexture.active = tmp; Texture2D newTexture2D = new Texture2D(texture.width, texture.height); newTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0); newTexture2D.Apply(); RenderTexture.active = previous; var bytes = newTexture2D.EncodeToPNG(); var file = File.Open(imgSavePath, FileMode.Create); var binary = new BinaryWriter(file); binary.Write(bytes); file.Close(); this.ShowNotification(new GUIContent("已保存")); } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } }
AllIcons.txt 文件内容如下,参考https://www.xuanyusong.com/archives/3777/comment-page-1
TreeEditor.AddLeaves TreeEditor.AddBranches TreeEditor.Trash TreeEditor.Duplicate TreeEditor.Refresh editicon.sml tree_icon_branch_frond tree_icon_branch tree_icon_frond tree_icon_leaf tree_icon animationvisibilitytoggleon animationvisibilitytoggleoff MonoLogo AgeiaLogo AboutWindow.MainHeader Animation.AddEvent lightMeter/greenLight lightMeter/lightRim lightMeter/orangeLight lightMeter/redLight Animation.PrevKey Animation.NextKey Animation.AddKeyframe Animation.EventMarker Animation.Play Animation.Record AS Badge Delete AS Badge Move AS Badge New WelcomeScreen.AssetStoreLogo preAudioAutoPlayOff preAudioAutoPlayOn preAudioPlayOff preAudioPlayOn preAudioLoopOff preAudioLoopOn AvatarInspector/BodySilhouette AvatarInspector/HeadZoomSilhouette AvatarInspector/LeftHandZoomSilhouette AvatarInspector/RightHandZoomSilhouette AvatarInspector/Torso AvatarInspector/Head AvatarInspector/LeftArm AvatarInspector/LeftFingers AvatarInspector/RightArm AvatarInspector/RightFingers AvatarInspector/LeftLeg AvatarInspector/RightLeg AvatarInspector/HeadZoom AvatarInspector/LeftHandZoom AvatarInspector/RightHandZoom AvatarInspector/DotFill AvatarInspector/DotFrame AvatarInspector/DotFrameDotted AvatarInspector/DotSelection SpeedScale AvatarPivot Avatar Icon Mirror AvatarInspector/BodySIlhouette AvatarInspector/BodyPartPicker AvatarInspector/MaskEditor_Root AvatarInspector/LeftFeetIk AvatarInspector/RightFeetIk AvatarInspector/LeftFingersIk AvatarInspector/RightFingersIk BuildSettings.SelectedIcon SocialNetworks.UDNLogo SocialNetworks.LinkedInShare SocialNetworks.FacebookShare SocialNetworks.Tweet SocialNetworks.UDNOpen Clipboard Toolbar Minus ClothInspector.PaintValue EditCollider EyeDropper.Large ColorPicker.CycleColor ColorPicker.CycleSlider PreTextureMipMapLow PreTextureMipMapHigh PreTextureAlpha PreTextureRGB Icon Dropdown UnityLogo Profiler.PrevFrame Profiler.NextFrame GameObject Icon Prefab Icon PrefabNormal Icon PrefabModel Icon ScriptableObject Icon sv_icon_none PreMatLight0 PreMatLight1 Toolbar Plus Camera Icon PreMatSphere PreMatCube PreMatCylinder PreMatTorus PlayButton PauseButton HorizontalSplit VerticalSplit BuildSettings.Web.Small js Script Icon cs Script Icon boo Script Icon Shader Icon TextAsset Icon AnimatorController Icon AudioMixerController Icon RectTransformRaw RectTransformBlueprint MoveTool MeshRenderer Icon Terrain Icon SceneviewLighting SceneviewFx SceneviewAudio SettingsIcon TerrainInspector.TerrainToolRaise TerrainInspector.TerrainToolSetHeight TerrainInspector.TerrainToolSmoothHeight TerrainInspector.TerrainToolSplat TerrainInspector.TerrainToolTrees TerrainInspector.TerrainToolPlants TerrainInspector.TerrainToolSettings RotateTool ScaleTool RectTool MoveTool On RotateTool On ScaleTool On RectTool On ViewToolOrbit ViewToolMove ViewToolZoom ViewToolOrbit On ViewToolMove On ViewToolZoom On StepButton PlayButtonProfile PlayButton On PauseButton On StepButton On PlayButtonProfile On PlayButton Anim PauseButton Anim StepButton Anim PlayButtonProfile Anim WelcomeScreen.MainHeader WelcomeScreen.VideoTutLogo WelcomeScreen.UnityBasicsLogo WelcomeScreen.UnityForumLogo WelcomeScreen.UnityAnswersLogo Toolbar Plus More
工具效果如下:
文章评论