Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

モバイルデバイスでゲームライクの入力を切り替えられるようにインスペクターから指定可能にしました #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 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