forked from alvani/Unity-glTF-Exporter
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Preset.cs
53 lines (46 loc) · 1.2 KB
/
Preset.cs
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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using SimpleJSON;
public class Preset {
public class Shader {
public string vertexShader;
public string fragmentShader;
}
public Dictionary<string, Shader> shaderMap = new Dictionary<string, Shader>();
const string DEFAULT_VERTEX_SHADER = "DefaultVS.glsl";
const string DEFAULT_FRAGMENT_SHADER = "DefaultFS.glsl";
public string GetVertexShader(string shaderName)
{
if (shaderMap.ContainsKey(shaderName))
{
var s = shaderMap[shaderName];
return s.vertexShader;
}
return DEFAULT_VERTEX_SHADER;
}
public string GetFragmentShader(string shaderName)
{
if (shaderMap.ContainsKey(shaderName))
{
var s = shaderMap[shaderName];
return s.fragmentShader;
}
return DEFAULT_FRAGMENT_SHADER;
}
public void Load(string path)
{
var text = File.ReadAllText(path);
var obj = JSON.Parse(text);
var sm = obj["ShaderMap"];
shaderMap.Clear();
foreach (var smc in sm.AsObject.Dict)
{
Shader shader = new Shader();
shader.vertexShader = smc.Value["shaders"]["vertexShader"];
shader.fragmentShader = smc.Value["shaders"]["fragmentShader"];
shaderMap[smc.Key] = shader;
}
}
}