PreShaderPropExporter.cs
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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<string, ShaderProps> m_shaderPropMap;
public static ShaderProps GetPropsForSupportedShader(string shaderName)
{
if (m_shaderPropMap == null)
{
m_shaderPropMap = new Dictionary<string, ShaderProps>();
foreach (var prop in typeof(PreShaderPropExporter).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
{
if (prop.GetCustomAttributes(typeof(PreExportShaderAttribute), true).Any())
{
var kv = (KeyValuePair<string, ShaderProps>)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
}
}
}