Eonirr

Untitled

Apr 24th, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public static List<T> FindAllAssetsOfTypeWithLevel<T>(string folderPath, int targetLevel) where T : ScriptableObject
  2. {
  3. List<T> matchingAssets = new List<T>();
  4.  
  5. string[] guids = AssetDatabase.FindAssets("t:" + typeof(T).Name, new[] { folderPath });
  6.  
  7. foreach (string guid in guids)
  8. {
  9. string assetPath = AssetDatabase.GUIDToAssetPath(guid);
  10. T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
  11.  
  12. if (asset is WeaponSO weapon && weapon.weaponLevel == targetLevel && !weapon.isBaseSo)
  13. {
  14. matchingAssets.Add(asset);
  15. }
  16. }
  17.  
  18. return matchingAssets;
  19. }
  20.  
  21.  
  22. #if UNITY_EDITOR
  23. [ContextMenu("FIND LEVEL 1 WEAPONS")]
  24. public void FindLevel1Weapons()
  25. {
  26. level1Weapons = ScriptableObjectUtils.FindAllAssetsOfTypeWithLevel<WeaponSO>(folderPath, 1);
  27. }
  28. #endif
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment