Beispiel #1
0
        private static void CleanFilePaths(out string inPath, out string outPath)
        {
            outPath = string.Empty;
            inPath  = EditorSelection.GetSelectedFilePath();
            if (string.IsNullOrEmpty(inPath))
            {
                return;
            }

            outPath =
                $"{Path.GetDirectoryName(inPath)}{Path.DirectorySeparatorChar}{Path.GetFileNameWithoutExtension(inPath)}";
            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }
        }
Beispiel #2
0
        public static void CompileMaterial()
        {
            string path = EditorSelection.GetSelectedFolderPath();

            Shader shader =
                GraphicsSettings.renderPipelineAsset
                    ? GraphicsSettings.renderPipelineAsset.defaultShader
                    : Shader.Find("Standard");

            Material material = new Material(shader);

            Color color = Color.black;

            color.ToRandomColor();
            material.color = color;

            ProjectWindowUtil.CreateAsset(material, $"{path}{Path.DirectorySeparatorChar}material.mat");
            AssetDatabase.Refresh();
        }
        public static void CompileMaterial()
        {
            string path         = EditorSelection.GetSelectedFolderPath();
            string materialName = string.Empty;

            string[] guids = AssetDatabase.FindAssets("t:texture2D", new[] { path });
            if (guids.IsNull())
            {
                Debug.LogWarning("Incorrect Folder Selected");
                return;
            }

            TextureKeywords textureKeywords = Resources.Load <TextureKeywords>("TextureKeywords/texture-keywords");

            if (!textureKeywords)
            {
                textureKeywords = ScriptableObject.CreateInstance <TextureKeywords>();
            }

            CreateMaterial(out Material material);

            foreach (string guid in guids)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(guid);

                materialName = string.IsNullOrEmpty(materialName)
                    ? "material.mat"
                    : $"{Path.GetFileName(Path.GetDirectoryName(assetPath))}.mat";

                Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);

                SetTextureMap(textureKeywords.BaseMapKeys, texture, material, _BaseMap);
                SetTextureMap(textureKeywords.MetallicMapKeys, texture, material, _MetallicGlossMap);
                SetTextureMap(textureKeywords.SpecularMapKeys, texture, material, _SpecGlossMap);
                SetTextureMap(textureKeywords.OcclusionMapKeys, texture, material, _OcclusionMap);
                SetNormalMap(textureKeywords, texture, assetPath, material);
            }

            ProjectWindowUtil.CreateAsset(material, $"{path}{Path.DirectorySeparatorChar}{materialName}");
            AssetDatabase.Refresh();
        }