Skip to content

Commit

Permalink
#116 にて、モバイルデバイスでゲームライクの入力を切り替えられるようにインスペクターから指定可能にしました
Browse files Browse the repository at this point in the history
  • Loading branch information
kou-yeung committed Jul 26, 2023
1 parent e5b7c66 commit bef9962
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
4 changes: 3 additions & 1 deletion Assets/WebGLSupport/WebGLInput/WebGLInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ static WebGLInput()

[TooltipAttribute("show input element on canvas. this will make you select text by drag.")]
public bool showHtmlElement = false;
[TooltipAttribute("show input element above keyboard (mobile only)")]
public bool useGameLikeInput = true;

private IInputField Setup()
{
Expand Down Expand Up @@ -181,7 +183,7 @@ public void OnSelect()

// モバイルの場合、強制表示する
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);
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 && useGameLikeInput);

instances[id] = this;
WebGLInputPlugin.WebGLInputEnterSubmit(id, input.lineType != LineType.MultiLineNewline);
Expand Down
37 changes: 17 additions & 20 deletions Assets/WebGLSupport/WebGLInput/WebGLInput.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var WebGLInput = {
// 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) {
WebGLInputCreate: function (canvasId, x, y, width, height, fontsize, text, placeholder, isMultiLine, isPassword, isHidden, useGameLikeInput) {

var container = document.getElementById(UTF8ToString(canvasId));
var canvas = container.getElementsByTagName('canvas')[0];
Expand All @@ -30,26 +30,23 @@ var WebGLInput = {
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";
}

if(useGameLikeInput) {
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
Expand All @@ -66,7 +63,7 @@ var WebGLInput = {
input.type = 'password';
}

if(isMobile) {
if(useGameLikeInput) {
document.body.appendChild(input);
} else {
container.appendChild(input);
Expand Down

0 comments on commit bef9962

Please sign in to comment.