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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

How to get selected sprites from Texture asset?

Discussion in 'Immediate Mode GUI (IMGUI)' started by eses, Mar 1, 2018.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,638
    Hi,

    so my question is how to get selected sprites from Texture asset? I know I can get selection using something like:

    Code (csharp):
    1.  
    2. Selection.GetFiltered (typeof(Object), SelectionMode.Assets);
    3.  
    I also found out that I can iterate all the sprites in texture:

    Code (csharp):
    1.  
    2. Object[] allSprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
    3.  
    But how can I get the editor selection? Selection just shows I've selected a texture sheet.

    Any help would be appreciated!
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,638
    I actually figured this out (eventually).

    If someone else needs this - here it is:

    Code (csharp):
    1.  
    2. Sprite[] selSprites = Selection.GetFiltered<Sprite>(SelectionMode.Unfiltered);
    3.  
     
  3. tranminhvu22

    tranminhvu22

    Joined:
    Sep 28, 2022
    Posts:
    1
    thanks