我为我的游戏做了一些项目使开发更容易,我希望为我的项目添加自定义图标,ScriptableObjects
,我该怎么做?我知道将Gizmo文件夹上的图标与脚本同名的技巧,但是对于具有相同脚本的不同项目,图标应该是不同的
答案 0 :(得分:2)
您可以将RawImage字段添加到可编写脚本的对象中。
[SerializeField] RawImage imageIcon;
编辑以回答您的其他问题:
此外,您可以查看此资产包并根据数据创建图标:https://assetstore.unity.com/packages/tools/gui/asseticons-100547
答案 1 :(得分:0)
public StateMachine Target {
get {
return this.target as StateMachine;
}
}
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) {
Texture2D newIcon = new Texture2D(width, height);
if (Target.icon != null) {
EditorUtility.CopySerialized(Target.icon, newIcon);
return newIcon;
} else {
Texture2D defaultCustomIcon = AssetDatabase.LoadAssetAtPath("Assets/WinxProduction/Editor/Editor Default Resources/StateMachine Icon.png", typeof(Texture2D)) as Texture2D;
if (defaultCustomIcon != null) {
EditorUtility.CopySerialized(defaultCustomIcon, newIcon);
Target.icon=newIcon;
AssetDatabase.AddObjectToAsset(newIcon,Target);
EditorUtility.SetDirty(Target);
return newIcon;
}
}
return base.RenderStaticPreview(assetPath, subAssets, width, height);
}
第一次Unity Loads将使用默认Icon并保存所有自定义子类ScriptableObjects。如果你想拥有不同的图标,那么你可以创建一些像这样的函数:
protected void OnClickBrowseForNewIcon() {
string path=EditorUtility.OpenFilePanelWithFilters("Select icon","Assets",new string[]{"Icon files", "png",});
if(!string.IsNullOrEmpty(path)){
Target.icon=AssetDatabase.LoadAssetAtPath(AssetDatabaseUtility.AbsoluteUrlToAssets(path));
EditorUtility.SetDirty(Target);
}
}
相对于绝对
public static class AssetDatabaseUtility
{
public static string AbsoluteUrlToAssets(string absoluteUrl)
{
Uri fullPath = new Uri (absoluteUrl, UriKind.Absolute);
Uri relRoot = new Uri (Application.dataPath, UriKind.Absolute);
return relRoot.MakeRelativeUri (fullPath).ToString ();
}
}