public static IEnumerable <Material> GetSelectionAllMaterial(MatSelectMode mode, List <Material> result = null)
        {
            InitList(ref result);

            if ((mode & MatSelectMode.FromScene) != 0)
            {
                // GameObject
                GetAllMaterials(Selection.GetFiltered <GameObject>(SelectionMode.Editable), result);
            }
            if ((mode & MatSelectMode.FromAsset) != 0)
            {
                // Materialアセット自体
                result.AddRange(Selection.GetFiltered <Material>(SelectionMode.Assets));
            }
            // サブフォルダ含めて
            if ((mode & MatSelectMode.FromAssetDeep) == MatSelectMode.FromAssetDeep)
            {
                var folders = Selection.GetFiltered <DefaultAsset>(SelectionMode.Assets)
                              .Select(asset => AssetDatabase.GetAssetPath(asset))
                              .Where(path => !string.IsNullOrWhiteSpace(path))
                              .Distinct()
                              .Where(path => System.IO.File.GetAttributes(path).HasFlag(System.IO.FileAttributes.Directory))
                              .ToArray();
                if (0 < folders.Length)
                {
                    result.AddRange(
                        AssetDatabase.FindAssets("t:Material", folders)
                        .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
                        .Where(path => !string.IsNullOrWhiteSpace(path) && path.EndsWith(".mat"))
                        .Distinct()
                        .Select(path => AssetDatabase.LoadAssetAtPath <Material>(path))
                        .Where(mat => mat != null));
                }
            }
            return(result);
        }
示例#2
0
 public static void SetSelectedMaterials(MatSelectMode mode)
 {
     arguments.Clear();
     arguments.AddRange(MaterialSeeker.GetSelectionAllMaterial(mode));
 }