当前位置:网站首页>Exploration of unity webgl
Exploration of unity webgl
2022-06-30 04:51:00 【Answer-3】
from :https://www.cnblogs.com/yaukey/p/unity_webgl_explore_1.html
Found Unity Official information of , If we need to use WebGL There are several challenges to face :
- Native Plugin: In other words, various native plug-ins (C/C++ And other compiled local machine code libraries ), Our challenge is to use SLua.
- Multithreading :WebGL The client cannot support any multithreaded code , because JavaScript There is no implementation of multithreading ,C# The end uses similar System.Threading And other libraries will not be compiled into corresponding js Code .
- Network module : Conventional Socket Can't use , You have to use WebSocket perhaps xxx,System.Net, In especial UnityEngine.Net.Sockets None of them WebGL Server-side implementation , So the transformation will not be compiled correctly ;Unity Can be used in WWW and UnityWebRequest, Or use the new version to support WebGL Of Unity Networking API; Or directly at JavaScript Use in WebSockets and WebRTC To realize network layer functions .
- Rendering :WebGL The graphic api Is based on OpenGL ES 2.0;GI Only support Baked GI( We didn't use it );Procedural Materials I won't support it ( We didn't use it );Linear Rendering I won't support it ( We didn't use it );MovieTextures I won't support it ( We didn't use it );WebGL Shader code restrictions: At present, it is understood as in shader Only constants are supported in code , The index value or union of the loop is used as the index to access the array and matrix , The only exception is Vertex Shader Medium visit uniform You can use any expression , In addition, there is the limitation of circulation , Not available “ Count cycle - Assign a constant value when initializing a variable , Increase or decrease a constant value each time you loop ” Other ways , And does not support while loop .( At present, we don't use the subscript expression of array or matrix , Nor does it use complex loops , You may need to check carefully later ).
- Audio Almost half of them api I won't support it , Compatibility modification is required later , There should be a lot of trouble .
- Others will not be considered for the time being , The above items directly determine whether we can Port come out , Efficiency issues are not considered first .
First from Native Plugin Starting with ,Lua This is the first hurdle to pass . The official gave two good documents :WebGL: Interacting with browser scripting and Unity WebGL The underlying plug-ins in ,WebGL It's through IL2CPP Will all C# Code to C++, This allows you to use the LLVM Of Emscripten The tool chain will be all C++ The code is compiled based on asm.js Of JavaScript Code , In this way, you can support Html5 On the browser of .
We used SLua plug-in unit , So now I need to use Lua To participate in the compilation and packaging process . It's lucky that our project decided to change from the original one after discussion this year LuaJit Upgrade to Lua 5.3, If it is LuaJit The compilation of the project itself produces a large number of assembly code for the target platform to finally generate , It has great platform specificity , So even using LuaJit The source code of is also unusable WebGL Of , It still needs to be used directly Lua 5.1 perhaps 5.3 Source code .
Create a new empty one Unity engineering , Import SLua plug-in unit , Switch to WebGL platform , stay Plugins New folder WebGL, Create a new one C Code files such as :lua.dll.c, Then the latest version Lua5.3 Unzip the source code to a local directory :(LuaSrcDir), All the code is there (LuaSrcDir), All the code is there (LuaSrcDir)/src in , take slua.c Copy it in , But exclude lua.c,luac.c These two documents .
stay lua.dll.c Add the following :
#define LUA_COMPAT_5_1 #define LUA_COMPAT_5_2 // Lua source code only, relative . #include “$(LuaSrcRelativePath)/src/lapi.c” #include “$(LuaSrcRelativePath)/src/lauxlib” #include “$(LuaSrcRelativePath)/src/lbaselib.c” … // Add all lua source file *.c, exclude lua.c, luac.c. //#include "$(LuaSrcRelativePath)/src/lua.c" //#include "$(LuaSrcRelativePath)/src/luac.c" #include “$(LuaSrcRelativePath)/src/slua.c”
Be careful : All the above contents are added Lua The source file , Excluding header files , Which precompiled macros should be used at the beginning , It depends on your project .
In addition, due to Lua 5.3 The problem of downward compatibility , If you define LUA_COMPAT_5_1 after ,LUA_COMPAT_MODULE Will be defined , Then the compatible implementation will be compiled :luaL_findtable, and SLua In order to be compatible, I wrote an extra , So it can be deleted at this time slua.c In the implementation of , Otherwise, redefinition errors will occur during compilation .
The next in Unity Player Setting Add precompiled macros to LUA_5_3 take SLua Switch to 5.3 Implementation version of , Then you can add a sample scenario to the build list ,BuildAndRun, You can see that SLua Of Demo The scene runs correctly on the browser .
thus ,Lua Of Native Plugin Part of it has been completed , You can go down .
边栏推荐
- PBR material: basic principle and simple fabrication
- Royal Albert Hall, a popular landmark in London
- [UGV] schematic diagram of UGV version 32
- Thread safety and processing caused by multithreading
- 為什麼win10開熱點後電腦沒有網絡?
- Break through the existing customer group marketing, and try customer grouping management (including clustering model and other practical effect evaluation)
- JPA复合主键使用
- 【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter
- svg和canvas的区别
- Keywords implements and @override
猜你喜欢
Create transfer generation point
Force buckle 349 Intersection of two arrays
【Paper】2016_ A Learning-Based Fault Tolerant Tracking Control of an Unmanned Quadrotor Helicopter
图的一些表示方式、邻居和度的介绍
Winter vacation parent-child tour, these new york attractions are not only fun but also knowledge
【Paper】2017_ Distributed control for high-speed trains movements
Unity is associated with vs. there is a compiler problem when opening
redis集群概念
【Paper】2019_ Distributed Cooperative Control of a High-speed Train
【Paper】2013_ An efficient model predictive control scheme for an unmanned quadrotor helicopter
随机推荐
amd锐龙CPU A320系列主板如何安装win7
My idea configuration
A must see cruise experience in Bangkok: visit the Mekong River and enjoy the scenery on both sides of the river
Geotrustov wildcard
【Paper】2017_ Distributed control for high-speed trains movements
[UAV] kinematic analysis from single propeller to four rotor UAV
Unreal 4 learning notes - set player birth point
Draw on screen border in Commodore 64
Method of applying for code signing certificate by enterprise
一条命令运行rancher
Is the Flink connector JDBC open source? Where can I download it
Autowired注解警告的解决办法
IO stream, character read / write, copy
SCM learning notes: interrupt learning
力扣292周赛题解
A virtual reality secret room escape adventure, let you see Technology Singapore
Deep learning ----- different methods to realize inception-10
Create transfer generation point
Unity automatic pathfinding
力扣59. 螺旋矩阵 II