Skip to content

Commit

Permalink
Merge pull request #378 from Amsterdam/feature/move-jslib-references
Browse files Browse the repository at this point in the history
removed static javascriptmethod caller class, and moved the script re…
  • Loading branch information
sambaas authored Dec 3, 2021
2 parents c6a4b65 + 83163ba commit d8f523d
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 139 deletions.
5 changes: 4 additions & 1 deletion 3DAmsterdam/Assets/Netherlands3D/Plugins/netDxf/DxfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class DxfFile
private DxfDocument dxfDocument;
private Layer dxfLayer;

[DllImport("__Internal")]
private static extern void DownloadFile(byte[] array, int byteLength, string fileName);

public void SetupDXF()
{
dxfDocument = new DxfDocument();
Expand Down Expand Up @@ -46,7 +49,7 @@ public void Save()
{
if (dxfDocument.Save(stream))
{
JavascriptMethodCaller.DownloadByteArrayAsFile(stream.ToArray(), stream.ToArray().Length, "testfile.dxf");
DownloadFile(stream.ToArray(), stream.ToArray().Length, "testfile.dxf");
}
else
{
Expand Down
12 changes: 11 additions & 1 deletion 3DAmsterdam/Assets/Netherlands3D/Scripts/Interface/OpenURL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
using Netherlands3D.JavascriptConnection;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Runtime.InteropServices;

namespace Netherlands3D.Interface
{
public class OpenURL : ChangePointerStyleHandler, IPointerDownHandler
{
[DllImport("__Internal")]
private static extern string OpenURLInNewWindow(string openUrl = "https://");

public void OnPointerDown(PointerEventData eventData)
{
/*
Expand All @@ -24,7 +28,13 @@ private void OpenURLByGameObjectName()
{
var httpPosition = gameObject.name.IndexOf("http");
var url = gameObject.name.Substring(httpPosition, gameObject.name.Length-httpPosition);
JavascriptMethodCaller.OpenURL(url);

#if !UNITY_EDITOR && UNITY_WEBGL
OpenURLInNewWindow(url);

#else
Application.OpenURL(url);
#endif

//Make sure to release everything manually (release event is blocked by our new browser window)
EventSystem.current.SetSelectedGameObject(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public enum SharingState
[DllImport("__Internal")]
private static extern void SyncFilesToIndexedDB();

[DllImport("__Internal")]
private static extern string SetUniqueShareURL(string token);

[SerializeField]
private RectTransform shareOptions;

Expand Down Expand Up @@ -197,8 +200,9 @@ private IEnumerator CompleteSharing()

sharedURL.ShowURL(sharedSceneURL);

JavascriptMethodCaller.SetUniqueShareURLToken(currentSceneServerReturn.sceneId);

#if !UNITY_EDITOR && UNITY_WEBGL
SetUniqueShareURL(currentSceneServerReturn.sceneId);
#endif
yield return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Netherlands3D.JavascriptConnection {
public class ChangePointerStyleHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[DllImport("__Internal")]
private static extern string SetCSSCursor(string cursorName = "pointer");

public enum Style{
AUTO,
POINTER,
Expand Down Expand Up @@ -53,7 +57,9 @@ public static void ChangeCursor(Style type)
cursorString = "progress";
break;
}
JavascriptMethodCaller.ChangeCursor(cursorString);
#if !UNITY_EDITOR && UNITY_WEBGL
SetCSSCursor(cursorString);
#endif
}

public void OnPointerEnter(PointerEventData eventData)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -9,6 +10,10 @@ namespace Netherlands3D.JavascriptConnection
{
public class DrawHTMLOverCanvas : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void DisplayDOMObjectWithID(string id = "htmlID", string display = "none", float x = 0, float y = 0, float width = 0, float height = 0, float offsetX = 0, float offsetY = 0);


[SerializeField]
private string htmlObjectID = "";

Expand All @@ -24,19 +29,31 @@ private void Awake()
image = GetComponent<Image>();
}


#if !UNITY_EDITOR && UNITY_WEBGL
private void Update()
{
if (alignEveryUpdate)
AlignHTMLOverlay();
}
private void OnEnable()
{
AlignHTMLOverlay();
}
private void OnDisable()
{
DisplayDOMObjectWithID(htmlObjectID,"none");
}
#endif

/// <summary>
/// Tell JavaScript to make a DOM object with htmlObjectID to align with the Image component
/// </summary>
private void AlignHTMLOverlay()
{
var screenSpaceRectangle = GetScreenSpaceRectangle();
JavascriptMethodCaller.DisplayWithID(htmlObjectID, true,

DisplayDOMObjectWithID(htmlObjectID, "inline",
screenSpaceRectangle.x / Screen.width,
screenSpaceRectangle.y / Screen.height,
screenSpaceRectangle.width / Screen.width,
Expand All @@ -56,17 +73,5 @@ private Rect GetScreenSpaceRectangle()
screenSpaceRectangle.y -= ((1.0f - image.rectTransform.pivot.y) * size.y);
return screenSpaceRectangle;
}

#if UNITY_WEBGL && !UNITY_EDITOR
private void OnEnable()
{
AlignHTMLOverlay();
}

private void OnDisable()
{
JavascriptMethodCaller.DisplayWithID(htmlObjectID,false);
}
#endif
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using UnityEngine;
Expand All @@ -17,6 +18,9 @@
/// </summary>
public class ColladaFile
{
[DllImport("__Internal")]
private static extern void DownloadFile(byte[] array, int byteLength, string fileName);

private XmlTextWriter writer;
private StringWriter stringWriter;
private List<Material> materials;
Expand Down Expand Up @@ -402,7 +406,7 @@ public void Save(string filename = "")
byte[] byteArray = Encoding.UTF8.GetBytes(stringWriter.ToString());
stringWriter = null;
writer = null;
JavascriptMethodCaller.DownloadByteArrayAsFile(byteArray, byteArray.Length, (filename!="") ? filename : "ColladaExport.dae");
DownloadFile(byteArray, byteArray.Length, (filename!="") ? filename : "ColladaExport.dae");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
using Netherlands3D.LayerSystem;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;

namespace Netherlands3D.Settings {
public class ApplicationSettings : MonoBehaviour
{
[DllImport("__Internal")]
private static extern bool IsMobile();

[SerializeField]
private bool forceMobileDevice = false;
private bool isMobileDevice = false;
Expand Down Expand Up @@ -58,7 +62,11 @@ public class ApplicationSettings : MonoBehaviour
private void Awake()
{
Instance = this;
IsMobileDevice = (forceMobileDevice || JavascriptMethodCaller.IsMobileBrowser());
IsMobileDevice = forceMobileDevice;

#if !UNITY_EDITOR && UNITY_WEBGL
IsMobileDevice = IsMobile();
#endif
}

void Start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
using UnityEngine;
using UnityEngine.UI;
using Netherlands3D.Cameras;
using System.Runtime.InteropServices;

namespace Netherlands3D.Interface
{
public class CanvasSettings : MonoBehaviour
{
[DllImport("__Internal")]
private static extern string ChangeInterfaceScale(float scale);


[SerializeField]
private CanvasScaler canvasScaler;
private string canvasScaleFactorKey = "canvasScaleFactor";
Expand All @@ -35,7 +40,9 @@ public float DetectPreferedCanvasScale()
{
canvasScale = Mathf.Clamp(Screen.width / referenceWidth, 1.0f, maxAutoWidth);
canvasScaler.scaleFactor = canvasScale;
JavascriptMethodCaller.SetInterfaceScale(canvasScale);
#if !UNITY_EDITOR && UNITY_WEBGL
ChangeInterfaceScale(canvasScale);
#endif
return canvasScale;
}

Expand All @@ -48,7 +55,9 @@ public void ChangeCanvasScale(float scaleFactor)
canvasScale = scaleFactor;
canvasScaler.scaleFactor = canvasScale;
PlayerPrefs.SetFloat(canvasScaleFactorKey, canvasScale);
JavascriptMethodCaller.SetInterfaceScale(canvasScale);
#if !UNITY_EDITOR && UNITY_WEBGL
ChangeInterfaceScale(canvasScale);
#endif
}
}
}

0 comments on commit d8f523d

Please sign in to comment.