While I making a custom package. I found if i can let the generated ScriptableObject asset has its own icon, will be cool.
In general develop, it can be done by adding the namespace/to/Scriptable icon.png to Assets/Gizmos.
So, I thought the custom package folder could include the Gizmos?
And i found the office package include the Gizmos folder!
But it has no effect, in my custom package…
Any thing wrong, or it is no support now?
If you just want to assign an icon to a ScriptableObject, there’s an easier way that works with packages:
Just select the ScriptableObject script in the editor and click on its icon in the top left of the inspector to assign any Texture2D as its icon. Any instance of the ScriptableObject will then use that icon, too.
I was looking for this as well.
Looking at the Cinemachine’s changelog, it looks like they used to copy the gizmos automatically to Assets/Gizmos after import (see here). You could use the same approach. I didn’t check if it works yet, but I don’t see why it shouldn’t.
cool!
the package build-in support merge behaviour will be better.
But dont know whether be accepted.
the Gizmos and othe special folder and files(like link.xml)
https://discussions.unity.com/t/754406
There is a better way. You can specify the Full path to the gizmo with package qualifier:
var assembly = Assembly.GetExecutingAssembly();
var packagePath = PackagePath.FindForAssembly(assembly).assetPath;
Gizmos.DrawIcon(transform.position, packagePath+"/Path/In/Package/Gizmo.png", true);
This code will work from the inside of package. If you want to Reference a gizmo in package from the outside of it (other package or code in project), you have to provide the packagePath on your own. It goes like this:
"Packages/com.yourcompany.packagename"
where com.yourcompany.packagename is name from package.json.
Yes, but this would only display the gizmo in Scene View, not in Inspector (to replace the default script icon).
I mainly want a custom icon for a ScriptableObject or a MonoBehaviour – and for that, the icons currently need to be in the ‘proper’ Gizmos folder.
see Adrian’s response - you just map the scriptable object or custom class to your gizmo and the mapping will work for packages as well.
Is there a way to include gizmos in a package and have it just show up in the inspector but not in the scene view?
When the question about the engine is more or less complex - there is almost no way to find the the correct answer. This is for you, guys struggling. I’ll save you time and health
This is the generic API to work inside the package using Unity 2022. It supports loading from Gizmos and Editor Default Resorces folders. I expect the default package structure is in use. Yeah, Unity team has changed a lot and dropped many old API but… This is good, isn’t it?
private static T Load<T>(string path) where T : Object
{
var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(Assembly.GetExecutingAssembly());
var packagePath = $"{packageInfo.assetPath}/{path}".Replace('\\', '/');
var result = AssetDatabase.LoadAssetAtPath<T>(packagePath);
if (result)
{
return result;
}
Debug.LogError($"Failed to load [{typeof(T)}] from [{path}]");
return default;
}
private static T LoadFromEditorDefaultResources<T>(string path) where T : Object =>
Load<T>($"Editor/Editor Default Resources/{path}");
private static T LoadFromGizmos<T>(string path) where T : Object =>
Load<T>($"Editor/Gizmos/{path}");
Hi, I am not sure why you need all the hoops, I just simply use the
[Icon("Packages/me.tooster.packagename/Editor/Resources/Icons/some-icon.png")]
public class SdfScene : MonoBehaviour {...}
and it seems to be working out of the box, so what’s the problem?