summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateDataParent.cs
blob: b7c3fd0249a5b46fa28b50b13ba1c91e7ae82550 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>

using System;
using System.Collections.Generic;
using UnityEngine;

namespace AmplifyShaderEditor
{
	public enum TemplateDataType
	{
		LegacySinglePass,
		MultiPass
	}

	[Serializable]
	public class TemplateIncludePragmaContainter
	{
		[SerializeField]
		private int m_nativeTopIndex = -1;

		[SerializeField]
		private List<string> m_nativeDirectivesList = new List<string>();

		[SerializeField]
		private List<string> m_includesList = new List<string>();
		private Dictionary<string,string> m_includesDict = new Dictionary<string,string>();

		[SerializeField]
		private List<string> m_pragmasList = new List<string>();
		private Dictionary<string, string> m_pragmasDict = new Dictionary<string, string>();

		[SerializeField]
		private List<string> m_definesList = new List<string>();
		private Dictionary<string, string> m_definesDict = new Dictionary<string, string>();

		public void RefreshIncludesList()
		{
			if ( m_includesDict.Count != m_includesList.Count )
			{
				m_includesDict.Clear();
				int count = m_includesList.Count;
				for ( int i = 0; i < count; i++ )
				{
					m_includesDict.Add( m_includesList[ i ], m_includesList[ i ] );
				}
			}
		}

		public void RefreshPragmasList()
		{
			if ( m_pragmasDict.Count != m_pragmasList.Count )
			{
				m_pragmasDict.Clear();
				int count = m_pragmasList.Count;
				for ( int i = 0; i < count; i++ )
				{
					m_pragmasDict.Add( m_pragmasList[ i ], m_pragmasList[ i ] );
				}
			}
		}


		public void RefreshDefinesList()
		{
			if ( m_definesDict.Count != m_definesList.Count )
			{
				m_definesDict.Clear();
				int count = m_definesList.Count;
				for ( int i = 0; i < count; i++ )
				{
					m_definesDict.Add( m_definesList[ i ], m_definesList[ i ] );
				}
			}
		}
		
		public bool HasInclude( string include )
		{
			RefreshIncludesList();
			return m_includesDict.ContainsKey( include );
		}

		public bool HasPragma( string pragma )
		{
			RefreshPragmasList();
			return m_pragmasDict.ContainsKey( pragma );
		}

		public bool HasDefine( string pragma )
		{
			RefreshDefinesList();
			return m_definesDict.ContainsKey( pragma );
		}

		public void AddInclude( string include )
		{
			RefreshIncludesList();
			if ( !m_includesDict.ContainsKey( include ) )
			{
				m_includesList.Add( include );
				m_includesDict.Add( include, include );
			}
		}

		public void AddPragma( string pragma )
		{
			RefreshPragmasList();
			if ( !m_pragmasDict.ContainsKey( pragma ) )
			{
				m_pragmasList.Add( pragma );
				m_pragmasDict.Add( pragma, pragma );
			}
		}

		public void AddDefine( string define )
		{
			RefreshDefinesList();
			if ( !m_definesDict.ContainsKey( define ) )
			{
				m_definesList.Add( define );
				m_definesDict.Add( define, define );
			}
		}

		public void AddNativeDirective( string native, int topIndex )
		{
			m_nativeTopIndex = topIndex;
			m_nativeDirectivesList.Add( native );
		}

		public void Destroy()
		{
			m_nativeDirectivesList.Clear();
			m_nativeDirectivesList = null;


			m_includesList.Clear();
			m_includesDict.Clear();
			m_includesList = null;
			m_includesDict = null;

			m_pragmasList.Clear();
			m_pragmasDict.Clear();
			m_pragmasList = null;
			m_pragmasDict = null;

			m_definesList.Clear();
			m_definesDict.Clear();
			m_definesList = null;
			m_definesDict = null;
		}

		public List<string> IncludesList { get { return m_includesList; } }
		public List<string> PragmasList { get { return m_pragmasList; } }
		public List<string> DefinesList { get { return m_definesList; } }
		public List<string> NativeDirectivesList { get { return m_nativeDirectivesList; } }
		public int NativeTopIndex { get { return m_nativeTopIndex; } }

	}

	[Serializable]
	public class TemplateInfoContainer
	{
		public string Id = string.Empty;
		public string Data = string.Empty;
		public int Index = -1;
		public bool IsValid { get { return Index > -1; } }
		public void Reset()
		{
			Id = string.Empty;
			Data = string.Empty;
			Index = -1;
		}
	}

	[Serializable]
	public class TemplateDataParent : ScriptableObject
	{
		[SerializeField]
		protected TemplateDataType m_templateType;

		[SerializeField]
		protected string m_name;

		[SerializeField]
		protected string m_guid;

		[SerializeField]
		protected int m_orderId;

		[SerializeField]
		protected string m_defaultShaderName = string.Empty;

		[SerializeField]
		protected bool m_isValid = true;

		[SerializeField]
		protected bool m_communityTemplate = false;

		public virtual void Destroy() { }
		public virtual bool Reload() { return true; }
		public string Name
		{
			get { return m_name; }
			set
			{
				m_name = value.StartsWith( "Hidden/" ) ? value.Replace( "Hidden/", string.Empty ) : value;
			}
		}
		public string GUID { get { return m_guid; } set { m_guid = value; } }
		public int OrderId { get { return m_orderId; } set { m_orderId = value; } }
		public string DefaultShaderName { get { return m_defaultShaderName; } set { m_defaultShaderName = value; } }
		public bool IsValid { get { return m_isValid; } }
		public TemplateDataType TemplateType { get { return m_templateType; } }
		public virtual void Init( string name, string guid, bool isCommunity ) { m_communityTemplate = isCommunity; }
	}
}