Esempio n. 1
0
        public static void CreateSplitAlphaMaterial(Dictionary <string, string> splitAlphaShaderNames)
        {
            HashSet <string> selectedObjectPaths = new HashSet <string> ();

            foreach (var assetGUID in Selection.assetGUIDs)
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);
                if (AssetDatabase.IsValidFolder(assetPath))
                {
                    selectedObjectPaths.UnionWith(Directory.GetFiles(assetPath, StarPng, SearchOption.AllDirectories));
                }
                else if (assetPath.EndsWith(PNGSuffix))
                {
                    selectedObjectPaths.Add(assetPath);
                }
            }

            foreach (var path in selectedObjectPaths)
            {
                string    materialPath     = System.IO.Path.GetDirectoryName(path);
                string    materialName     = System.IO.Path.GetFileNameWithoutExtension(path);
                Texture2D mainTexture      = AssetDatabase.LoadAssetAtPath <Texture2D> (path);
                var       alphaTexturePath = SplitAlphaTextureCreator.GetAlphaTextureAssetPath(path);
                Texture2D alphaTexture     = AssetDatabase.LoadAssetAtPath <Texture2D> (alphaTexturePath);

                foreach (string shaderName in splitAlphaShaderNames.Keys)
                {
                    CreateSplitAlphaMaterial(splitAlphaShaderNames [shaderName], materialPath + "/" + materialName + shaderName + ".mat", mainTexture, alphaTexture);
                }
            }
        }
Esempio n. 2
0
        public static void Apply(Material m)
        {
            var texture = m.GetTexture("_MainTex");

            if (texture == null || !(texture is Texture2D))
            {
                Debug.LogErrorFormat("{0}::{1} Make sure material have main texture!", "SplitAlphaReplacer", "Apply");
                return;
            }

            var       alphaTexturePath = SplitAlphaTextureCreator.GetAlphaTextureAssetPath(AssetDatabase.GetAssetPath(texture));
            Texture2D alphaTexture     = AssetDatabase.LoadAssetAtPath <Texture2D> (alphaTexturePath);

            if (alphaTexture == null)
            {
                Debug.LogErrorFormat("{0}::{1} Cannot Find Alpha texture at {2}!", "SplitAlphaReplacer", "Apply", alphaTexturePath);
                return;
            }
            m.SetTexture("_AlphaTex", alphaTexture);
        }