Beispiel #1
0
        public static List <Material> GetSelectedMaterialsInProjectHierarchy()
        {
            List <Material>           selectedMaterials     = new List <Material>();
            List <string>             selectedMaterialPaths = new List <string>();
            List <UnityEngine.Object> selection             = new List <UnityEngine.Object>();

            foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
            {
                if (obj.GetType() == typeof(Material) && selectedMaterials.Count <= maxMaterialAllowed)
                {
                    selectedMaterials.Add((Material)obj);
                }
                else
                {
                    selection.Add(obj);
                }
            }

            List <string> selectedFolders = MegascansUtilities.GetSelectedFolders(selection);

            foreach (string folder in selectedFolders)
            {
                selectedMaterialPaths = selectedMaterialPaths.Concat(MegascansUtilities.GetFiles(folder, ".mat")).ToList();
            }

            foreach (string mPath in selectedMaterialPaths)
            {
                Material mat = (Material)AssetDatabase.LoadAssetAtPath(mPath, typeof(Material));
                if (mat != null && selectedMaterials.Count <= maxMaterialAllowed) //4 is the max number of layers currently allowed in the HDRenderPipeline/LayeredLit shader.
                {
                    selectedMaterials.Add(mat);
                }
            }

            return(selectedMaterials);
        }