Skip to content
Open
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
4 changes: 2 additions & 2 deletions Assets/Scripts/Core/Stage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static bool touchScreen
_touchScreen = value;
if (_touchScreen)
{
#if !(UNITY_WEBPLAYER || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR)
#if !(UNITY_WEBGL || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR)
keyboardInput = true;
#endif
_clickTestThreshold = 50;
Expand Down Expand Up @@ -154,7 +154,7 @@ public static bool keyboardInput
_keyboardInput = value;
if (value && _keyboard == null)
{
#if !(UNITY_WEBPLAYER || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR)
#if !(UNITY_WEBGL || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR)
_keyboard = new TouchScreenKeyboard();
#endif
}
Expand Down
32 changes: 12 additions & 20 deletions Assets/Scripts/Extensions/WebGLTextInput/WebGLTextInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,28 @@ static WebGLTextInput()

public static void Start(InputTextField target)
{
WebGLTextInputSetText(target.text,
var rect = target.TransformRect(new Rect(0, 0, target.width, target.height), null);
rect.min = StageCamera.main.WorldToScreenPoint(rect.min);
rect.max = StageCamera.main.WorldToScreenPoint(rect.max);
rect.y = Screen.height - rect.y - rect.height;

WebGLTextInputShow(rect.x, rect.y, target.width, target.height, rect.width / target.width, rect.height / target.height, target.text,
!target.textField.singleLine,
ColorUtility.ToHtmlStringRGBA(target.textFormat.color),
target.textFormat.size,
target.textFormat.font,
target.maxLength);

target.maxLength,
target.textFormat.align,
target.textFormat.lineSpacing);

WebGLInput.captureAllKeyboardInput = false;

SyncTransform(target);
}

public static void Stop()
{
WebGLTextInputHide();
}

public static void SyncTransform(InputTextField target)
{
Rect rect = target.TransformRect(new Rect(0, 0, target.width, target.height), null);
rect.min = StageCamera.main.WorldToScreenPoint(rect.min);
rect.max = StageCamera.main.WorldToScreenPoint(rect.max);
rect.y = Screen.height - rect.y - rect.height;

WebGLTextInputShow(rect.x, rect.y, target.width, target.height,
rect.width / target.width, rect.height / target.height);
}

[MonoPInvokeCallback(typeof(Action<string>))]
static void OnInput(string value)
{
Expand All @@ -65,10 +59,8 @@ static void OnBlur()
public static extern void WebGLTextInputInit(Action<string> onInputCallback, Action onBlurCallback);

[DllImport("__Internal")]
public static extern void WebGLTextInputSetText(string text, bool multiline, string color, int fontSize, string fontFace, int maxLength);

[DllImport("__Internal")]
public static extern void WebGLTextInputShow(float x, float y, float width, float height, float scaleX, float scaleY);
public static extern void WebGLTextInputShow(float x, float y, float width, float height, float scaleX, float scaleY, string text, bool multiline, string color, int fontSize,
string fontFace, int maxLength, AlignType align, int lineSpacing);

[DllImport("__Internal")]
public static extern void WebGLTextInputHide();
Expand Down
25 changes: 13 additions & 12 deletions Assets/Scripts/Extensions/WebGLTextInput/WebGLTextInput.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var WebGLTextInput = {
canvasEle = document.getElementById('unity-canvas');
},

WebGLTextInputSetText: function (text, multiline, color, fontSize, fontFace, maxLength) {
WebGLTextInputShow: function (x, y, width, height, scaleX, scaleY, text, multiline, color, fontSize, fontFace, maxLength, align, lineSpacing) {
if (containerEle == null) {
InitInput(inputEle = document.createElement("input"));
InitInput(textareaEle = document.createElement("textarea"));
Expand All @@ -23,6 +23,12 @@ var WebGLTextInput = {
canvasEle.parentElement.appendChild(containerEle);
}

containerEle.style.top = y / devicePixelRatio + "px";
containerEle.style.left = x / devicePixelRatio + "px";
containerEle.style.width = width / devicePixelRatio + "px";
containerEle.style.height = height / devicePixelRatio + "px";
containerEle.style.transform = "scale(" + scaleX + "," + scaleY + ")";

inputEle.parentElement && (containerEle.removeChild(inputEle));
textareaEle.parentElement && (containerEle.removeChild(textareaEle));

Expand All @@ -32,18 +38,13 @@ var WebGLTextInput = {

current.maxLength = maxLength <= 0 ? 1E5 : maxLength;
current.value = UTF8ToString(text);
current.style.color = color;
current.style.fontSize = fontSize + 'px';
current.style.fontFamily = fontFace;
current.focus();
},
current.style.color = '#' + UTF8ToString(color);
current.style.fontSize = fontSize / devicePixelRatio + 'px';
current.style.fontFamily = UTF8ToString(fontFace);
current.style.textAlign = ['left','center','right'][align];
current.style.lineHeight = `calc(1.25em + ${lineSpacing / devicePixelRatio}px)`;

WebGLTextInputShow: function (x, y, width, height, scaleX, scaleY) {
containerEle.style.top = y + "px";
containerEle.style.left = x + "px";
containerEle.style.width = width + "px";
containerEle.style.height = height + "px";
containerEle.style.transform = "scale(" + scaleX + "," + scaleY + ")";
current.focus();
},

WebGLTextInputHide: function () {
Expand Down