简体   繁体   English

如何在 Unity3D 中创建脚本图标?

[英]How to create a script icon in Unity3D?

I created a scipt and editor for it.我为它创建了一个 scipt 和编辑器。 Now I want to assosiate an icon with it like this:现在我想像这样关联一个图标:在此处输入图片说明

How to do such thing?这样的事情怎么办? Cant find any documentation on this.找不到关于此的任何文档

You can change the icon by selecting the Object in Project view.您可以通过在项目视图中选择对象来更改图标。 Then click the icon in the upper left corner in the Inspector.然后单击检查器左上角的图标。 Then select Other .然后选择Other

[Picture Guide] So after you have selected the script, click on the icon marked in red in the picture below: 【图片指南】所以选择脚本后,点击下图中红色标记的图标:

在此处输入图片说明

Look at the picture below for guidance.请看下图以获取指导。

在此处输入图片说明

If you want to assign an icon to a custom script, I believe you can create a gizmo icon for it and place the image at a project location that maps to the namespace of your script.如果您想为自定义脚本分配一个图标,我相信您可以为其创建一个 Gizmo 图标并将图像放置在映射到脚本命名空间的项目位置。 My understanding is for each MonoBehaviour in your assembly, Unity looks for an associated icon with the name "<className> Icon" under the "Gizmos" folder, but the hierarchy must match the namespace.我的理解是,对于程序集中的每个 MonoBehaviour,Unity 会在“Gizmos”文件夹下查找名称为“<className> Icon”的关联图标,但层次结构必须与命名空间匹配。

So if your MonoBehavior is TestClass and its namespace is Company.Project.Foo , you would place the image in your project at "Assets/Gizmos/Company/Project/Foo/" and image name should be "TestClass Icon".因此,如果您的 MonoBehavior 是TestClass并且它的命名空间是Company.Project.Foo ,那么您可以将图像放置在您的项目中的“Assets/Gizmos/Company/Project/Foo/”并且图像名称应该是“TestClass Icon”。

Your script will then have the icon associated with it when viewed in the Inspector, but I don't believe this will cause it to appear in the SceneView.在 Inspector 中查看时,您的脚本将具有与其关联的图标,但我不相信这会导致它出现在 SceneView 中。 You should use the DrawGizmo attribute on an editor script, if you want to make the icon appear in the SceneView or perform any other custom gizmo drawing.如果要使图标出现在 SceneView 中或执行任何其他自定义 Gizmo 绘图,则应在编辑器脚本上使用DrawGizmo属性。

In the following example screenshots, I have a script called SafeArea with the namespace Greyborn.Library .在以下示例屏幕截图中,我有一个名为SafeArea的脚本,其命名空间为Greyborn.Library I placed the "SafeArea Icon.png" at "Assets/Gizmos/Greyborn/Library/", and the icon immediately appeared in the Inspector and Project windows.我将“SafeArea Icon.png”放在“Assets/Gizmos/Greyborn/Library/”中,该图标立即出现在Inspector和Project窗口中。

Unity 脚本 Gizmo 示例 1

I used a PNG.我使用了 PNG。 Other image types may be supported, however when I tested with a PSD image, the gizmo wouldn't show up.可能支持其他图像类型,但是当我使用 PSD 图像进行测试时,Gizmo 不会出现。 Be sure to set the Texture Type to "Editor GUI and Legacy GUI".确保将纹理类型设置为“Editor GUI and Legacy GUI”。

Unity 脚本 Gizmo 示例 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM