From 4e4d7354862d76668ce0bbc479c4ce03ee86703b Mon Sep 17 00:00:00 2001 From: Benjamin Lipman Date: Tue, 3 May 2022 12:58:40 -0400 Subject: [PATCH] Compatability Update for Unity 2020+ #19 --- Assets/Plugins/WebGL/ARWTAccess.jslib | 18 ++ Assets/Scripts/Common/CameraController.cs | 28 ++- .../Common/PostBuild/PostBuildActions.cs | 11 +- Assets/Scripts/WebAR/DetectionManager.cs | 9 +- Assets/WebGLTemplates/WebAR/index.html | 202 ++++++++++++++++-- 5 files changed, 241 insertions(+), 27 deletions(-) create mode 100644 Assets/Plugins/WebGL/ARWTAccess.jslib diff --git a/Assets/Plugins/WebGL/ARWTAccess.jslib b/Assets/Plugins/WebGL/ARWTAccess.jslib new file mode 100644 index 0000000..c039d19 --- /dev/null +++ b/Assets/Plugins/WebGL/ARWTAccess.jslib @@ -0,0 +1,18 @@ +mergeInto(LibraryManager.library, { + CameraReady : function() { + cameraReady(); + }, + DetectionManagerReady : function () { + detectionManagerReady(); + }, + + ObjectAvailable : function() { + objectAvailable(); + }, + + GetCamName : function(camName) { + var name = Pointer_stringify(camName) + getCamName(name); + }, + +}); \ No newline at end of file diff --git a/Assets/Scripts/Common/CameraController.cs b/Assets/Scripts/Common/CameraController.cs index cc919bc..d3a3af1 100644 --- a/Assets/Scripts/Common/CameraController.cs +++ b/Assets/Scripts/Common/CameraController.cs @@ -1,15 +1,25 @@ using UnityEngine; +using System.Runtime.InteropServices; namespace ARWT.Core{ public class CameraController : MonoBehaviour{ - + + [DllImport("__Internal")] + private static extern void ObjectAvailable(); + + [DllImport("__Internal")] + private static extern void CameraReady(); + + Matrix4x4 defProj; Camera cam; - [System.Obsolete] void Start() { cam = GetComponent(); - Application.ExternalCall("cameraReady"); + + if(!Application.isEditor){ + CameraReady(); + } defProj = cam.projectionMatrix; } @@ -93,5 +103,17 @@ public void setEuler(string val){ transform.eulerAngles = new Vector3(x, y, z); } + public void ObjectCheck(string objectName){ + + if(GameObject.Find(objectName) != null){ + if(!Application.isEditor){ + ObjectAvailable(); + } + }else{ + Debug.LogError("There is no gameobject with the name " + objectName + " available for use!"); + } + } + + } } diff --git a/Assets/Scripts/Common/PostBuild/PostBuildActions.cs b/Assets/Scripts/Common/PostBuild/PostBuildActions.cs index 02da261..62cd0e0 100644 --- a/Assets/Scripts/Common/PostBuild/PostBuildActions.cs +++ b/Assets/Scripts/Common/PostBuild/PostBuildActions.cs @@ -17,27 +17,18 @@ public class PostBuildActions{ static string markersPath = "data/markers"; static string markersImagesPath = "data/markersImages"; static string index = "index.html"; - static string appJS = "js/app.js"; - - [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget target, string targetPath){ if(PlayerSettings.WebGL.template.Contains("WebAR")){ - var path = Path.Combine(targetPath, "Build/UnityLoader.js"); + var path = Path.Combine(targetPath, "Build/" + getName(targetPath) + ".loader.js"); var text = File.ReadAllText(path); text = text.Replace("UnityLoader.SystemInfo.mobile", "false"); File.WriteAllText(path, text); - string buildJsonPath = "Build/" + getName(targetPath) + ".json"; - path = Path.Combine(targetPath, "Build/" + getName(targetPath) + ".json"); - replaceInFile(path, "backgroundColor", ""); - generateHTML(targetPath); copyImages(targetPath); - string unityDeclaration = $"const unityInstance = UnityLoader.instantiate(\"unityContainer\", \"{buildJsonPath}\");"; - replaceInFile(Path.Combine(targetPath, appJS), buildPlaceholder, unityDeclaration); } } diff --git a/Assets/Scripts/WebAR/DetectionManager.cs b/Assets/Scripts/WebAR/DetectionManager.cs index 96af069..f7a718d 100644 --- a/Assets/Scripts/WebAR/DetectionManager.cs +++ b/Assets/Scripts/WebAR/DetectionManager.cs @@ -1,5 +1,6 @@ using ARWT.Core; using UnityEngine; +using System.Runtime.InteropServices; namespace ARWT.Marker{ public class MarkerInfo{ @@ -20,14 +21,18 @@ public MarkerInfo(string name, bool isVisible, Vector3 position, Quaternion rota public class DetectionManager : Singleton{ + [DllImport("__Internal")] + private static extern void DetectionManagerReady(); + public delegate void MarkerDetection(MarkerInfo m); public static event MarkerDetection onMarkerDetected; public static event MarkerDetection onMarkerVisible; public static event MarkerDetection onMarkerLost; - [System.Obsolete] void Start() { - Application.ExternalCall("detectionManagerReady"); + if(!Application.isEditor){ + DetectionManagerReady(); + } } public void markerInfos(string infos){ diff --git a/Assets/WebGLTemplates/WebAR/index.html b/Assets/WebGLTemplates/WebAR/index.html index 8286be0..2c46310 100644 --- a/Assets/WebGLTemplates/WebAR/index.html +++ b/Assets/WebGLTemplates/WebAR/index.html @@ -4,23 +4,201 @@ - Unity WebGL Player | WebGL Test AR + Unity WebGL Player | {{{ PRODUCT_NAME }}} + - - - + + + + +
+
Loading, please wait...
+
+ +
+ +
+ + - - -
- - - + - --MARKERS-- - + --MARKERS-- + \ No newline at end of file