diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps.meta b/Assets/VRM/ShaderProperty.meta similarity index 57% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps.meta rename to Assets/VRM/ShaderProperty.meta index c49cf8b4c..4b06ef7be 100644 --- a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps.meta +++ b/Assets/VRM/ShaderProperty.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 3fa98374d2ce76443981cc61ab80e6ce +guid: f877649750df3814aa5272250b22678c folderAsset: yes -timeCreated: 1533035745 -licenseType: Free DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/VRM/ShaderProperty/Editor.meta b/Assets/VRM/ShaderProperty/Editor.meta new file mode 100644 index 000000000..8ccaa983d --- /dev/null +++ b/Assets/VRM/ShaderProperty/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 36a5a07493511bd49b1ad9dbad2683d2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/ShaderProperty/Editor/ShaderPropMenu.cs b/Assets/VRM/ShaderProperty/Editor/ShaderPropMenu.cs new file mode 100644 index 000000000..b13dec97e --- /dev/null +++ b/Assets/VRM/ShaderProperty/Editor/ShaderPropMenu.cs @@ -0,0 +1,99 @@ +using System.Reflection; +using System.Linq; +using UnityEditor; +using UnityEngine; +using System.IO; +using UniGLTF.ShaderPropExporter; +using System.Collections.Generic; + +namespace UniGLTF +{ + public static class ShaderPropMenu + { +#if VRM_DEVELOP + [MenuItem("VRM/ShaderProperty/PreExport ShaderProps")] +#endif + public static void PreExport() + { + foreach (var fi in typeof(PreExportShaders).GetFields( + BindingFlags.Static + | BindingFlags.Public + | BindingFlags.NonPublic)) + { + var attr = fi.GetCustomAttributes(true).FirstOrDefault(y => y is PreExportShadersAttribute); + if (attr != null) + { + var supportedShaders = fi.GetValue(null) as SupportedShader[]; + foreach (var supported in supportedShaders) + { + PreExport(supported); + } + } + } + } + + static string EscapeShaderName(string name) + { + return name.Replace("/", "_").Replace(" ", "_"); + } + + static string ExportDir + { + get + { + return Application.dataPath + "/VRM/ShaderProperty/Runtime"; + } + } + + static void PreExport(SupportedShader supportedShader) + { + var shader = Shader.Find(supportedShader.ShaderName); + var props = ShaderProps.FromShader(shader); + + var path = Path.Combine(ExportDir, supportedShader.TargetFolder); + path = Path.Combine(path, EscapeShaderName(supportedShader.ShaderName) + ".cs").Replace("\\", "/"); + Debug.LogFormat("PreExport: {0}", path); + File.WriteAllText(path, ToString(props, shader.name)); + } + + static string ToString(ShaderProps props, string shaderName) + { + var list = new List(); + foreach (var prop in props.Properties) + { + list.Add(string.Format("new ShaderProperty(\"{0}\", ShaderPropertyType.{1})\r\n", prop.Key, prop.ShaderPropertyType)); + } + + return string.Format(@"using System.Collections.Generic; + + +namespace UniGLTF.ShaderPropExporter +{{ + public static partial class PreShaderPropExporter + {{ + [PreExportShader] + static KeyValuePair {0} + {{ + get + {{ + return new KeyValuePair( + ""{1}"", + new ShaderProps + {{ + Properties = new ShaderProperty[]{{ +{2} + }} + }} + ); + }} + }} + }} +}} +" +, EscapeShaderName(shaderName) +, shaderName +, string.Join(",", list.ToArray())); + } + + } +} diff --git a/Assets/VRM/ShaderProperty/Editor/ShaderPropMenu.cs.meta b/Assets/VRM/ShaderProperty/Editor/ShaderPropMenu.cs.meta new file mode 100644 index 000000000..0626004d1 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Editor/ShaderPropMenu.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5eb12c186c6337e4db278b5f01d47cae +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/ShaderProperty/Editor/ShaderProperty.Editor.asmdef b/Assets/VRM/ShaderProperty/Editor/ShaderProperty.Editor.asmdef new file mode 100644 index 000000000..382622a74 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Editor/ShaderProperty.Editor.asmdef @@ -0,0 +1,12 @@ +{ + "name": "ShaderProperty.Editor", + "references": [ + "ShaderProperty.Runtime" + ], + "optionalUnityReferences": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false +} \ No newline at end of file diff --git a/Assets/VRM/ShaderProperty/Editor/ShaderProperty.Editor.asmdef.meta b/Assets/VRM/ShaderProperty/Editor/ShaderProperty.Editor.asmdef.meta new file mode 100644 index 000000000..f5affb986 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Editor/ShaderProperty.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bc66ece0f33b52446a0830c05781d4db +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/ShaderProperty/Runtime.meta b/Assets/VRM/ShaderProperty/Runtime.meta new file mode 100644 index 000000000..8fa342dbb --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dd900b6f302c9404b99d77a1ae3d00be +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/ShaderProperty/Runtime/GLTF.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF.meta new file mode 100644 index 000000000..38d4fd8e7 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/GLTF.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d9c97ad7f5bbcac489a47a2f34dfff00 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/ShaderProperty/Runtime/GLTF/PreExportShaders_GLTF.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/PreExportShaders_GLTF.cs new file mode 100644 index 000000000..f6fcb7675 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/GLTF/PreExportShaders_GLTF.cs @@ -0,0 +1,20 @@ +namespace UniGLTF.ShaderPropExporter +{ + public static partial class PreExportShaders + { + const string GLTF_FOLDER = "GLTF"; + +#pragma warning disable 414 + [PreExportShaders] + static SupportedShader[] SupportedShaders = new SupportedShader[] + { + new SupportedShader(GLTF_FOLDER, "Standard"), + new SupportedShader(GLTF_FOLDER, "Unlit/Color"), + new SupportedShader(GLTF_FOLDER, "Unlit/Texture"), + new SupportedShader(GLTF_FOLDER, "Unlit/Transparent"), + new SupportedShader(GLTF_FOLDER, "Unlit/Transparent Cutout"), + new SupportedShader(GLTF_FOLDER, "UniGLTF/UniUnlit"), + }; +#pragma warning restore 414 + } +} diff --git a/Assets/VRM/ShaderProperty/Runtime/GLTF/PreExportShaders_GLTF.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/PreExportShaders_GLTF.cs.meta new file mode 100644 index 000000000..fa17b5099 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/GLTF/PreExportShaders_GLTF.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 90dcef1978c51e74386b76d77689dc82 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Standard.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/Standard.cs similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Standard.cs rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Standard.cs diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Standard.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/Standard.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Standard.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Standard.cs.meta diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/UniGLTF_UniUnlit.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/UniGLTF_UniUnlit.cs similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/UniGLTF_UniUnlit.cs rename to Assets/VRM/ShaderProperty/Runtime/GLTF/UniGLTF_UniUnlit.cs diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/UniGLTF_UniUnlit.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/UniGLTF_UniUnlit.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/UniGLTF_UniUnlit.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/GLTF/UniGLTF_UniUnlit.cs.meta diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Color.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Color.cs similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Color.cs rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Color.cs diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Color.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Color.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Color.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Color.cs.meta diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Texture.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Texture.cs similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Texture.cs rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Texture.cs diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Texture.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Texture.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Texture.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Texture.cs.meta diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent.cs similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent.cs rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent.cs diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent.cs.meta diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent_Cutout.cs b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent_Cutout.cs similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent_Cutout.cs rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent_Cutout.cs diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent_Cutout.cs.meta b/Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent_Cutout.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/PreExportShaderProps/Unlit_Transparent_Cutout.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/GLTF/Unlit_Transparent_Cutout.cs.meta diff --git a/Assets/VRM/ShaderProperty/Runtime/PreShaderPropExporter.cs b/Assets/VRM/ShaderProperty/Runtime/PreShaderPropExporter.cs new file mode 100644 index 000000000..bdc6b49da --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/PreShaderPropExporter.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + + +namespace UniGLTF.ShaderPropExporter +{ + public class PreExportShadersAttribute : Attribute { } + public class PreExportShaderAttribute : Attribute { } + + public struct SupportedShader + { + public string TargetFolder; + public string ShaderName; + + public SupportedShader(string targetFolder, string shaderName) + { + TargetFolder = targetFolder; + ShaderName = shaderName; + } + } + + public static partial class PreShaderPropExporter + { + static Dictionary m_shaderPropMap; + + public static ShaderProps GetPropsForSupportedShader(string shaderName) + { + if (m_shaderPropMap == null) + { + m_shaderPropMap = new Dictionary(); + foreach (var prop in typeof(PreShaderPropExporter).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) + { + if (prop.GetCustomAttributes(typeof(PreExportShaderAttribute), true).Any()) + { + var kv = (KeyValuePair)prop.GetValue(null, null); + m_shaderPropMap.Add(kv.Key, kv.Value); + } + } + } + + ShaderProps props; + if (m_shaderPropMap.TryGetValue(shaderName, out props)) + { + return props; + } + +#if UNITY_EDITOR + // fallback + Debug.LogWarningFormat("{0} is not predefined shader. Use ShaderUtil", shaderName); + var shader = Shader.Find(shaderName); + return ShaderProps.FromShader(shader); +#else + return null; +#endif + } + } +} diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/PreShaderPropExporter.cs.meta b/Assets/VRM/ShaderProperty/Runtime/PreShaderPropExporter.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/PreShaderPropExporter.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/PreShaderPropExporter.cs.meta diff --git a/Assets/VRM/ShaderProperty/Runtime/ShaderProperty.Runtime.asmdef b/Assets/VRM/ShaderProperty/Runtime/ShaderProperty.Runtime.asmdef new file mode 100644 index 000000000..ed0a498d0 --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/ShaderProperty.Runtime.asmdef @@ -0,0 +1,8 @@ +{ + "name": "ShaderProperty.Runtime", + "references": [], + "optionalUnityReferences": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false +} \ No newline at end of file diff --git a/Assets/VRM/ShaderProperty/Runtime/ShaderProperty.Runtime.asmdef.meta b/Assets/VRM/ShaderProperty/Runtime/ShaderProperty.Runtime.asmdef.meta new file mode 100644 index 000000000..ec0da628b --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/ShaderProperty.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 301b251fd9834274c9228e0532f444f7 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/ShaderProps.cs b/Assets/VRM/ShaderProperty/Runtime/ShaderProps.cs similarity index 62% rename from Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/ShaderProps.cs rename to Assets/VRM/ShaderProperty/Runtime/ShaderProps.cs index 49a3ba77a..36d9a8258 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/ShaderProps.cs +++ b/Assets/VRM/ShaderProperty/Runtime/ShaderProps.cs @@ -62,50 +62,6 @@ namespace UniGLTF.ShaderPropExporter Properties = properties.ToArray(), }; } - - static string EscapeShaderName(string name) - { - return name.Replace("/", "_").Replace(" ", "_"); - } - - public string ToString(string shaderName) - { - var list = new List(); - foreach (var prop in Properties) - { - list.Add(string.Format("new ShaderProperty(\"{0}\", ShaderPropertyType.{1})\r\n", prop.Key, prop.ShaderPropertyType)); - } - - return string.Format(@"using System.Collections.Generic; - - -namespace UniGLTF.ShaderPropExporter -{{ - public static partial class PreShaderPropExporter - {{ - [PreExportShader] - static KeyValuePair {0} - {{ - get - {{ - return new KeyValuePair( - ""{1}"", - new ShaderProps - {{ - Properties = new ShaderProperty[]{{ -{2} - }} - }} - ); - }} - }} - }} -}} -" -, EscapeShaderName(shaderName) -, shaderName -, String.Join(",", list.ToArray())); - } #endif } } diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/ShaderProps.cs.meta b/Assets/VRM/ShaderProperty/Runtime/ShaderProps.cs.meta similarity index 100% rename from Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/ShaderProps.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/ShaderProps.cs.meta diff --git a/Assets/VRM/ShaderProperty/Runtime/VRM.meta b/Assets/VRM/ShaderProperty/Runtime/VRM.meta new file mode 100644 index 000000000..6d0ee19da --- /dev/null +++ b/Assets/VRM/ShaderProperty/Runtime/VRM.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eb31f565eeca6164694b06ccfe3bc251 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMPreShaderPropExporter.cs b/Assets/VRM/ShaderProperty/Runtime/VRM/PreExportShaders_VRM.cs similarity index 83% rename from Assets/VRM/UniVRM/Scripts/Format/VRMPreShaderPropExporter.cs rename to Assets/VRM/ShaderProperty/Runtime/VRM/PreExportShaders_VRM.cs index 9654a7179..f246304c9 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMPreShaderPropExporter.cs +++ b/Assets/VRM/ShaderProperty/Runtime/VRM/PreExportShaders_VRM.cs @@ -1,8 +1,8 @@ namespace UniGLTF.ShaderPropExporter { - public static partial class PreShaderPropExporter + public static partial class PreExportShaders { - const string VRM_TARGET_FOLDER = "VRM/Scripts"; + const string VRM_TARGET_FOLDER = "VRM"; [PreExportShaders] public static SupportedShader[] VRMSupportedShaders = new SupportedShader[] { diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMPreShaderPropExporter.cs.meta b/Assets/VRM/ShaderProperty/Runtime/VRM/PreExportShaders_VRM.cs.meta similarity index 100% rename from Assets/VRM/UniVRM/Scripts/Format/VRMPreShaderPropExporter.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/VRM/PreExportShaders_VRM.cs.meta diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_MToon.cs b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_MToon.cs similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_MToon.cs rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_MToon.cs diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_MToon.cs.meta b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_MToon.cs.meta similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_MToon.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_MToon.cs.meta diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitCutout.cs similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitCutout.cs diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs.meta b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitCutout.cs.meta similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitCutout.cs.meta diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTexture.cs similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTexture.cs diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs.meta b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTexture.cs.meta similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTexture.cs.meta diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparent.cs similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparent.cs diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs.meta b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparent.cs.meta similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparent.cs.meta diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparentZWrite.cs similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparentZWrite.cs diff --git a/Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs.meta b/Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparentZWrite.cs.meta similarity index 100% rename from Assets/VRM/UniVRM/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs.meta rename to Assets/VRM/ShaderProperty/Runtime/VRM/VRM_UnlitTransparentZWrite.cs.meta diff --git a/Assets/VRM/UniGLTF/Editor/UniGLTF.Editor.asmdef b/Assets/VRM/UniGLTF/Editor/UniGLTF.Editor.asmdef index 371219aad..3fdf35234 100644 --- a/Assets/VRM/UniGLTF/Editor/UniGLTF.Editor.asmdef +++ b/Assets/VRM/UniGLTF/Editor/UniGLTF.Editor.asmdef @@ -1,7 +1,8 @@ { "name": "UniGLTF.Editor", "references": [ - "VRM" + "VRM", + "ShaderProperty.Runtime" ], "optionalUnityReferences": [], "includePlatforms": [ diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter.meta b/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter.meta index 85372c3fb..0c999e6dd 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter.meta +++ b/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f877649750df3814aa5272250b22678c +guid: 892bd9a40a0e26a48b55fcb93590bf46 folderAsset: yes timeCreated: 1533542717 licenseType: Free diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/PreShaderPropExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/PreShaderPropExporter.cs deleted file mode 100644 index afa6be872..000000000 --- a/Assets/VRM/UniGLTF/Scripts/IO/ShaderPropExporter/PreShaderPropExporter.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using UnityEngine; -#if UNITY_EDITOR -using UnityEditor; -#endif - - -namespace UniGLTF.ShaderPropExporter -{ - public class PreExportShadersAttribute : Attribute { } - public class PreExportShaderAttribute : Attribute { } - - public struct SupportedShader - { - public string TargetFolder; - public string ShaderName; - - public SupportedShader(string targetFolder, string shaderName) - { - TargetFolder = targetFolder; - ShaderName = shaderName; - } - } - - public static partial class PreShaderPropExporter - { - const string TARGET_FOLDER = "UniGLTF/Core/Scripts"; - -#pragma warning disable 414 - [PreExportShaders] - static SupportedShader[] SupportedShaders = new SupportedShader[] - { - new SupportedShader(TARGET_FOLDER, "Standard"), - new SupportedShader(TARGET_FOLDER, "Unlit/Color"), - new SupportedShader(TARGET_FOLDER, "Unlit/Texture"), - new SupportedShader(TARGET_FOLDER, "Unlit/Transparent"), - new SupportedShader(TARGET_FOLDER, "Unlit/Transparent Cutout"), - new SupportedShader(TARGET_FOLDER, "UniGLTF/UniUnlit"), - }; -#pragma warning restore 414 - -#if UNITY_EDITOR - [MenuItem(UniGLTFVersion.MENU + "/PreExport ShaderProps")] - public static void PreExport() - { - foreach (var fi in typeof(PreShaderPropExporter).GetFields( - BindingFlags.Static - | BindingFlags.Public - | BindingFlags.NonPublic)) - { - var attr = fi.GetCustomAttributes(true).FirstOrDefault(y => y is PreExportShadersAttribute); - if (attr != null) - { - var supportedShaders = fi.GetValue(null) as SupportedShader[]; - foreach (var supported in supportedShaders) - { - PreExport(supported); - } - } - } - } - - static string EscapeShaderName(string name) - { - return name.Replace("/", "_").Replace(" ", "_"); - } - - static UnityPath GetExportDir(string target) - { - foreach (var x in UnityPath.FromUnityPath("Assets").TravserseDir()) - { - if (x.Value.EndsWith(target)) - { - var dir = x.Child("PreExportShaderProps"); - dir.EnsureFolder(); - return dir; - } - } - throw new Exception(target + " not found"); - } - - static void PreExport(SupportedShader supportedShader) - { - var path = GetExportDir(supportedShader.TargetFolder).Child(EscapeShaderName(supportedShader.ShaderName) + ".cs"); - Debug.LogFormat("PreExport: {0}", path.FullPath); - - var shader = Shader.Find(supportedShader.ShaderName); - var props = ShaderProps.FromShader(shader); - - File.WriteAllText(path.FullPath, props.ToString(shader.name)); - } -#endif - - #region Runtime - static Dictionary m_shaderPropMap; - - public static ShaderProps GetPropsForSupportedShader(string shaderName) - { - if (m_shaderPropMap == null) - { - m_shaderPropMap = new Dictionary(); - foreach (var prop in typeof(PreShaderPropExporter).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) - { - if (prop.GetCustomAttributes(typeof(PreExportShaderAttribute), true).Any()) - { - var kv = (KeyValuePair)prop.GetValue(null, null); - m_shaderPropMap.Add(kv.Key, kv.Value); - } - } - } - - ShaderProps props; - if (m_shaderPropMap.TryGetValue(shaderName, out props)) - { - return props; - } - -#if UNITY_EDITOR - // fallback - Debug.LogWarningFormat("{0} is not predefined shader. Use ShaderUtil", shaderName); - var shader = Shader.Find(shaderName); - return ShaderProps.FromShader(shader); -#else - return null; -#endif - } - #endregion - } -} diff --git a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps.meta b/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps.meta index 30855e0fe..4ba368329 100644 --- a/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps.meta +++ b/Assets/VRM/UniGLTF/Scripts/PreExportShaderProps.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d9c97ad7f5bbcac489a47a2f34dfff00 +guid: 98bc58647c431d04f8633bd7341c862b folderAsset: yes timeCreated: 1533538930 licenseType: Free diff --git a/Assets/VRM/VRM.asmdef b/Assets/VRM/VRM.asmdef index f088e65c3..661c2b138 100644 --- a/Assets/VRM/VRM.asmdef +++ b/Assets/VRM/VRM.asmdef @@ -5,7 +5,8 @@ "DepthFirstScheduler", "UniUnlit", "UniHumanoid", - "UniJSON" + "UniJSON", + "ShaderProperty.Runtime" ], "optionalUnityReferences": [], "includePlatforms": [],