You've already forked FateViewer
Added WebGL Mobile Input plugin
Added 3D camera controls
This commit is contained in:
8
Assets/Scripts/WebGLSupport/WebGLInput/Detail.meta
Normal file
8
Assets/Scripts/WebGLSupport/WebGLInput/Detail.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd840bb14379149498902237a63bb794
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WebGLSupport.Detail
|
||||
{
|
||||
public class RebuildChecker
|
||||
{
|
||||
IInputField input;
|
||||
|
||||
string beforeString;
|
||||
int beforeCaretPosition;
|
||||
int beforeSelectionFocusPosition;
|
||||
int beforeSelectionAnchorPosition;
|
||||
//Vector2 anchoredPosition;
|
||||
|
||||
public RebuildChecker(IInputField input)
|
||||
{
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public bool NeedRebuild(bool debug = false)
|
||||
{
|
||||
var res = false;
|
||||
|
||||
// any not same
|
||||
if (beforeString != input.text)
|
||||
{
|
||||
if(debug) Debug.Log(string.Format("beforeString : {0} != {1}", beforeString, input.text));
|
||||
beforeString = input.text;
|
||||
res = true;
|
||||
}
|
||||
|
||||
if (beforeCaretPosition != input.caretPosition)
|
||||
{
|
||||
if (debug) Debug.Log(string.Format("beforeCaretPosition : {0} != {1}", beforeCaretPosition, input.caretPosition));
|
||||
beforeCaretPosition = input.caretPosition;
|
||||
res = true;
|
||||
}
|
||||
|
||||
if (beforeSelectionFocusPosition != input.selectionFocusPosition)
|
||||
{
|
||||
if (debug) Debug.Log(string.Format("beforeSelectionFocusPosition : {0} != {1}", beforeSelectionFocusPosition, input.selectionFocusPosition));
|
||||
beforeSelectionFocusPosition = input.selectionFocusPosition;
|
||||
res = true;
|
||||
}
|
||||
|
||||
if (beforeSelectionAnchorPosition != input.selectionAnchorPosition)
|
||||
{
|
||||
if (debug) Debug.Log(string.Format("beforeSelectionAnchorPosition : {0} != {1}", beforeSelectionAnchorPosition, input.selectionAnchorPosition));
|
||||
beforeSelectionAnchorPosition = input.selectionAnchorPosition;
|
||||
res = true;
|
||||
}
|
||||
|
||||
//if (anchoredPosition != input.TextComponentRectTransform().anchoredPosition)
|
||||
//{
|
||||
// if (debug) Debug.Log(string.Format("anchoredPosition : {0} != {1}", anchoredPosition, input.TextComponentRectTransform().anchoredPosition));
|
||||
// anchoredPosition = input.TextComponentRectTransform().anchoredPosition;
|
||||
// res = true;
|
||||
//}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cb8b49a6bee2384b888ba951eb2bdbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/WebGLSupport/WebGLInput/Mobile.meta
Normal file
8
Assets/Scripts/WebGLSupport/WebGLInput/Mobile.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fcb4aaeec72ef54486eff0172891c0b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
460
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.cs
Normal file
460
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.cs
Normal file
@@ -0,0 +1,460 @@
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
#define TMP_WEBGL_SUPPORT
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using AOT;
|
||||
using System.Runtime.InteropServices; // for DllImport
|
||||
using System.Collections;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace WebGLSupport
|
||||
{
|
||||
internal class WebGLInputPlugin
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputInit();
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebGLInputCreate(string canvasId, int x, int y, int width, int height, int fontsize, string text, string placeholder, bool isMultiLine, bool isPassword, bool isHidden, bool isMobile);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputEnterSubmit(int id, bool flag);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputTab(int id, Action<int, int> cb);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputFocus(int id);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputOnFocus(int id, Action<int> cb);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputOnBlur(int id, Action<int> cb);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputOnValueChange(int id, Action<int, string> cb);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputOnEditEnd(int id, Action<int, string> cb);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebGLInputSelectionStart(int id);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebGLInputSelectionEnd(int id);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern int WebGLInputSelectionDirection(int id);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputSetSelectionRange(int id, int start, int end);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputMaxLength(int id, int maxlength);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputText(int id, string text);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern bool WebGLInputIsFocus(int id);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputDelete(int id);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputForceBlur(int id);
|
||||
|
||||
#if WEBGLINPUT_TAB
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLInputEnableTabText(int id, bool enable);
|
||||
#endif
|
||||
#else
|
||||
public static void WebGLInputInit() {}
|
||||
public static int WebGLInputCreate(string canvasId, int x, int y, int width, int height, int fontsize, string text, string placeholder, bool isMultiLine, bool isPassword, bool isHidden, bool isMobile) { return 0; }
|
||||
public static void WebGLInputEnterSubmit(int id, bool flag) { }
|
||||
public static void WebGLInputTab(int id, Action<int, int> cb) { }
|
||||
public static void WebGLInputFocus(int id) { }
|
||||
public static void WebGLInputOnFocus(int id, Action<int> cb) { }
|
||||
public static void WebGLInputOnBlur(int id, Action<int> cb) { }
|
||||
public static void WebGLInputOnValueChange(int id, Action<int, string> cb) { }
|
||||
public static void WebGLInputOnEditEnd(int id, Action<int, string> cb) { }
|
||||
public static int WebGLInputSelectionStart(int id) { return 0; }
|
||||
public static int WebGLInputSelectionEnd(int id) { return 0; }
|
||||
public static int WebGLInputSelectionDirection(int id) { return 0; }
|
||||
public static void WebGLInputSetSelectionRange(int id, int start, int end) { }
|
||||
public static void WebGLInputMaxLength(int id, int maxlength) { }
|
||||
public static void WebGLInputText(int id, string text) { }
|
||||
public static bool WebGLInputIsFocus(int id) { return false; }
|
||||
public static void WebGLInputDelete(int id) { }
|
||||
public static void WebGLInputForceBlur(int id) { }
|
||||
|
||||
#if WEBGLINPUT_TAB
|
||||
public static void WebGLInputEnableTabText(int id, bool enable) { }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public class WebGLInput : MonoBehaviour, IComparable<WebGLInput>
|
||||
{
|
||||
static Dictionary<int, WebGLInput> instances = new Dictionary<int, WebGLInput>();
|
||||
public static string CanvasId { get; set; }
|
||||
|
||||
#if WEBGLINPUT_TAB
|
||||
public bool enableTabText = false;
|
||||
#endif
|
||||
|
||||
static WebGLInput()
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
WebGLInput.CanvasId = "unity-container";
|
||||
#elif UNITY_2019_1_OR_NEWER
|
||||
WebGLInput.CanvasId = "unityContainer";
|
||||
#else
|
||||
WebGLInput.CanvasId = "gameContainer";
|
||||
#endif
|
||||
WebGLInputPlugin.WebGLInputInit();
|
||||
}
|
||||
public int Id { get { return id; } }
|
||||
internal int id = -1;
|
||||
public IInputField input;
|
||||
bool blurBlock = false;
|
||||
|
||||
[TooltipAttribute("show input element on canvas. this will make you select text by drag.")]
|
||||
public bool showHtmlElement = false;
|
||||
|
||||
private IInputField Setup()
|
||||
{
|
||||
if (GetComponent<InputField>()) return new WrappedInputField(GetComponent<InputField>());
|
||||
#if TMP_WEBGL_SUPPORT
|
||||
if (GetComponent<TMPro.TMP_InputField>()) return new WrappedTMPInputField(GetComponent<TMPro.TMP_InputField>());
|
||||
#endif // TMP_WEBGL_SUPPORT
|
||||
throw new Exception("Can not Setup WebGLInput!!");
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
input = Setup();
|
||||
#if !(UNITY_WEBGL && !UNITY_EDITOR)
|
||||
// WebGL 以外、更新メソッドは動作しないようにします
|
||||
enabled = false;
|
||||
#endif
|
||||
// モバイルの入力対応
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
gameObject.AddComponent<WebGLInputMobile>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the element rect of input
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
RectInt GetElemetRect()
|
||||
{
|
||||
var rect = GetScreenCoordinates(input.RectTransform());
|
||||
// モバイルの場合、強制表示する
|
||||
if (showHtmlElement || Application.isMobilePlatform)
|
||||
{
|
||||
var x = (int)(rect.x);
|
||||
var y = (int)(Screen.height - (rect.y + rect.height));
|
||||
return new RectInt(x, y, (int)rect.width, (int)rect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
var x = (int)(rect.x);
|
||||
var y = (int)(Screen.height - (rect.y));
|
||||
return new RectInt(x, y, (int)rect.width, (int)1);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 対象が選択されたとき
|
||||
/// </summary>
|
||||
/// <param name="eventData"></param>
|
||||
public void OnSelect()
|
||||
{
|
||||
if (id != -1) throw new Exception("OnSelect : id != -1");
|
||||
|
||||
var rect = GetElemetRect();
|
||||
bool isPassword = input.contentType == ContentType.Password;
|
||||
|
||||
var fontSize = Mathf.Max(14, input.fontSize); // limit font size : 14 !!
|
||||
|
||||
// モバイルの場合、強制表示する
|
||||
var isHidden = !(showHtmlElement || Application.isMobilePlatform);
|
||||
id = WebGLInputPlugin.WebGLInputCreate(WebGLInput.CanvasId, rect.x, rect.y, rect.width, rect.height, fontSize, input.text, input.placeholder, input.lineType != LineType.SingleLine, isPassword, isHidden, Application.isMobilePlatform);
|
||||
|
||||
instances[id] = this;
|
||||
WebGLInputPlugin.WebGLInputEnterSubmit(id, input.lineType != LineType.MultiLineNewline);
|
||||
WebGLInputPlugin.WebGLInputOnFocus(id, OnFocus);
|
||||
WebGLInputPlugin.WebGLInputOnBlur(id, OnBlur);
|
||||
WebGLInputPlugin.WebGLInputOnValueChange(id, OnValueChange);
|
||||
WebGLInputPlugin.WebGLInputOnEditEnd(id, OnEditEnd);
|
||||
WebGLInputPlugin.WebGLInputTab(id, OnTab);
|
||||
// default value : https://www.w3schools.com/tags/att_input_maxlength.asp
|
||||
WebGLInputPlugin.WebGLInputMaxLength(id, (input.characterLimit > 0) ? input.characterLimit : 524288);
|
||||
WebGLInputPlugin.WebGLInputFocus(id);
|
||||
#if WEBGLINPUT_TAB
|
||||
WebGLInputPlugin.WebGLInputEnableTabText(id, enableTabText);
|
||||
#endif
|
||||
if (input.OnFocusSelectAll)
|
||||
{
|
||||
WebGLInputPlugin.WebGLInputSetSelectionRange(id, 0, input.text.Length);
|
||||
}
|
||||
|
||||
WebGLWindow.OnBlurEvent += OnWindowBlur;
|
||||
}
|
||||
|
||||
void OnWindowBlur()
|
||||
{
|
||||
blurBlock = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 画面内の描画範囲を取得する
|
||||
/// </summary>
|
||||
/// <param name="uiElement"></param>
|
||||
/// <returns></returns>
|
||||
Rect GetScreenCoordinates(RectTransform uiElement)
|
||||
{
|
||||
var worldCorners = new Vector3[4];
|
||||
uiElement.GetWorldCorners(worldCorners);
|
||||
|
||||
// try to support RenderMode:WorldSpace
|
||||
var canvas = uiElement.GetComponentInParent<Canvas>();
|
||||
var useCamera = (canvas.renderMode != RenderMode.ScreenSpaceOverlay);
|
||||
if (canvas && useCamera)
|
||||
{
|
||||
var camera = canvas.worldCamera;
|
||||
if (!camera) camera = Camera.main;
|
||||
|
||||
for (var i = 0; i < worldCorners.Length; i++)
|
||||
{
|
||||
worldCorners[i] = camera.WorldToScreenPoint(worldCorners[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var min = new Vector3(float.MaxValue, float.MaxValue);
|
||||
var max = new Vector3(float.MinValue, float.MinValue);
|
||||
for (var i = 0; i < worldCorners.Length; i++)
|
||||
{
|
||||
min.x = Mathf.Min(min.x, worldCorners[i].x);
|
||||
min.y = Mathf.Min(min.y, worldCorners[i].y);
|
||||
max.x = Mathf.Max(max.x, worldCorners[i].x);
|
||||
max.y = Mathf.Max(max.y, worldCorners[i].y);
|
||||
}
|
||||
|
||||
return new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
|
||||
}
|
||||
|
||||
internal void DeactivateInputField()
|
||||
{
|
||||
if (!instances.ContainsKey(id)) return;
|
||||
|
||||
WebGLInputPlugin.WebGLInputDelete(id);
|
||||
input.DeactivateInputField();
|
||||
instances.Remove(id);
|
||||
id = -1; // reset id to -1;
|
||||
WebGLWindow.OnBlurEvent -= OnWindowBlur;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action<int>))]
|
||||
static void OnFocus(int id)
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
Input.ResetInputAxes(); // Inputの状態リセット
|
||||
UnityEngine.WebGLInput.captureAllKeyboardInput = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action<int>))]
|
||||
static void OnBlur(int id)
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
UnityEngine.WebGLInput.captureAllKeyboardInput = true;
|
||||
Input.ResetInputAxes(); // Inputの状態リセット
|
||||
#endif
|
||||
instances[id].StartCoroutine(Blur(id));
|
||||
}
|
||||
|
||||
static IEnumerator Blur(int id)
|
||||
{
|
||||
yield return null;
|
||||
if (!instances.ContainsKey(id)) yield break;
|
||||
|
||||
var block = instances[id].blurBlock; // get blur block state
|
||||
instances[id].blurBlock = false; // reset instalce block state
|
||||
if (block) yield break; // if block. break it!!
|
||||
instances[id].DeactivateInputField();
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action<int, string>))]
|
||||
static void OnValueChange(int id, string value)
|
||||
{
|
||||
if (!instances.ContainsKey(id)) return;
|
||||
|
||||
var instance = instances[id];
|
||||
if (!instance.input.ReadOnly)
|
||||
{
|
||||
instance.input.text = value;
|
||||
}
|
||||
|
||||
// InputField.ContentType.Name が Name の場合、先頭文字が強制的大文字になるため小文字にして比べる
|
||||
if (instance.input.contentType == ContentType.Name)
|
||||
{
|
||||
if (string.Compare(instance.input.text, value, true) == 0)
|
||||
{
|
||||
value = instance.input.text;
|
||||
}
|
||||
}
|
||||
|
||||
// InputField の ContentType による整形したテキストを HTML の input に再設定します
|
||||
if (value != instance.input.text)
|
||||
{
|
||||
var start = WebGLInputPlugin.WebGLInputSelectionStart(id);
|
||||
var end = WebGLInputPlugin.WebGLInputSelectionEnd(id);
|
||||
// take the offset.when char remove from input.
|
||||
var offset = instance.input.text.Length - value.Length;
|
||||
|
||||
WebGLInputPlugin.WebGLInputText(id, instance.input.text);
|
||||
// reset the input element selection range!!
|
||||
WebGLInputPlugin.WebGLInputSetSelectionRange(id, start + offset, end + offset);
|
||||
}
|
||||
}
|
||||
[MonoPInvokeCallback(typeof(Action<int, string>))]
|
||||
static void OnEditEnd(int id, string value)
|
||||
{
|
||||
if (!instances[id].input.ReadOnly)
|
||||
{
|
||||
instances[id].input.text = value;
|
||||
}
|
||||
}
|
||||
[MonoPInvokeCallback(typeof(Action<int, int>))]
|
||||
static void OnTab(int id, int value)
|
||||
{
|
||||
WebGLInputTabFocus.OnTab(instances[id], value);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (input == null || !input.isFocused)
|
||||
{
|
||||
CheckOutFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
// 未登録の場合、選択する
|
||||
if (!instances.ContainsKey(id))
|
||||
{
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
return;
|
||||
} else
|
||||
{
|
||||
OnSelect();
|
||||
}
|
||||
}
|
||||
else if (!WebGLInputPlugin.WebGLInputIsFocus(id))
|
||||
{
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
//input.DeactivateInputField();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// focus this id
|
||||
WebGLInputPlugin.WebGLInputFocus(id);
|
||||
}
|
||||
}
|
||||
|
||||
var start = WebGLInputPlugin.WebGLInputSelectionStart(id);
|
||||
var end = WebGLInputPlugin.WebGLInputSelectionEnd(id);
|
||||
// 選択方向によって設定します
|
||||
if (WebGLInputPlugin.WebGLInputSelectionDirection(id) == -1)
|
||||
{
|
||||
input.selectionFocusPosition = start;
|
||||
input.selectionAnchorPosition = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.selectionFocusPosition = end;
|
||||
input.selectionAnchorPosition = start;
|
||||
}
|
||||
|
||||
input.Rebuild();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (!instances.ContainsKey(id)) return;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
UnityEngine.WebGLInput.captureAllKeyboardInput = true;
|
||||
Input.ResetInputAxes(); // Inputの状態リセット
|
||||
#endif
|
||||
DeactivateInputField();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
WebGLInputTabFocus.Add(this);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
WebGLInputTabFocus.Remove(this);
|
||||
}
|
||||
public int CompareTo(WebGLInput other)
|
||||
{
|
||||
var a = GetScreenCoordinates(input.RectTransform());
|
||||
var b = GetScreenCoordinates(other.input.RectTransform());
|
||||
var res = b.y.CompareTo(a.y);
|
||||
if (res == 0) res = a.x.CompareTo(b.x);
|
||||
return res;
|
||||
}
|
||||
|
||||
public void CheckOutFocus()
|
||||
{
|
||||
if (!Application.isMobilePlatform) return;
|
||||
if (!instances.ContainsKey(id)) return;
|
||||
var current = EventSystem.current.currentSelectedGameObject;
|
||||
if (current != null) return;
|
||||
WebGLInputPlugin.WebGLInputForceBlur(id); // Input ではないし、キーボードを閉じる
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to manage tab focus
|
||||
/// base on scene position
|
||||
/// </summary>
|
||||
static class WebGLInputTabFocus
|
||||
{
|
||||
static List<WebGLInput> inputs = new List<WebGLInput>();
|
||||
|
||||
public static void Add(WebGLInput input)
|
||||
{
|
||||
inputs.Add(input);
|
||||
inputs.Sort();
|
||||
}
|
||||
|
||||
public static void Remove(WebGLInput input)
|
||||
{
|
||||
inputs.Remove(input);
|
||||
}
|
||||
|
||||
public static void OnTab(WebGLInput input, int value)
|
||||
{
|
||||
if (inputs.Count <= 1) return;
|
||||
var index = inputs.IndexOf(input);
|
||||
index += value;
|
||||
if (index < 0) index = inputs.Count - 1;
|
||||
else if (index >= inputs.Count) index = 0;
|
||||
inputs[index].input.ActivateInputField();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.cs.meta
Normal file
11
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc33a39070010f94fb1c2dd721c1286d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
184
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.jslib
Normal file
184
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.jslib
Normal file
@@ -0,0 +1,184 @@
|
||||
var WebGLInput = {
|
||||
$instances: [],
|
||||
WebGLInputInit : function() {
|
||||
// Remove the `Runtime` object from "v1.37.27: 12/24/2017"
|
||||
// if Runtime not defined. create and add functon!!
|
||||
if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall }
|
||||
},
|
||||
WebGLInputCreate: function (canvasId, x, y, width, height, fontsize, text, placeholder, isMultiLine, isPassword, isHidden, isMobile) {
|
||||
|
||||
var container = document.getElementById(UTF8ToString(canvasId));
|
||||
var canvas = document.getElementsByTagName('canvas')[0];
|
||||
|
||||
// if container is null and have canvas
|
||||
if (!container && canvas)
|
||||
{
|
||||
// set the container to canvas.parentNode
|
||||
container = canvas.parentNode;
|
||||
}
|
||||
|
||||
if(canvas)
|
||||
{
|
||||
var scaleX = container.offsetWidth / canvas.width;
|
||||
var scaleY = container.offsetHeight / canvas.height;
|
||||
|
||||
if(scaleX && scaleY)
|
||||
{
|
||||
x *= scaleX;
|
||||
width *= scaleX;
|
||||
y *= scaleY;
|
||||
height *= scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
var input = document.createElement(isMultiLine?"textarea":"input");
|
||||
input.style.position = "absolute";
|
||||
|
||||
if(isMobile) {
|
||||
input.style.bottom = 1 + "vh";
|
||||
input.style.left = 5 + "vw";
|
||||
input.style.width = 90 + "vw";
|
||||
input.style.height = (isMultiLine? 18 : 10) + "vh";
|
||||
input.style.fontSize = 5 + "vh";
|
||||
input.style.borderWidth = 5 + "px";
|
||||
input.style.borderColor = "#000000";
|
||||
} else {
|
||||
input.style.top = y + "px";
|
||||
input.style.left = x + "px";
|
||||
input.style.width = width + "px";
|
||||
input.style.height = height + "px";
|
||||
input.style.fontSize = fontsize + "px";
|
||||
}
|
||||
|
||||
input.style.outlineWidth = 1 + 'px';
|
||||
input.style.opacity = isHidden?0:1;
|
||||
input.style.resize = 'none'; // for textarea
|
||||
input.style.padding = '0px 1px';
|
||||
input.style.cursor = "default";
|
||||
input.style.touchAction = 'manipulation'; // for mobile
|
||||
|
||||
input.spellcheck = false;
|
||||
input.value = UTF8ToString(text);
|
||||
input.placeholder = UTF8ToString(placeholder);
|
||||
|
||||
if(isPassword){
|
||||
input.type = 'password';
|
||||
}
|
||||
|
||||
if(isMobile) {
|
||||
document.body.appendChild(input);
|
||||
} else {
|
||||
container.appendChild(input);
|
||||
}
|
||||
return instances.push(input) - 1;
|
||||
},
|
||||
WebGLInputEnterSubmit: function(id, falg){
|
||||
var input = instances[id];
|
||||
// for enter key
|
||||
input.addEventListener('keydown', function(e) {
|
||||
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
|
||||
if(falg)
|
||||
{
|
||||
e.preventDefault();
|
||||
input.blur();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
WebGLInputTab:function(id, cb) {
|
||||
var input = instances[id];
|
||||
// for tab key
|
||||
input.addEventListener('keydown', function (e) {
|
||||
if ((e.which && e.which === 9) || (e.keyCode && e.keyCode === 9)) {
|
||||
e.preventDefault();
|
||||
|
||||
// if enable tab text
|
||||
if(input.enableTabText){
|
||||
var val = input.value;
|
||||
var start = input.selectionStart;
|
||||
var end = input.selectionEnd;
|
||||
input.value = val.substr(0, start) + '\t' + val.substr(end, val.length);
|
||||
input.setSelectionRange(start + 1, start + 1);
|
||||
input.oninput(); // call oninput to exe ValueChange function!!
|
||||
} else {
|
||||
Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
WebGLInputFocus: function(id){
|
||||
var input = instances[id];
|
||||
input.focus();
|
||||
},
|
||||
WebGLInputOnFocus: function (id, cb) {
|
||||
var input = instances[id];
|
||||
input.onfocus = function () {
|
||||
Runtime.dynCall("vi", cb, [id]);
|
||||
};
|
||||
},
|
||||
WebGLInputOnBlur: function (id, cb) {
|
||||
var input = instances[id];
|
||||
input.onblur = function () {
|
||||
Runtime.dynCall("vi", cb, [id]);
|
||||
};
|
||||
},
|
||||
WebGLInputIsFocus: function (id) {
|
||||
return instances[id] === document.activeElement;
|
||||
},
|
||||
WebGLInputOnValueChange:function(id, cb){
|
||||
var input = instances[id];
|
||||
input.oninput = function () {
|
||||
var intArray = intArrayFromString(input.value);
|
||||
var value = (allocate.length <= 2) ? allocate(intArray, ALLOC_NORMAL):allocate(intArray, 'i8', ALLOC_NORMAL);
|
||||
Runtime.dynCall("vii", cb, [id,value]);
|
||||
};
|
||||
},
|
||||
WebGLInputOnEditEnd:function(id, cb){
|
||||
var input = instances[id];
|
||||
input.onchange = function () {
|
||||
var intArray = intArrayFromString(input.value);
|
||||
var value = (allocate.length <= 2) ? allocate(intArray, ALLOC_NORMAL):allocate(intArray, 'i8', ALLOC_NORMAL);
|
||||
Runtime.dynCall("vii", cb, [id,value]);
|
||||
};
|
||||
},
|
||||
WebGLInputSelectionStart:function(id){
|
||||
var input = instances[id];
|
||||
return input.selectionStart;
|
||||
},
|
||||
WebGLInputSelectionEnd:function(id){
|
||||
var input = instances[id];
|
||||
return input.selectionEnd;
|
||||
},
|
||||
WebGLInputSelectionDirection:function(id){
|
||||
var input = instances[id];
|
||||
return (input.selectionDirection == "backward")?-1:1;
|
||||
},
|
||||
WebGLInputSetSelectionRange:function(id, start, end){
|
||||
var input = instances[id];
|
||||
input.setSelectionRange(start, end);
|
||||
},
|
||||
WebGLInputMaxLength:function(id, maxlength){
|
||||
var input = instances[id];
|
||||
input.maxLength = maxlength;
|
||||
},
|
||||
WebGLInputText:function(id, text){
|
||||
var input = instances[id];
|
||||
input.value = UTF8ToString(text);
|
||||
},
|
||||
WebGLInputDelete:function(id){
|
||||
var input = instances[id];
|
||||
input.parentNode.removeChild(input);
|
||||
instances[id] = null;
|
||||
},
|
||||
WebGLInputEnableTabText:function(id, enable) {
|
||||
var input = instances[id];
|
||||
input.enableTabText = enable;
|
||||
},
|
||||
WebGLInputForceBlur:function(id) {
|
||||
var input = instances[id];
|
||||
input.blur();
|
||||
},
|
||||
}
|
||||
|
||||
autoAddDeps(WebGLInput, '$instances');
|
||||
mergeInto(LibraryManager.library, WebGLInput);
|
||||
34
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.jslib.meta
Normal file
34
Assets/Scripts/WebGLSupport/WebGLInput/WebGLInput.jslib.meta
Normal file
@@ -0,0 +1,34 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7df541bf7b903fb45b24fab892876393
|
||||
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:
|
||||
8
Assets/Scripts/WebGLSupport/WebGLInput/Wrapper.meta
Normal file
8
Assets/Scripts/WebGLSupport/WebGLInput/Wrapper.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfaa1fbdc36ec0d45b321b02a2089b55
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace WebGLSupport
|
||||
{
|
||||
public enum ContentType
|
||||
{
|
||||
Standard = 0,
|
||||
Autocorrected = 1,
|
||||
IntegerNumber = 2,
|
||||
DecimalNumber = 3,
|
||||
Alphanumeric = 4,
|
||||
Name = 5,
|
||||
EmailAddress = 6,
|
||||
Password = 7,
|
||||
Pin = 8,
|
||||
Custom = 9
|
||||
}
|
||||
public enum LineType
|
||||
{
|
||||
SingleLine = 0,
|
||||
MultiLineSubmit = 1,
|
||||
MultiLineNewline = 2
|
||||
}
|
||||
public interface IInputField
|
||||
{
|
||||
ContentType contentType { get; }
|
||||
LineType lineType { get; }
|
||||
int fontSize { get; }
|
||||
string text { get; set; }
|
||||
string placeholder { get; }
|
||||
int characterLimit { get; }
|
||||
int caretPosition { get; }
|
||||
bool isFocused { get; }
|
||||
int selectionFocusPosition { get; set; }
|
||||
int selectionAnchorPosition { get; set; }
|
||||
bool ReadOnly { get; }
|
||||
bool OnFocusSelectAll { get; }
|
||||
|
||||
RectTransform RectTransform();
|
||||
void ActivateInputField();
|
||||
void DeactivateInputField();
|
||||
void Rebuild();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8be52c4f26f76e04fbae3cb86e539bdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,110 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using WebGLSupport.Detail;
|
||||
|
||||
namespace WebGLSupport
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper for UnityEngine.UI.InputField
|
||||
/// </summary>
|
||||
class WrappedInputField : IInputField
|
||||
{
|
||||
InputField input;
|
||||
RebuildChecker checker;
|
||||
|
||||
public bool ReadOnly { get { return input.readOnly; } }
|
||||
|
||||
public string text
|
||||
{
|
||||
get { return input.text; }
|
||||
set { input.text = value; }
|
||||
}
|
||||
|
||||
public string placeholder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!input.placeholder) return "";
|
||||
var text = input.placeholder.GetComponent<Text>();
|
||||
return text ? text.text : "";
|
||||
}
|
||||
}
|
||||
|
||||
public int fontSize
|
||||
{
|
||||
get { return input.textComponent.fontSize; }
|
||||
}
|
||||
|
||||
public ContentType contentType
|
||||
{
|
||||
get { return (ContentType)input.contentType; }
|
||||
}
|
||||
|
||||
public LineType lineType
|
||||
{
|
||||
get { return (LineType)input.lineType; }
|
||||
}
|
||||
|
||||
public int characterLimit
|
||||
{
|
||||
get { return input.characterLimit; }
|
||||
}
|
||||
|
||||
public int caretPosition
|
||||
{
|
||||
get { return input.caretPosition; }
|
||||
}
|
||||
|
||||
public bool isFocused
|
||||
{
|
||||
get { return input.isFocused; }
|
||||
}
|
||||
|
||||
public int selectionFocusPosition
|
||||
{
|
||||
get { return input.selectionFocusPosition; }
|
||||
set { input.selectionFocusPosition = value; }
|
||||
}
|
||||
|
||||
public int selectionAnchorPosition
|
||||
{
|
||||
get { return input.selectionAnchorPosition; }
|
||||
set { input.selectionAnchorPosition = value; }
|
||||
}
|
||||
|
||||
public bool OnFocusSelectAll
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public WrappedInputField(InputField input)
|
||||
{
|
||||
this.input = input;
|
||||
checker = new RebuildChecker(this);
|
||||
}
|
||||
|
||||
public RectTransform RectTransform()
|
||||
{
|
||||
return input.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void ActivateInputField()
|
||||
{
|
||||
input.ActivateInputField();
|
||||
}
|
||||
|
||||
public void DeactivateInputField()
|
||||
{
|
||||
input.DeactivateInputField();
|
||||
}
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
if (checker.NeedRebuild())
|
||||
{
|
||||
input.textComponent.SetAllDirty();
|
||||
input.Rebuild(CanvasUpdate.LatePreRender);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c8464791034e144ca224c37c1816e37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,167 @@
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
#define TMP_WEBGL_SUPPORT
|
||||
#endif
|
||||
|
||||
#if TMP_WEBGL_SUPPORT
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using WebGLSupport.Detail;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace WebGLSupport
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper for TMPro.TMP_InputField
|
||||
/// </summary>
|
||||
class WrappedTMPInputField : IInputField
|
||||
{
|
||||
TMP_InputField input;
|
||||
RebuildChecker checker;
|
||||
Coroutine delayedGraphicRebuild;
|
||||
|
||||
public bool ReadOnly { get { return input.readOnly; } }
|
||||
|
||||
public string text
|
||||
{
|
||||
get { return input.text; }
|
||||
set { input.text = value; }
|
||||
}
|
||||
public string placeholder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!input.placeholder) return "";
|
||||
var text = input.placeholder.GetComponent<TMP_Text>();
|
||||
return text ? text.text : "";
|
||||
}
|
||||
}
|
||||
|
||||
public int fontSize
|
||||
{
|
||||
get { return (int)input.textComponent.fontSize; }
|
||||
}
|
||||
|
||||
public ContentType contentType
|
||||
{
|
||||
get { return (ContentType)input.contentType; }
|
||||
}
|
||||
|
||||
public LineType lineType
|
||||
{
|
||||
get { return (LineType)input.lineType; }
|
||||
}
|
||||
|
||||
public int characterLimit
|
||||
{
|
||||
get { return input.characterLimit; }
|
||||
}
|
||||
|
||||
public int caretPosition
|
||||
{
|
||||
get { return input.caretPosition; }
|
||||
}
|
||||
|
||||
public bool isFocused
|
||||
{
|
||||
get { return input.isFocused; }
|
||||
}
|
||||
|
||||
public int selectionFocusPosition
|
||||
{
|
||||
get { return input.selectionStringFocusPosition; }
|
||||
set { input.selectionStringFocusPosition = value; }
|
||||
}
|
||||
|
||||
public int selectionAnchorPosition
|
||||
{
|
||||
get { return input.selectionStringAnchorPosition; }
|
||||
set { input.selectionStringAnchorPosition = value; }
|
||||
}
|
||||
|
||||
public bool OnFocusSelectAll
|
||||
{
|
||||
get { return input.onFocusSelectAll; }
|
||||
}
|
||||
|
||||
public WrappedTMPInputField(TMP_InputField input)
|
||||
{
|
||||
this.input = input;
|
||||
checker = new RebuildChecker(this);
|
||||
}
|
||||
|
||||
public RectTransform RectTransform()
|
||||
{
|
||||
// 表示範囲
|
||||
// MEMO :
|
||||
// TMP では textComponent を移動させてクリッピングするため、
|
||||
// 表示範囲外になる場合があるので、自分の範囲を返す
|
||||
return input.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void ActivateInputField()
|
||||
{
|
||||
input.ActivateInputField();
|
||||
}
|
||||
|
||||
public void DeactivateInputField()
|
||||
{
|
||||
input.DeactivateInputField();
|
||||
}
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if (checker.NeedRebuild())
|
||||
{
|
||||
input.textComponent.SetVerticesDirty();
|
||||
input.textComponent.SetLayoutDirty();
|
||||
input.Rebuild(CanvasUpdate.LatePreRender);
|
||||
}
|
||||
#else
|
||||
if (input.textComponent.enabled && checker.NeedRebuild())
|
||||
{
|
||||
//================================
|
||||
// fix bug for tmp
|
||||
// TMPの不具合で、正しく座標を設定されてなかったため、試しに対応する
|
||||
var rt = input.textComponent.GetComponent<RectTransform>();
|
||||
var size = input.textComponent.GetPreferredValues();
|
||||
if (size.x < rt.rect.xMax)
|
||||
{
|
||||
// textComponent の座標を更新
|
||||
var pos = rt.anchoredPosition;
|
||||
pos.x = 0;
|
||||
rt.anchoredPosition = pos;
|
||||
|
||||
// caret の座標更新
|
||||
var caret = input.GetComponentInChildren<TMP_SelectionCaret>();
|
||||
var caretRect = caret.GetComponent<RectTransform>();
|
||||
caretRect.anchoredPosition = rt.anchoredPosition;
|
||||
}
|
||||
//==============================
|
||||
|
||||
// HACK : 1フレーム無効にする
|
||||
// MEMO : 他にいい方法Rebuildがあれば対応する
|
||||
// LayoutRebuilder.ForceRebuildLayoutImmediate(); で試してダメでした
|
||||
input.textComponent.enabled = rectOverlaps(input.textComponent.rectTransform, input.textViewport);
|
||||
input.textComponent.SetAllDirty();
|
||||
input.Rebuild(CanvasUpdate.LatePreRender);
|
||||
//Debug.Log(input.textComponent.enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
input.textComponent.enabled = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool rectOverlaps(RectTransform rectTrans1, RectTransform rectTrans2)
|
||||
{
|
||||
Rect rect1 = new Rect(rectTrans1.localPosition.x, rectTrans1.localPosition.y, rectTrans1.rect.width, rectTrans1.rect.height);
|
||||
Rect rect2 = new Rect(rectTrans2.localPosition.x, rectTrans2.localPosition.y, rectTrans2.rect.width, rectTrans2.rect.height);
|
||||
|
||||
return rect1.Overlaps(rect2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TMP_WEBGL_SUPPORT
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1629c3a135d89a45aca880fa8052f5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user