├── Editor.meta ├── Editor ├── WebGLServerEditorWindow.cs ├── WebGLServerEditorWindow.cs.meta ├── com.stinkysteak.webgl-editor-server.asmdef └── com.stinkysteak.webgl-editor-server.asmdef.meta ├── README.md ├── README.md.meta ├── package.json └── package.json.meta /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 600cce33480d49aa9d67d7644e621b0d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/WebGLServerEditorWindow.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.IO; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using Debug = UnityEngine.Debug; 6 | 7 | namespace StinkySteak.WebGLEditorServer 8 | { 9 | public class WebGLServerEditorWindow : EditorWindow 10 | { 11 | private Process _process; 12 | private const string DEFAULT_URL = "http://localhost:" + DEFAULT_PORT; 13 | private const string DEFAULT_PORT = "8080"; 14 | private const string WEB_SERVER_PATH = @"Data\PlaybackEngines\WebGLSupport\BuildTools\SimpleWebServer.exe"; 15 | 16 | private string _lastBuildPath; 17 | 18 | [MenuItem("Tools/WebGL Editor Server")] 19 | public static void SetGameBuild() 20 | => GetWindow("WebGL Editor Server"); 21 | 22 | private void DrawField() 23 | { 24 | GUILayout.BeginHorizontal(); 25 | GUILayout.Label("Custom Last Build Path", GUILayout.Width(150)); 26 | _lastBuildPath = GUILayout.TextField(_lastBuildPath, GUILayout.Height(30)); 27 | GUILayout.EndHorizontal(); 28 | } 29 | 30 | private void OnGUI() 31 | { 32 | GUILayout.Space(10); 33 | GUILayout.Label("WebGL Server Editor", GetHeadingStyle()); 34 | GUILayout.Space(10); 35 | 36 | GUILayout.Label($"Last Build Path: {GetLastBuildPath()}", GUILayout.Height(30)); 37 | DrawField(); 38 | 39 | GUILayout.BeginHorizontal(); 40 | 41 | if (GUILayout.Button("Start Server")) 42 | StartServer(); 43 | 44 | if (GUILayout.Button("Terminate Server")) 45 | TerminateServer(); 46 | 47 | GUILayout.EndHorizontal(); 48 | 49 | if (GUILayout.Button("Launch Browser")) 50 | LaunchBrowser(); 51 | } 52 | 53 | private GUIStyle GetHeadingStyle() 54 | { 55 | return new GUIStyle() 56 | { 57 | normal = new GUIStyleState() 58 | { 59 | textColor = Color.white, 60 | }, 61 | 62 | fontSize = 18 63 | }; 64 | } 65 | 66 | private string GetLastBuildPath() 67 | { 68 | if (!string.IsNullOrEmpty(_lastBuildPath)) 69 | return _lastBuildPath; 70 | 71 | return EditorUserBuildSettings.GetBuildLocation(BuildTarget.WebGL); 72 | } 73 | 74 | private void StartServer() 75 | { 76 | string apppath = Path.GetDirectoryName(EditorApplication.applicationPath); 77 | string lastBuildPath = GetLastBuildPath(); 78 | 79 | _process = new Process(); 80 | _process.StartInfo.FileName = Path.Combine(apppath, WEB_SERVER_PATH); 81 | _process.StartInfo.Arguments = lastBuildPath + $" {DEFAULT_PORT}"; 82 | _process.StartInfo.UseShellExecute = false; 83 | _process.Start(); 84 | 85 | Debug.Log($"[{nameof(WebGLServerEditorWindow)}]: Starting server.... lastBuildPath: {lastBuildPath}"); 86 | } 87 | 88 | private void TerminateServer() 89 | { 90 | try 91 | { 92 | _process.Kill(); 93 | } 94 | catch (System.Exception e) 95 | { 96 | Debug.Log($"[{nameof(WebGLServerEditorWindow)}]: {e.Message}"); 97 | } 98 | } 99 | 100 | private void LaunchBrowser() 101 | { 102 | try 103 | { 104 | if (_process.HasExited) 105 | { 106 | StartServer(); 107 | } 108 | } 109 | catch (System.Exception) 110 | { 111 | StartServer(); 112 | } 113 | 114 | Process b = new Process(); 115 | b.StartInfo.FileName = DEFAULT_URL; 116 | b.Start(); 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /Editor/WebGLServerEditorWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffc735845e17e7f469510011dda577b4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/com.stinkysteak.webgl-editor-server.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.stinkysteak.webgl-editor-server", 3 | "rootNamespace": "", 4 | "references": [], 5 | "includePlatforms": [ 6 | "Editor" 7 | ], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [], 15 | "noEngineReferences": false 16 | } -------------------------------------------------------------------------------- /Editor/com.stinkysteak.webgl-editor-server.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7d9c0f0705a1b047909eb56e7d33356 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity WebGL Editor Server 2 | 3 | This plugin allow you to host a webGL build using unity editor simple web server. So you won't need to use "Build and Run" anymore 4 | 5 | ![Overview](https://github.com/StinkySteak/unity-webgl-server/blob/docs/overview.gif) 6 | 7 | ### How to Use? 8 | 1. Tools > WebGL Editor Server 9 | 2. Put the WebGL HTML File path. (make sure the path has the index.html file) 10 | 3. Start Server 11 | 4. Launch Browser 12 | 13 | ### Credits 14 | bugfinders 15 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5c912fb9644557a4897534f66aa7accc 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.stinkysteak.webgl-editor-server", 3 | "version": "0.1.0", 4 | "displayName": "WebGL Editor Server", 5 | "description": "Unity Plugin to Host WebGL run build locally without \"Build and Run\" with zero dependencies", 6 | "unity": "2021.3", 7 | "author": { 8 | "name": "Stinkysteak", 9 | "email": "stinkysteak@steaksoft.com", 10 | "url": "https://steaksoft.net" 11 | } 12 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6b83d43703f47218ca0a7ea65ede298 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------