Skip to content

Instantly share code, notes, and snippets.

@davecdempsey
Forked from Volantk/SetIcon.cs
Created June 20, 2024 13:31
Show Gist options
  • Select an option

  • Save davecdempsey/92d25220e6086ce6b9ece1fc113987b9 to your computer and use it in GitHub Desktop.

Select an option

Save davecdempsey/92d25220e6086ce6b9ece1fc113987b9 to your computer and use it in GitHub Desktop.

Revisions

  1. @Volantk Volantk revised this gist Dec 16, 2016. 1 changed file with 32 additions and 32 deletions.
    64 changes: 32 additions & 32 deletions SetIcon.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,35 @@
    public static void SetGameObjectIcon(GameObject go, string texturePath)
    {
    Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }

    public static void SetGameObjectIcon(GameObject go, EditorIconType iconType)
    {
    Texture2D texture = EditorGUIUtility.FindTexture(GetIconPath(iconType));

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }

    public enum EditorIconType
    {
    GreyLabel,
    @@ -58,35 +90,3 @@ private static string GetIconPath(EditorIconType iconType)
    throw new ArgumentOutOfRangeException("iconType", iconType, null);
    }
    }

    public static void SetGameObjectIcon(GameObject go, EditorIconType iconType)
    {
    Texture2D texture = EditorGUIUtility.FindTexture(GetIconPath(iconType));

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }

    public static void SetGameObjectIcon(GameObject go, string texturePath)
    {
    Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }
  2. @Volantk Volantk revised this gist Dec 16, 2016. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion SetIcon.cs
    Original file line number Diff line number Diff line change
    @@ -73,4 +73,20 @@ public static void SetGameObjectIcon(GameObject go, EditorIconType iconType)
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }
    }

    public static void SetGameObjectIcon(GameObject go, string texturePath)
    {
    Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }
  3. @Volantk Volantk revised this gist Dec 16, 2016. 1 changed file with 70 additions and 70 deletions.
    140 changes: 70 additions & 70 deletions SetIcon.cs
    Original file line number Diff line number Diff line change
    @@ -1,76 +1,76 @@
    public enum EditorIconType
    {
    GreyLabel,
    BlueLabel,
    CyanLabel,
    GreenLabel,
    YellowLabel,
    OrangeLabel,
    RedLabel,
    PinkLabel,
    GreyRound,
    BlueRound,
    CyanRound,
    GreenRound,
    YellowRound,
    OrangeRound,
    RedRound,
    PinkRound,
    GreyDiamond,
    BlueDiamond,
    CyanDiamond,
    GreenDiamond,
    YellowDiamond,
    OrangeDiamond,
    RedDiamond,
    PinkDiamond
    }
    public enum EditorIconType
    {
    GreyLabel,
    BlueLabel,
    CyanLabel,
    GreenLabel,
    YellowLabel,
    OrangeLabel,
    RedLabel,
    PinkLabel,
    GreyRound,
    BlueRound,
    CyanRound,
    GreenRound,
    YellowRound,
    OrangeRound,
    RedRound,
    PinkRound,
    GreyDiamond,
    BlueDiamond,
    CyanDiamond,
    GreenDiamond,
    YellowDiamond,
    OrangeDiamond,
    RedDiamond,
    PinkDiamond
    }

    private static string GetIconPath(EditorIconType iconType)
    private static string GetIconPath(EditorIconType iconType)
    {
    switch (iconType)
    {
    switch (iconType)
    {
    case EditorIconType.GreyLabel: return "sv_label_0";
    case EditorIconType.BlueLabel: return "sv_label_1";
    case EditorIconType.CyanLabel: return "sv_label_2";
    case EditorIconType.GreenLabel: return "sv_label_3";
    case EditorIconType.YellowLabel: return "sv_label_4";
    case EditorIconType.OrangeLabel: return "sv_label_5";
    case EditorIconType.RedLabel: return "sv_label_6";
    case EditorIconType.PinkLabel: return "sv_label_7";
    case EditorIconType.GreyRound: return "sv_icon_dot0_pix16_gizmo";
    case EditorIconType.BlueRound: return "sv_icon_dot1_pix16_gizmo";
    case EditorIconType.CyanRound: return "sv_icon_dot2_pix16_gizmo";
    case EditorIconType.GreenRound: return "sv_icon_dot3_pix16_gizmo";
    case EditorIconType.YellowRound: return "sv_icon_dot4_pix16_gizmo";
    case EditorIconType.OrangeRound: return "sv_icon_dot5_pix16_gizmo";
    case EditorIconType.RedRound: return "sv_icon_dot6_pix16_gizmo";
    case EditorIconType.PinkRound: return "sv_icon_dot7_pix16_gizmo";
    case EditorIconType.GreyDiamond: return "sv_icon_dot8_pix16_gizmo";
    case EditorIconType.BlueDiamond: return "sv_icon_dot9_pix16_gizmo";
    case EditorIconType.CyanDiamond: return "sv_icon_dot10_pix16_gizmo";
    case EditorIconType.GreenDiamond: return "sv_icon_dot11_pix16_gizmo";
    case EditorIconType.YellowDiamond: return "sv_icon_dot12_pix16_gizmo";
    case EditorIconType.OrangeDiamond: return "sv_icon_dot13_pix16_gizmo";
    case EditorIconType.RedDiamond: return "sv_icon_dot14_pix16_gizmo";
    case EditorIconType.PinkDiamond: return "sv_icon_dot15_pix16_gizmo";
    default:
    throw new ArgumentOutOfRangeException("iconType", iconType, null);
    }
    case EditorIconType.GreyLabel: return "sv_label_0";
    case EditorIconType.BlueLabel: return "sv_label_1";
    case EditorIconType.CyanLabel: return "sv_label_2";
    case EditorIconType.GreenLabel: return "sv_label_3";
    case EditorIconType.YellowLabel: return "sv_label_4";
    case EditorIconType.OrangeLabel: return "sv_label_5";
    case EditorIconType.RedLabel: return "sv_label_6";
    case EditorIconType.PinkLabel: return "sv_label_7";
    case EditorIconType.GreyRound: return "sv_icon_dot0_pix16_gizmo";
    case EditorIconType.BlueRound: return "sv_icon_dot1_pix16_gizmo";
    case EditorIconType.CyanRound: return "sv_icon_dot2_pix16_gizmo";
    case EditorIconType.GreenRound: return "sv_icon_dot3_pix16_gizmo";
    case EditorIconType.YellowRound: return "sv_icon_dot4_pix16_gizmo";
    case EditorIconType.OrangeRound: return "sv_icon_dot5_pix16_gizmo";
    case EditorIconType.RedRound: return "sv_icon_dot6_pix16_gizmo";
    case EditorIconType.PinkRound: return "sv_icon_dot7_pix16_gizmo";
    case EditorIconType.GreyDiamond: return "sv_icon_dot8_pix16_gizmo";
    case EditorIconType.BlueDiamond: return "sv_icon_dot9_pix16_gizmo";
    case EditorIconType.CyanDiamond: return "sv_icon_dot10_pix16_gizmo";
    case EditorIconType.GreenDiamond: return "sv_icon_dot11_pix16_gizmo";
    case EditorIconType.YellowDiamond: return "sv_icon_dot12_pix16_gizmo";
    case EditorIconType.OrangeDiamond: return "sv_icon_dot13_pix16_gizmo";
    case EditorIconType.RedDiamond: return "sv_icon_dot14_pix16_gizmo";
    case EditorIconType.PinkDiamond: return "sv_icon_dot15_pix16_gizmo";
    default:
    throw new ArgumentOutOfRangeException("iconType", iconType, null);
    }
    }

    public static void SetGameObjectIcon(GameObject go, EditorIconType iconType)
    {
    Texture2D texture = EditorGUIUtility.FindTexture(GetIconPath(iconType));
    public static void SetGameObjectIcon(GameObject go, EditorIconType iconType)
    {
    Texture2D texture = EditorGUIUtility.FindTexture(GetIconPath(iconType));

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }
    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }
    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }
  4. @Volantk Volantk created this gist Dec 16, 2016.
    76 changes: 76 additions & 0 deletions SetIcon.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    public enum EditorIconType
    {
    GreyLabel,
    BlueLabel,
    CyanLabel,
    GreenLabel,
    YellowLabel,
    OrangeLabel,
    RedLabel,
    PinkLabel,
    GreyRound,
    BlueRound,
    CyanRound,
    GreenRound,
    YellowRound,
    OrangeRound,
    RedRound,
    PinkRound,
    GreyDiamond,
    BlueDiamond,
    CyanDiamond,
    GreenDiamond,
    YellowDiamond,
    OrangeDiamond,
    RedDiamond,
    PinkDiamond
    }

    private static string GetIconPath(EditorIconType iconType)
    {
    switch (iconType)
    {
    case EditorIconType.GreyLabel: return "sv_label_0";
    case EditorIconType.BlueLabel: return "sv_label_1";
    case EditorIconType.CyanLabel: return "sv_label_2";
    case EditorIconType.GreenLabel: return "sv_label_3";
    case EditorIconType.YellowLabel: return "sv_label_4";
    case EditorIconType.OrangeLabel: return "sv_label_5";
    case EditorIconType.RedLabel: return "sv_label_6";
    case EditorIconType.PinkLabel: return "sv_label_7";
    case EditorIconType.GreyRound: return "sv_icon_dot0_pix16_gizmo";
    case EditorIconType.BlueRound: return "sv_icon_dot1_pix16_gizmo";
    case EditorIconType.CyanRound: return "sv_icon_dot2_pix16_gizmo";
    case EditorIconType.GreenRound: return "sv_icon_dot3_pix16_gizmo";
    case EditorIconType.YellowRound: return "sv_icon_dot4_pix16_gizmo";
    case EditorIconType.OrangeRound: return "sv_icon_dot5_pix16_gizmo";
    case EditorIconType.RedRound: return "sv_icon_dot6_pix16_gizmo";
    case EditorIconType.PinkRound: return "sv_icon_dot7_pix16_gizmo";
    case EditorIconType.GreyDiamond: return "sv_icon_dot8_pix16_gizmo";
    case EditorIconType.BlueDiamond: return "sv_icon_dot9_pix16_gizmo";
    case EditorIconType.CyanDiamond: return "sv_icon_dot10_pix16_gizmo";
    case EditorIconType.GreenDiamond: return "sv_icon_dot11_pix16_gizmo";
    case EditorIconType.YellowDiamond: return "sv_icon_dot12_pix16_gizmo";
    case EditorIconType.OrangeDiamond: return "sv_icon_dot13_pix16_gizmo";
    case EditorIconType.RedDiamond: return "sv_icon_dot14_pix16_gizmo";
    case EditorIconType.PinkDiamond: return "sv_icon_dot15_pix16_gizmo";
    default:
    throw new ArgumentOutOfRangeException("iconType", iconType, null);
    }
    }

    public static void SetGameObjectIcon(GameObject go, EditorIconType iconType)
    {
    Texture2D texture = EditorGUIUtility.FindTexture(GetIconPath(iconType));

    if (texture == null)
    {
    Debug.LogError("Couldn't find an icon...");
    return;
    }

    var so = new SerializedObject(go);
    var iconProperty = so.FindProperty("m_Icon");
    iconProperty.objectReferenceValue = texture;
    so.ApplyModifiedProperties();
    }