You've already forked FateViewer
Added WebGL Mobile Input plugin
Added 3D camera controls
This commit is contained in:
@@ -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