Skip to content

Commit e117f3c

Browse files
committed
Added copy of LICENSE file when embedding
Fix on the embedder comments remove Less aggressive, will keep comments that are don't start at the beginning of the line, but doesn't cause issues
1 parent ba86e20 commit e117f3c

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

Editor/Tools/EmbedLibraryWindow.cs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
public class EmbedLibraryWindow : EditorWindow
1313
{
1414
[MenuItem(MSSConstants.WINDOW_PATH + "/Embed Library")]
15-
public static void ShowExample()
15+
public static void CreateWindow()
1616
{
17-
EmbedLibraryWindow wnd = GetWindow<EmbedLibraryWindow>();
18-
wnd.titleContent = new GUIContent("Embed Library");
17+
var window = GetWindow<EmbedLibraryWindow>();
18+
window.titleContent = new GUIContent("Embed Library");
1919
}
2020

2121
[Serializable]
22-
private class librarySettings
22+
private class LibrarySettings
2323
{
2424
public string nmsc;
2525
public string variableSink;
@@ -114,17 +114,21 @@ private void EmbedButtonOnclick()
114114
Directory.Delete(path + "/ModularShaderSystem", true);
115115

116116
CopyDirectory(PATH, path, "", false);
117+
118+
string licencePath = PATH.Replace("Editor", "LICENSE");
119+
if (File.Exists(licencePath))
120+
File.Copy(licencePath, path + "/ModularShaderSystem/LICENSE");
117121

118122
AssetDatabase.Refresh();
119123
}
120124

121-
public void SaveSettingsOnFile()
125+
private void SaveSettingsOnFile()
122126
{
123127
string path = EditorUtility.SaveFilePanel("Save settings to file", "Assets", "embedSettings.json", "json");
124128
if (path.Length == 0)
125129
return;
126130

127-
librarySettings settings = new librarySettings
131+
LibrarySettings settings = new LibrarySettings
128132
{
129133
nmsc = _namespaceField.value,
130134
variableSink = _variableKeywordField.value,
@@ -140,7 +144,7 @@ public void SaveSettingsOnFile()
140144
File.WriteAllText(path,JsonUtility.ToJson(settings));
141145
}
142146

143-
public void LoadSettingsFromFile()
147+
private void LoadSettingsFromFile()
144148
{
145149
string path = EditorUtility.OpenFilePanel("Load settings", "Assets", "json");
146150
if (!File.Exists(path))
@@ -149,7 +153,7 @@ public void LoadSettingsFromFile()
149153
return;
150154
}
151155

152-
var settings = JsonUtility.FromJson<librarySettings>(File.ReadAllText(path));
156+
var settings = JsonUtility.FromJson<LibrarySettings>(File.ReadAllText(path));
153157

154158
_namespaceField.value = settings.nmsc;
155159
_variableKeywordField.value = settings.variableSink;
@@ -171,31 +175,9 @@ private void CopyDirectory(string oldPath, string newPath, string subpath, bool
171175

172176
if (Path.GetExtension(file).Equals(".cs") || Path.GetExtension(file).Equals(".uxml"))
173177
{
174-
var lines = new List<string>();
175-
lines.AddRange(File.ReadAllLines(file));
176-
int i = 0;
177-
while (i < lines.Count && !keepComments)
178-
{
179-
int index = lines[i].IndexOf("//", StringComparison.Ordinal);
180-
if (index != -1)
181-
{
182-
if (!string.IsNullOrEmpty(lines[i].Substring(0, index).Trim()))
183-
{
184-
lines[i] = lines[i].Substring(0, index);
185-
i++;
186-
}
187-
else
188-
{
189-
lines.RemoveAt(i);
190-
}
191-
}
192-
else
193-
{
194-
i++;
195-
}
196-
}
197-
198-
string text = string.Join(System.Environment.NewLine, lines);
178+
var lines = new List<string>(File.ReadAllLines(file));
179+
var newLines = lines.Where(line => !line.Trim().StartsWith("//")).ToList();
180+
string text = string.Join(System.Environment.NewLine, newLines);
199181

200182
text = text.Replace(NAMESPACE, _namespaceField.value + ".ModularShaderSystem");
201183

0 commit comments

Comments
 (0)