You've already forked FateViewer
Added WebGL Mobile Input plugin
Added 3D camera controls
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using System.Runtime.InteropServices; // for DllImport
|
||||
using AOT;
|
||||
using System;
|
||||
|
||||
namespace WebGLSupport
|
||||
{
|
||||
class WebGLInputMobilePlugin
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebGLInputMobileRegister(Action<int> OnTouchEnd);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputMobileOnFocusOut(int id, Action<int> OnFocusOut);
|
||||
#else
|
||||
/// <summary>
|
||||
/// ID を割り振り
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int WebGLInputMobileRegister(Action<int> OnTouchEnd) { return 0; }
|
||||
|
||||
public static void WebGLInputMobileOnFocusOut(int id, Action<int> OnFocusOut) {}
|
||||
#endif
|
||||
}
|
||||
|
||||
public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
static Dictionary<int, WebGLInputMobile> instances = new Dictionary<int, WebGLInputMobile>();
|
||||
|
||||
int id = -1;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if !(UNITY_WEBGL && !UNITY_EDITOR)
|
||||
// WebGL 以外、更新メソッドは動作しないようにします
|
||||
enabled = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 押されたら、touchend イベントを登録する
|
||||
/// </summary>
|
||||
/// <param name="eventData"></param>
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (id != -1) return;
|
||||
id = WebGLInputMobilePlugin.WebGLInputMobileRegister(OnTouchEnd);
|
||||
instances[id] = this;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action<int>))]
|
||||
static void OnTouchEnd(int id)
|
||||
{
|
||||
var @this = instances[id];
|
||||
@this.GetComponent<WebGLInput>().OnSelect();
|
||||
@this.StartCoroutine(RegisterOnFocusOut(id));
|
||||
}
|
||||
|
||||
static IEnumerator RegisterOnFocusOut(int id)
|
||||
{
|
||||
yield return null; // wait one frame.
|
||||
WebGLInputMobilePlugin.WebGLInputMobileOnFocusOut(id, OnFocusOut);
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action<int>))]
|
||||
static void OnFocusOut(int id)
|
||||
{
|
||||
var @this = instances[id];
|
||||
@this.StartCoroutine(ExecFocusOut(id));
|
||||
}
|
||||
|
||||
static IEnumerator ExecFocusOut(int id)
|
||||
{
|
||||
yield return null; // wait one frame.
|
||||
var @this = instances[id];
|
||||
@this.GetComponent<WebGLInput>().DeactivateInputField();
|
||||
// release
|
||||
@this.id = -1;
|
||||
instances.Remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56393f797a0f7e94e95547f5052052a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
var WebGLInputMobile = {
|
||||
$instances: [],
|
||||
|
||||
WebGLInputMobileRegister: function (touchend) {
|
||||
var id = instances.push(null) - 1;
|
||||
|
||||
document.body.addEventListener("touchend", function () {
|
||||
document.body.removeEventListener("touchend", arguments.callee);
|
||||
Runtime.dynCall("vi", touchend, [id]);
|
||||
});
|
||||
|
||||
return id;
|
||||
},
|
||||
WebGLInputMobileOnFocusOut: function (id, focusout) {
|
||||
document.body.addEventListener("focusout", function () {
|
||||
document.body.removeEventListener("focusout", arguments.callee);
|
||||
Runtime.dynCall("vi", focusout, [id]);
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
autoAddDeps(WebGLInputMobile, '$instances');
|
||||
mergeInto(LibraryManager.library, WebGLInputMobile);
|
||||
@@ -0,0 +1,34 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4df3633103619754fb77d82a1d683868
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Facebook: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user