Skip to content

Commit 1347f10

Browse files
committed
Added a menu item to copy the WebGLTemplates folder from the Package folder to the Assets folder
1 parent 9fa22ae commit 1347f10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+107
-0
lines changed

MainProject/Assets/WebGLTemplates

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Packages/webxr/Hidden~/WebGLTemplates

Packages/webxr/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "WebXR.Editor",
3+
"references": [],
4+
"includePlatforms": [
5+
"Editor"
6+
],
7+
"excludePlatforms": [],
8+
"allowUnsafeCode": false,
9+
"overrideReferences": true,
10+
"precompiledReferences": [],
11+
"autoReferenced": false,
12+
"defineConstraints": [],
13+
"versionDefines": [],
14+
"noEngineReferences": false
15+
}

Packages/webxr/Editor/WebXR.Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/webxr/Editor/WebXRMenu.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using System.IO;
4+
5+
namespace WebXR.Editor
6+
{
7+
public class WebXRMenu : UnityEditor.EditorWindow
8+
{
9+
public TextAsset packageReference;
10+
11+
[MenuItem("Window/WebXR/Copy WebGLTemplates")]
12+
static void CopyWebGLTemplates()
13+
{
14+
if (!EditorUtility.DisplayDialog("Copy WebGLTemplates", "This action might override your WebGLTemplates folders and files. Make sure to have a backup", "Continue", "Cancel"))
15+
{
16+
return;
17+
}
18+
// Ugly hack to get package path by asset reference
19+
WebXRMenu webXRMenu = (WebXRMenu)ScriptableObject.CreateInstance("WebXRMenu");
20+
string packageAssetFullPath = Path.GetFullPath(AssetDatabase.GetAssetPath(webXRMenu.packageReference));
21+
DestroyImmediate(webXRMenu);
22+
string packagePath = Path.GetDirectoryName(packageAssetFullPath);
23+
24+
CopyFolder(Path.Combine(packagePath, "Hidden~"), Application.dataPath);
25+
AssetDatabase.Refresh();
26+
}
27+
28+
// modified version of https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories
29+
private static void CopyFolder(string sourceFolderName, string destFolderName)
30+
{
31+
DirectoryInfo directory = new DirectoryInfo(sourceFolderName);
32+
33+
DirectoryInfo[] directories = directory.GetDirectories();
34+
if (!Directory.Exists(destFolderName))
35+
{
36+
Directory.CreateDirectory(destFolderName);
37+
}
38+
39+
FileInfo[] files = directory.GetFiles();
40+
// In the source repository, it'll throw an error,
41+
// as it'll try to copy from the same file, to the same file (symlink)
42+
foreach (FileInfo file in files)
43+
{
44+
string temppath = Path.Combine(destFolderName, file.Name);
45+
try
46+
{
47+
file.CopyTo(temppath, true);
48+
}
49+
catch (IOException exception)
50+
{
51+
Debug.LogError(exception.Message);
52+
}
53+
}
54+
55+
foreach (DirectoryInfo subFolder in directories)
56+
{
57+
string temppath = Path.Combine(destFolderName, subFolder.Name);
58+
CopyFolder(subFolder.FullName, temppath);
59+
}
60+
}
61+
}
62+
}

Packages/webxr/Editor/WebXRMenu.cs.meta

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)