Rendering设置
Gamma和Linear颜色空间,两者有色差,Gamma有个2.25左右的修正值;
WebGL2.0可用的情况,只支持Deferred Render延迟渲染,且只支持Linear颜色空间;
UnityWebGL使用Video播放工具还不支持WegGL2.0;
使用WebGL1.0对shader有很大的限制,如果shader失效替换WebGL2.0,或者调低shader版本;
这里的设置还关系到屏幕后期处理PostProcessing能不能用;
OtherSetting
Strip Engine Code和Managed Stripping Level大概是什么代码剥离和剥离等级,打包后运行出错有可能就是这里选择了enable;
Prebake Collision Mesh:提前添加碰撞到网格,变复杂场景加载过慢问题,空间换时间;问题;
Optimize Mesh Data:静态分析材质,去掉Mesh中无用的数据,比如切线,多余UV什么的;但是如果有代码动态切换材质使用法线的,打包运行会出错,尽量也别选吧;
PublishingSettings
Enable Exceptions 是否允许打印日志,测试选择打印,报错会使用trycatch,至少能让程序跑起来;
Compression Format 发布版本文件压缩格式,如果出错也可试试看是不是因为压缩问题;
Name Files As Hashes 使用MD5哈希作为每个文件名,在Js中再处理也要用哈希名;
Data caching 允许浏览器缓存,可能需要浏览器权限;
WebGL模板
官方给了mini和Default模板,在Unity安装目录PlaybackEngines/WebGLSupport/BuildTools/WebGLTemplates/中;
可以拷贝官方的模板做修改也放在这个目录,会在playersetting中显示出自定义模板;
修改模板中Index.html即可;
下面是自定义做了浏览器自适应的模板,取消了白色加载条;
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
| <!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Unity WebGL Player | {{{ PRODUCT_NAME }}}</title> <link rel="shortcut icon" href="TemplateData/favicon.ico"> <link rel="stylesheet" href="TemplateData/style.css"> <style> html,body{overflow:hidden;} </style> </head> <body> <div id="unity-container" class="unity-desktop"> <canvas id="unity-canvas" width={{{ WIDTH }}} height={{{ HEIGHT }}}></canvas> <div id="unity-loading-bar"> <div id="unity-logo"></div> <div id="unity-progress-bar-empty"> <div id="unity-progress-bar-full"></div> </div> </div> <div id="unity-mobile-warning"> WebGL builds are not supported on mobile devices. </div> </div> <script> var buildUrl = "Build"; var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}"; var config = { dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}", frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}", codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}", #if MEMORY_FILENAME memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}", #endif #if SYMBOLS_FILENAME symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}", #endif streamingAssetsUrl: "StreamingAssets", companyName: "{{{ COMPANY_NAME }}}", productName: "{{{ PRODUCT_NAME }}}", productVersion: "{{{ PRODUCT_VERSION }}}", };
var container = document.querySelector("#unity-container"); var canvas = document.querySelector("#unity-canvas"); var loadingBar = document.querySelector("#unity-loading-bar"); var progressBarFull = document.querySelector("#unity-progress-bar-full"); var mobileWarning = document.querySelector("#unity-mobile-warning");
let width =0; let height=0; function changeMargin() { width = document.documentElement.clientWidth height = document.documentElement.clientHeight + 8 canvas.style.width = width+"px"; canvas.style.height = height+"px"; }
window.onresize = function () { changeMargin(); }
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) { container.className = "unity-mobile"; config.devicePixelRatio = 1; mobileWarning.style.display = "block"; setTimeout(() => { mobileWarning.style.display = "none"; }, 5000); } else { changeMargin(); } #if BACKGROUND_FILENAME canvas.style.background = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover"; #endif loadingBar.style.display = "block";
let address = "";
var script = document.createElement("script"); script.src = loaderUrl; script.onload = () => { createUnityInstance(canvas, config, (progress) => { progressBarFull.style.width = 100 * progress + "%"; }).then((unityInstance) => { loadingBar.style.display = "none"; unityInstance.SendMessage("GameInit","Login",address); }).catch((message) => { alert(message); }); }; document.body.appendChild(script); </script> </body> </html>
|
打开日志和栈信息
OtherSetting中如下,以及上述的PublishingSetting中Enable Exceptions:

Splash Image
开屏动画,加载条,icon等素材替换;

开屏Logo把DrawMode换成顺序,然后换顺序放上Logo,点Preview可以预览;
WebGL模板文件夹TemplateData下有个css,定义了加载进度条和logo格式,同时也存放了相应图片素材,直接替换或者修改css都可;
图标.ico也在里面,png转ico要转格式;
关于压缩
选择压缩后必须勾选decompression fallback;
设置压缩后,webgl无法识别内部类,也不支持一个cs文件中写入两个class(就离谱);
