Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #386

Merged
merged 4 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions 3DAmsterdam/Assets/Netherlands3D/Plugins/Jslib/FileUploads.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ mergeInto(LibraryManager.library, {
window.dbVersion = 21;

//Inject our required html input fields
window.InjectHiddenFileInput = function InjectHiddenFileInput(type, acceptedExtentions) {
window.InjectHiddenFileInput = function InjectHiddenFileInput(type, acceptedExtentions, multiFileSelect) {
var newInput = document.createElement("input");
newInput.id = type + '-input';
newInput.type = 'file';
newInput.accept = acceptedExtentions;
newInput.multiple = multiFileSelect;
newInput.onchange = function () {
window.ReadFiles(this.files);
};
newInput.style.cssText = 'display:none; cursor:pointer; opacity: 0; position: fixed; bottom: 0; left: 0; z-index: 2; width: 0px; height: 0px;';
document.body.appendChild(newInput);
};
window.InjectHiddenFileInput('obj', '.obj,.mtl');
window.InjectHiddenFileInput('csv', '.csv,.tsv');
window.InjectHiddenFileInput('fzp', '.fzp');
window.InjectHiddenFileInput('geojson', '.json,.geojson');
window.InjectHiddenFileInput('obj', '.obj,.mtl', true);
window.InjectHiddenFileInput('csv', '.csv,.tsv', false);
window.InjectHiddenFileInput('fzp', '.fzp', false);
window.InjectHiddenFileInput('geojson', '.json,.geojson', false);

//Support for dragging dropping files on browser window
document.addEventListener("dragover", function (event) {
Expand Down
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
Loading