Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Gizmos in package.

Discussion in 'Package Manager' started by wang37921, Aug 9, 2019.

  1. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    100
    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?
    upload_2019-8-9_14-49-53.png
     
    Rallix likes this.
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,051
    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.
     
  3. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    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.
     
    wang37921 likes this.
  4. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    100
    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://forum.unity.com/threads/while-custom-package-need-a-link-xml.727460/
     
  5. KarolStolaDD

    KarolStolaDD

    Joined:
    Sep 10, 2019
    Posts:
    7
    There is a better way. You can specify the Full path to the gizmo with package qualifier:

    Code (CSharp):
    1. var assembly = Assembly.GetExecutingAssembly();
    2. var packagePath = PackagePath.FindForAssembly(assembly).assetPath;
    3. 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:
    Code (CSharp):
    1. "Packages/com.yourcompany.packagename"
    where com.yourcompany.packagename is name from package.json.
     
  6. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    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.
     
  7. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    119
    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.
     
  8. ParadoxSolutions

    ParadoxSolutions

    Joined:
    Jul 27, 2015
    Posts:
    322
    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?
     
  9. Delacrowa

    Delacrowa

    Joined:
    Mar 11, 2015
    Posts:
    2
    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? :D


    Code (CSharp):
    1.   private static T Load<T>(string path) where T : Object
    2.         {
    3.             var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(Assembly.GetExecutingAssembly());
    4.             var packagePath = $"{packageInfo.assetPath}/{path}".Replace('\\', '/');
    5.             var result = AssetDatabase.LoadAssetAtPath<T>(packagePath);
    6.             if (result)
    7.             {
    8.                 return result;
    9.             }
    10.             Debug.LogError($"Failed to load [{typeof(T)}] from [{path}]");
    11.             return default;
    12.         }
    13.      
    14.         private static T LoadFromEditorDefaultResources<T>(string path) where T : Object =>
    15.             Load<T>($"Editor/Editor Default Resources/{path}");
    16.      
    17.         private static T LoadFromGizmos<T>(string path) where T : Object =>
    18.             Load<T>($"Editor/Gizmos/{path}");