From 352a3d86ba089bf2065049e98aaa277d4a7c6934 Mon Sep 17 00:00:00 2001 From: Bjoern Esswein <692-bessw@users.noreply.gl.kwarc.info> Date: Wed, 17 Jul 2024 18:10:55 +0200 Subject: [PATCH] Add scrollView.html to StreamingAssets and include the WebView package via git url. --- .../Prefabs/UI/Ingame/HidingCanvas.prefab | 11 +- Assets/Scripts/UI/InGame/WebViewController.cs | 3 + .../StreamToDataPath/scrollView.html | 312 ++++++++++++++++++ .../StreamToDataPath/scrollView.html.meta | 7 + Packages/manifest.json | 2 +- Packages/packages-lock.json | 7 +- 6 files changed, 330 insertions(+), 12 deletions(-) create mode 100644 Assets/StreamingAssets/StreamToDataPath/scrollView.html create mode 100644 Assets/StreamingAssets/StreamToDataPath/scrollView.html.meta diff --git a/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab b/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab index c78ab03b..ec56a279 100644 --- a/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab +++ b/Assets/Resources/Prefabs/UI/Ingame/HidingCanvas.prefab @@ -35,7 +35,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 1080} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 1, y: 1} --- !u!114 &6592514254180342026 @@ -2908,7 +2908,7 @@ MonoBehaviour: m_FallbackScreenDPI: 96 m_DefaultSpriteDPI: 96 m_DynamicPixelsPerUnit: 1 - m_PresetInfoIsWorld: 1 + m_PresetInfoIsWorld: 0 --- !u!114 &8004702057932254676 MonoBehaviour: m_ObjectHideFlags: 0 @@ -3426,11 +3426,6 @@ PrefabInstance: propertyPath: targetUrl value: http://127.0.0.1:5500/scrollView.html objectReference: {fileID: 0} - - target: {fileID: 2459857651630437765, guid: 1e9d514b702f5784791a4df8d22e1866, - type: 3} - propertyPath: headlessBrowser - value: 0 - objectReference: {fileID: 0} - target: {fileID: 2974656142881083530, guid: 1e9d514b702f5784791a4df8d22e1866, type: 3} propertyPath: m_Pivot.x @@ -3716,7 +3711,7 @@ PrefabInstance: - target: {fileID: 4838871000058222821, guid: 49deb83b881477047bfac0ee629a7ae9, type: 3} propertyPath: m_AnchoredPosition.y - value: -59.99997 + value: -0.000045776367 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 49deb83b881477047bfac0ee629a7ae9, type: 3} diff --git a/Assets/Scripts/UI/InGame/WebViewController.cs b/Assets/Scripts/UI/InGame/WebViewController.cs index f312d971..a80a93bd 100644 --- a/Assets/Scripts/UI/InGame/WebViewController.cs +++ b/Assets/Scripts/UI/InGame/WebViewController.cs @@ -7,6 +7,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using UnityEngine; using UnityEngine.Events; @@ -26,8 +27,10 @@ public class WebViewController : MonoBehaviour private void Awake() { + Debug.LogWarning("awake Webview Controller"); webViewComponent = GetComponent<WebViewComponent>(); WebViewComponent.serializerSettings.Converters.Add(new FactObjectUIConverter()); + webViewComponent.targetUrl = Path.Join(Application.dataPath, "scrollView.html"); // TODO: handle webViewComponent.onDomDocumentUpdated diff --git a/Assets/StreamingAssets/StreamToDataPath/scrollView.html b/Assets/StreamingAssets/StreamToDataPath/scrollView.html new file mode 100644 index 00000000..af335f71 --- /dev/null +++ b/Assets/StreamingAssets/StreamToDataPath/scrollView.html @@ -0,0 +1,312 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>Scroll View</title> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <style> + body { + font-size: 100px; + } + [dropzone] { + background-color: yellow; + } + #rectangle { + width: 10px; + height: 10px; + position: absolute; + background-color: red; + } + .demoFact { + font-size: initial; + margin-top: 20px; + } + </style> +</head> +<body> + <math> + <mi>E</mi> + <mo>=</mo> + <mfenced> + <mtable> + <mtr> + <mtd> + <mi dropzone="copy" data-allowed-types="PointFact,AngleFact" data-slot-id="http://mathhub.info/FrameIT/frameworld?Example?A">a</mi> + </mtd> + <mtd> + <mi dropzone="copy" data-slot-id="http://mathhub.info/FrameIT/frameworld?Example?B">b</mi> + </mtd> + <mtd> + <mn>0</mn> + </mtd> + </mtr> + <mtr> + <mtd> + <mn>0</mn> + </mtd> + <mtd> + <mn>1</mn> + </mtd> + <mtd> + <mn>0</mn> + </mtd> + </mtr> + <mtr> + <mtd> + <mn>0</mn> + </mtd> + <mtd> + <mn>0</mn> + </mtd> + <mtd> + <mn>1</mn> + </mtd> + </mtr> + </mtable> + </math> + <div class="demoFact">{ + "s_type": "PointFact", + "label": "A", + "_CustomLabel": null, + "hasCustomLabel": false, + "labelId": 0, + "point": {"x": -1.66086578, "y": -0.00494432449, "z": -2.17682648}, + "normal": {"x": 0.1, "y": 1.2, "z": 0.3} + }</div> + <div class="demoFact">{ + "pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact252", + "pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact254", + "pid3": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256", + "s_type": "AngleFact", + "label": "∠BDF", + "_CustomLabel": null, + "is_right_angle": false, + "hasCustomLabel": false, + "labelId": 0 + }</div> + <div class="demoFact">{ + "s_type": "LineFact", + "pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact255", + "pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256", + "dir": {"x": 0.1, "y": 1.2, "z": 0.3}, + "label": "[EF]", + "_CustomLabel": null, + "hasCustomLabel": false, + "labelId": 0 + }</div> + <div class="demoFact">{ + "s_type": "RayFact", + "pid1": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256", + "pid2": "http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact252", + "dir": {"x": 0.1, "y": 1.2, "z": 0.3}, + "label": "FB", + "_CustomLabel": null, + "hasCustomLabel": false, + "labelId": 0 + }</div> +</body> + <script> + /** + * @typedef Point + * @type {object} + * @property {number} x + * @property {number} y + * @property {number} z + */ + + /** + * @property {Point} point + * @property {Point} normal + * @property {string} s_type + * @property {string} label + * @property {string|null} _CustomLabel + * @property {boolean} hasCustomLabel + * @property {number} labelId + */ + + class Fact { + /** @property {string} id Fact id */ + id = "" + /** @property {string} s_type Fact type */ + s_type = "" + /** @property {string} label used in unity */ + label = "" + /** @property {string | null} _CustomLabel Custom label */ + _CustomLabel = null + /** @property {boolean} hasCustomLabel */ + hasCustomLabel = false + /** @property {number} labelId */ + labelId = 0 + } + + class Point { + /** @property {number} x */ + x = 0 + /** @property {number} y */ + y = 0 + /** @property {number} z */ + z = 0 + } + /** + s_type: PointFact, + label: A, + _CustomLabel: null, + hasCustomLabel: false, + labelId: 0, + point: {x: -1.66086578, y: -0.00494432449, z: -2.17682648}, + normal: {x: 0, y: 1, z: 0} + */ + class PointFact extends Fact { + s_type = "PointFact"; + /** @property {Point} point */ + point = new Point() + /** @property {Point} normal */ + normal = new Point() + } + + /** + * pid1: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact252, + pid2: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact254, + pid3: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256, + s_type: AngleFact, + label: ∠BDF, + _CustomLabel: null, + is_right_angle: false, + hasCustomLabel: false, + labelId: 0 + */ + class AngleFact extends Fact { + s_type = "AngleFact"; + pid1 = ""; + pid2 = ""; + pid3 = ""; + is_right_angle = false; + } + + /** + * s_type: LineFact, + pid1: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact255, + pid2: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256, + dir: [object Object], + label: [EF], + _CustomLabel: null, + hasCustomLabel: false, + labelId: 0 + */ + class LineFact extends Fact { + s_type = "LineFact"; + pid1 = ""; + pid2 = ""; + dir = new Point(); + } + + /** + * s_type: RayFact, + pid1: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256, + pid2: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact252, + dir: [object Object], + label: FB, + _CustomLabel: null, + hasCustomLabel: false, + labelId: 0 + */ + class RayFact extends Fact { + s_type = "RayFact"; + pid1 = ""; + pid2 = ""; + dir = new Point(); + } + + + + /** @param {DragEvent} event */ + function dropHandler(event) { + event.preventDefault() + + const data = event.dataTransfer.getData("application/json") + //const data = event.dataTransfer.getData("text/plain") + console.log(`Droped data: '${event.dataTransfer.types}'`, event.dataTransfer.types) + + /** @type {Fact} */ + const fact = JSON.parse(data) + console.warn(`Droped Fact '${fact.label}':`, fact) + + /** @type {HTMLElement} */ + const element = event.target + + if (element.hasAttribute("data-allowed-types")) { + //const allowedTypesStr = element.dataset["allowed-types"] + const allowedTypesStr = element.getAttribute("data-allowed-types") + const allowedTypes = allowedTypesStr.split(",") + + if (!allowedTypes.includes(fact.s_type)) { + console.warn(`The drop target data-type '${fact.s_type}' is not a member of the allowed types '${allowedTypesStr}'`) + return + } + } + + element.innerHTML = fact.label + element.fact = fact + element.dataset.factId = fact.id + } + + + /* + * debug functions + */ + + /** @param {DragEvent} event */ + function printHandler(event, evName) { + let items = event.dataTransfer.types + console.log(`${evName} getData: '${event.dataTransfer.getData("application/json")}'`, items) + console.log(`${evName} getData: '${event.dataTransfer.types}'`, items) + } + /** @param {DragEvent} event */ + function printPreventDefaultHandler(event, evName) { + printHandler(event, evName) + event.preventDefault() + } + + /* + * register the drag event listeners + */ + //document.addEventListener("dragstart", ev => printHandler(ev, "DragStartEvent")) + //document.addEventListener("dragenter", ev => printHandler(ev, "DragEnterEvent")) + //document.addEventListener("drag", ev => printHandler(ev, "DragEvent")) + document.addEventListener("dragover", ev => ev.preventDefault()) + //document.addEventListener("dragover", ev => printPreventDefaultHandler(ev, "DragOverEvent")) + //document.addEventListener("dragleave", ev => printHandler(ev, "DragLeaveEvent")) + //document.addEventListener("dragend", ev => printHandler(ev, "DragEndEvent")) + + // select all dropzones and add drop event listeners + let dropZones = document.querySelectorAll('[dropzone="copy"]') + dropZones.forEach( dropZone => dropZone.addEventListener("drop", ev => dropHandler(ev, "DropEvent")) ) + </script> + + <!--<script src="visualiseCursor.mjs" defer type="module"></script>--> + <!--<script> + /* mouse and pointer event handling */ + const rectangle = document.createElement("div"); + rectangle.id = "rectangle"; + + console.log("appendChild to", document.body) + document.body.appendChild(rectangle); + + function followCursor(event) { + const cursorX = event.clientX; + const cursorY = event.clientY +5; + //console.log(`MouseEvent X: ${cursorX}, Y: ${cursorY}, Event type: ${event.type}`, event); + rectangle.style.left = `${cursorX}px`; + rectangle.style.top = `${cursorY}px`; + } + + document.addEventListener("mousemove", followCursor); + document.addEventListener("pointermove", followCursor); + + document.addEventListener("mouseover", followCursor); + document.addEventListener("pointerover", followCursor); + + document.addEventListener("mouseout", followCursor); + document.addEventListener("pointerout", followCursor); + </script>--> +</html> diff --git a/Assets/StreamingAssets/StreamToDataPath/scrollView.html.meta b/Assets/StreamingAssets/StreamToDataPath/scrollView.html.meta new file mode 100644 index 00000000..02831017 --- /dev/null +++ b/Assets/StreamingAssets/StreamToDataPath/scrollView.html.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1d3e2132e24f19e41970733210b72ac6 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/manifest.json b/Packages/manifest.json index 1232e6b5..c1cd150e 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,6 +1,6 @@ { "dependencies": { - "bessw.unity.webview": "file:D:/b-ess/SW/src/UNI/BrowserView", + "bessw.unity.webview": "https://gl.kwarc.info/FrameIT/unity-webview.git", "com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity", "com.unity.2d.sprite": "1.0.0", "com.unity.2d.tilemap": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index cb181e02..1addb615 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,10 +1,11 @@ { "dependencies": { "bessw.unity.webview": { - "version": "file:D:/b-ess/SW/src/UNI/BrowserView", + "version": "https://gl.kwarc.info/FrameIT/unity-webview.git", "depth": 0, - "source": "local", - "dependencies": {} + "source": "git", + "dependencies": {}, + "hash": "7d6373282087b3434bc6e25a82ee2074b673ac5b" }, "com.github-glitchenzo.nugetforunity": { "version": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity", -- GitLab