diff --git a/packages/webgl/upm/Runtime/Plugins/WebGL/puerts.jslib b/packages/webgl/upm/Runtime/Plugins/WebGL/puerts.jslib index 54cb217..79970c4 100644 --- a/packages/webgl/upm/Runtime/Plugins/WebGL/puerts.jslib +++ b/packages/webgl/upm/Runtime/Plugins/WebGL/puerts.jslib @@ -1,44 +1,4 @@ -var exportDLL = { - InitPuertsWebGL: function () { - var global = typeof global != 'undefined' ? global : window; - if (!global.PuertsWebGL) { - throw new Error('cannot found PuertsWebGL script. please find some way to load puerts-runtime.js'); - } - let oldUpdateGlobalBufferAndViews = updateGlobalBufferAndViews; - updateGlobalBufferAndViews = function (buf) { - oldUpdateGlobalBufferAndViews(buf); - global.PuertsWebGL.updateGlobalBufferAndViews( - HEAP8, - HEAPU8, - HEAP32, - HEAPF32, - HEAPF64 - ); - } - global.PuertsWebGL.Init({ - UTF8ToString, - _malloc, - _free, - _setTempRet0, - stringToUTF8, - lengthBytesUTF8, - stackAlloc, - stackSave, - stackRestore, - _CallCSharpFunctionCallback: Module._CallCSharpFunctionCallback, - _CallCSharpConstructorCallback: Module._CallCSharpConstructorCallback, - _CallCSharpDestructorCallback: Module._CallCSharpDestructorCallback, - - HEAP8, - HEAPU8, - HEAP32, - HEAPF32, - HEAPF64, - }); - global.PuertsWebGL.inited = true; - }, -}; - +var exportDLL = {}; [ "GetLibVersion", @@ -132,14 +92,56 @@ var exportDLL = { "LogicTick", "SetLogCallback", ].forEach(function (methodName) { - exportDLL[methodName] = new Function( "var global = typeof global != 'undefined' ? global : window; " + "if (!global.PuertsWebGL) throw new Error('cannot found PuertsWebGL script. please find some way to load puerts-runtime.js');" + - "if (!global.PuertsWebGL.inited) throw new Error('please use Puerts.WebGL.MainEnv.Get() to create JsEnv'); " + "if (global.PuertsWebGL.debug) console.log('WebGL DLL:" + methodName + "'); "+ "return global.PuertsWebGL['" + methodName + "'].apply(this, arguments)" ); }) -mergeInto(LibraryManager.library, exportDLL); \ No newline at end of file +mergeInto(LibraryManager.library, exportDLL); + +mergeInto(LibraryManager.library, { + GetApiLevel__postset: ` + addOnInit(function () { + var global = typeof global != "undefined" ? global : window; + if (!global.PuertsWebGL) { + throw new Error( + "cannot found PuertsWebGL script. please find some way to load puerts-runtime.js" + ); + } + let oldUpdateGlobalBufferAndViews = updateGlobalBufferAndViews; + updateGlobalBufferAndViews = function (buf) { + oldUpdateGlobalBufferAndViews(buf); + global.PuertsWebGL.updateGlobalBufferAndViews( + HEAP8, + HEAPU8, + HEAP32, + HEAPF32, + HEAPF64 + ); + }; + global.PuertsWebGL.Init({ + UTF8ToString, + _malloc, + _free, + _setTempRet0, + stringToUTF8, + lengthBytesUTF8, + stackAlloc, + stackSave, + stackRestore, + _CallCSharpFunctionCallback: Module._CallCSharpFunctionCallback, + _CallCSharpConstructorCallback: Module._CallCSharpConstructorCallback, + _CallCSharpDestructorCallback: Module._CallCSharpDestructorCallback, + + HEAP8, + HEAPU8, + HEAP32, + HEAPF32, + HEAPF64, + }); + global.PuertsWebGL.inited = true; + });`, +}); \ No newline at end of file diff --git a/packages/webgl/upm/Runtime/WebGL.cs b/packages/webgl/upm/Runtime/WebGL.cs deleted file mode 100644 index 1aefca5..0000000 --- a/packages/webgl/upm/Runtime/WebGL.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Collections.Generic; - -namespace Puerts -{ - namespace WebGL - { - public class MainEnv - { - private static JsEnv jsEnvInstance; - - public static JsEnv Get() - { - if (jsEnvInstance != null) - { - return jsEnvInstance; - } - return Get(new Puerts.DefaultLoader()); - } - - public static JsEnv Get(Puerts.ILoader loader, int debugPort = -1) - { - if (jsEnvInstance != null) - { - return jsEnvInstance; - } - -#if !UNITY_EDITOR && UNITY_WEBGL - InitPuertsWebGL(); -#endif - jsEnvInstance = new JsEnv(loader, debugPort); - return jsEnvInstance; - } - -#if !UNITY_EDITOR && UNITY_WEBGL - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr InitPuertsWebGL(); -#endif - } - } -} \ No newline at end of file diff --git a/packages/webgl/upm/Runtime/WebGL.cs.meta b/packages/webgl/upm/Runtime/WebGL.cs.meta deleted file mode 100644 index a50c038..0000000 --- a/packages/webgl/upm/Runtime/WebGL.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 548962931a9de85429eb6f5f694e710e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/projects/8_UnitTest/Assets/Test/PuertsTest.cs b/projects/8_UnitTest/Assets/Test/PuertsTest.cs index 5e4f753..c703514 100644 --- a/projects/8_UnitTest/Assets/Test/PuertsTest.cs +++ b/projects/8_UnitTest/Assets/Test/PuertsTest.cs @@ -206,7 +206,7 @@ void Awake() void Start() { - var jsEnv = Puerts.WebGL.MainEnv.Get(new TSLoader()); + var jsEnv = new JsEnv(new TSLoader()); // var jsEnv = new Puerts.JsEnv(new DefaultLoader(), 8080); // jsEnv.WaitDebugger();