Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Editor scripting: iterating project view assets

Discussion in 'Scripting' started by Dom, Apr 7, 2009.

  1. Dom

    Dom

    Joined:
    Jul 10, 2007
    Posts:
    91
    Hello,

    how can I iterate through all (i.e. material) assets inside the current project (regardless if they are part of the current scene or not)?

    And a second question, how can I know what assets are selected in the project view?

    thx in advance
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You can use System.IO.Directory.GetFiles to get a list of all files in the Assets folder.
    http://msdn.microsoft.com/en-us/library/system.io.directory.getfiles.aspx


    You can then use AssetDatabase.LoadMainAssetAtPath("projectRelativePath") to get the reference to the material. For performance reasons you probably want to check the extension against ".mat" prior to calling AssetDatabase.LoadMainAssetAtPath.
    http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.LoadMainAssetAtPath.html
     
  3. Dom

    Dom

    Joined:
    Jul 10, 2007
    Posts:
    91
    ok, thx.