Skip to content

Commit 526beb9

Browse files
committed
WebGLInput
Plugin: unlock copy paste input fields
1 parent 92e25a0 commit 526beb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2248
-1
lines changed

Assets/Thirdweb/Examples/Scenes/Scene_Playground.unity

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ GameObject:
12441244
- component: {fileID: 187539454}
12451245
- component: {fileID: 187539453}
12461246
- component: {fileID: 187539452}
1247+
- component: {fileID: 187539455}
12471248
m_Layer: 5
12481249
m_Name: InputField_Email
12491250
m_TagString: Untagged
@@ -1407,6 +1408,19 @@ CanvasRenderer:
14071408
m_PrefabAsset: {fileID: 0}
14081409
m_GameObject: {fileID: 187539450}
14091410
m_CullTransparentMesh: 1
1411+
--- !u!114 &187539455
1412+
MonoBehaviour:
1413+
m_ObjectHideFlags: 0
1414+
m_CorrespondingSourceObject: {fileID: 0}
1415+
m_PrefabInstance: {fileID: 0}
1416+
m_PrefabAsset: {fileID: 0}
1417+
m_GameObject: {fileID: 187539450}
1418+
m_Enabled: 1
1419+
m_EditorHideFlags: 0
1420+
m_Script: {fileID: 11500000, guid: cc33a39070010f94fb1c2dd721c1286d, type: 3}
1421+
m_Name:
1422+
m_EditorClassIdentifier:
1423+
showHtmlElement: 0
14101424
--- !u!1 &198666611
14111425
GameObject:
14121426
m_ObjectHideFlags: 0
@@ -3784,7 +3798,10 @@ PrefabInstance:
37843798
m_RemovedComponents: []
37853799
m_RemovedGameObjects: []
37863800
m_AddedGameObjects: []
3787-
m_AddedComponents: []
3801+
m_AddedComponents:
3802+
- targetCorrespondingSourceObject: {fileID: 7581174088450466508, guid: f1f7a02a8c5efe54c95062bd90592227, type: 3}
3803+
insertIndex: -1
3804+
addedObject: {fileID: 686223896}
37883805
m_SourcePrefab: {fileID: 100100000, guid: f1f7a02a8c5efe54c95062bd90592227, type: 3}
37893806
--- !u!1 &581207178
37903807
GameObject:
@@ -4718,6 +4735,24 @@ MonoBehaviour:
47184735
m_Spacing: {x: 50, y: 50}
47194736
m_Constraint: 0
47204737
m_ConstraintCount: 2
4738+
--- !u!1 &686223891 stripped
4739+
GameObject:
4740+
m_CorrespondingSourceObject: {fileID: 7581174088450466508, guid: f1f7a02a8c5efe54c95062bd90592227, type: 3}
4741+
m_PrefabInstance: {fileID: 565346545}
4742+
m_PrefabAsset: {fileID: 0}
4743+
--- !u!114 &686223896
4744+
MonoBehaviour:
4745+
m_ObjectHideFlags: 0
4746+
m_CorrespondingSourceObject: {fileID: 0}
4747+
m_PrefabInstance: {fileID: 0}
4748+
m_PrefabAsset: {fileID: 0}
4749+
m_GameObject: {fileID: 686223891}
4750+
m_Enabled: 1
4751+
m_EditorHideFlags: 0
4752+
m_Script: {fileID: 11500000, guid: cc33a39070010f94fb1c2dd721c1286d, type: 3}
4753+
m_Name:
4754+
m_EditorClassIdentifier:
4755+
showHtmlElement: 0
47214756
--- !u!1 &700700974
47224757
GameObject:
47234758
m_ObjectHideFlags: 0
@@ -7353,6 +7388,7 @@ GameObject:
73537388
- component: {fileID: 1047630457}
73547389
- component: {fileID: 1047630456}
73557390
- component: {fileID: 1047630455}
7391+
- component: {fileID: 1047630458}
73567392
m_Layer: 5
73577393
m_Name: InputField_Phone
73587394
m_TagString: Untagged
@@ -7516,6 +7552,19 @@ CanvasRenderer:
75167552
m_PrefabAsset: {fileID: 0}
75177553
m_GameObject: {fileID: 1047630453}
75187554
m_CullTransparentMesh: 1
7555+
--- !u!114 &1047630458
7556+
MonoBehaviour:
7557+
m_ObjectHideFlags: 0
7558+
m_CorrespondingSourceObject: {fileID: 0}
7559+
m_PrefabInstance: {fileID: 0}
7560+
m_PrefabAsset: {fileID: 0}
7561+
m_GameObject: {fileID: 1047630453}
7562+
m_Enabled: 1
7563+
m_EditorHideFlags: 0
7564+
m_Script: {fileID: 11500000, guid: cc33a39070010f94fb1c2dd721c1286d, type: 3}
7565+
m_Name:
7566+
m_EditorClassIdentifier:
7567+
showHtmlElement: 0
75197568
--- !u!1 &1053544815
75207569
GameObject:
75217570
m_ObjectHideFlags: 0

Assets/Thirdweb/Plugins/WebGLInputCopy.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Plugins/WebGLInputCopy/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.IO;
2+
using UnityEditor;
3+
using UnityEditor.Callbacks;
4+
using UnityEngine;
5+
6+
namespace WebGLSupport
7+
{
8+
public class Postprocessor
9+
{
10+
const string MenuPath = "Assets/WebGLSupport/OverwriteFullscreenButton";
11+
12+
#if UNITY_2021_1_OR_NEWER
13+
static readonly bool supportedPostprocessor = true;
14+
static readonly string defaultFullscreenFunc = "unityInstance.SetFullscreen(1);";
15+
static readonly string fullscreenNode = "unity-container";
16+
#else
17+
static readonly bool supportedPostprocessor = false;
18+
static readonly string defaultFullscreenFunc = "";
19+
static readonly string fullscreenNode = "";
20+
#endif
21+
22+
private static bool IsEnable => PlayerPrefs.GetInt(MenuPath, 1) == 1;
23+
24+
[PostProcessBuild(1)]
25+
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
26+
{
27+
if (target != BuildTarget.WebGL) return;
28+
if (!supportedPostprocessor) return;
29+
if (!IsEnable) return;
30+
31+
var path = Path.Combine(pathToBuiltProject, "index.html");
32+
if (!File.Exists(path)) return;
33+
34+
var html = File.ReadAllText(path);
35+
36+
// check node is exist
37+
if (html.Contains(fullscreenNode))
38+
{
39+
html = html.Replace(defaultFullscreenFunc, $"document.makeFullscreen('{fullscreenNode}');");
40+
File.WriteAllText(path, html);
41+
}
42+
}
43+
44+
[MenuItem(MenuPath)]
45+
public static void OverwriteDefaultFullscreenButton()
46+
{
47+
var flag = !Menu.GetChecked(MenuPath);
48+
Menu.SetChecked(MenuPath, flag);
49+
PlayerPrefs.SetInt(MenuPath, flag ? 1 : 0);
50+
}
51+
52+
[MenuItem(MenuPath, validate = true)]
53+
private static bool OverwriteDefaultFullscreenButtonValidator()
54+
{
55+
Menu.SetChecked(MenuPath, IsEnable);
56+
return true;
57+
}
58+
}
59+
}

Assets/Thirdweb/Plugins/WebGLInputCopy/Editor/Postprocessor.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Plugins/WebGLInputCopy/WebGLInput.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Plugins/WebGLInputCopy/WebGLInput/Detail.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace WebGLSupport.Detail
6+
{
7+
public class RebuildChecker
8+
{
9+
IInputField input;
10+
11+
string beforeString;
12+
int beforeCaretPosition;
13+
int beforeSelectionFocusPosition;
14+
int beforeSelectionAnchorPosition;
15+
//Vector2 anchoredPosition;
16+
17+
public RebuildChecker(IInputField input)
18+
{
19+
this.input = input;
20+
}
21+
22+
public bool NeedRebuild(bool debug = false)
23+
{
24+
var res = false;
25+
26+
// any not same
27+
if (beforeString != input.text)
28+
{
29+
if(debug) Debug.Log(string.Format("beforeString : {0} != {1}", beforeString, input.text));
30+
beforeString = input.text;
31+
res = true;
32+
}
33+
34+
if (beforeCaretPosition != input.caretPosition)
35+
{
36+
if (debug) Debug.Log(string.Format("beforeCaretPosition : {0} != {1}", beforeCaretPosition, input.caretPosition));
37+
beforeCaretPosition = input.caretPosition;
38+
res = true;
39+
}
40+
41+
if (beforeSelectionFocusPosition != input.selectionFocusPosition)
42+
{
43+
if (debug) Debug.Log(string.Format("beforeSelectionFocusPosition : {0} != {1}", beforeSelectionFocusPosition, input.selectionFocusPosition));
44+
beforeSelectionFocusPosition = input.selectionFocusPosition;
45+
res = true;
46+
}
47+
48+
if (beforeSelectionAnchorPosition != input.selectionAnchorPosition)
49+
{
50+
if (debug) Debug.Log(string.Format("beforeSelectionAnchorPosition : {0} != {1}", beforeSelectionAnchorPosition, input.selectionAnchorPosition));
51+
beforeSelectionAnchorPosition = input.selectionAnchorPosition;
52+
res = true;
53+
}
54+
55+
//if (anchoredPosition != input.TextComponentRectTransform().anchoredPosition)
56+
//{
57+
// if (debug) Debug.Log(string.Format("anchoredPosition : {0} != {1}", anchoredPosition, input.TextComponentRectTransform().anchoredPosition));
58+
// anchoredPosition = input.TextComponentRectTransform().anchoredPosition;
59+
// res = true;
60+
//}
61+
return res;
62+
}
63+
}
64+
}

Assets/Thirdweb/Plugins/WebGLInputCopy/WebGLInput/Detail/RebuildChecker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using UnityEngine;
2+
3+
namespace WebGLSupport.Detail
4+
{
5+
public static class Support
6+
{
7+
/// <summary>
8+
/// 画面内の描画範囲を取得する
9+
/// </summary>
10+
/// <param name="uiElement"></param>
11+
/// <returns></returns>
12+
public static Rect GetScreenCoordinates(RectTransform uiElement)
13+
{
14+
var worldCorners = new Vector3[4];
15+
uiElement.GetWorldCorners(worldCorners);
16+
17+
// try to support RenderMode:WorldSpace
18+
var canvas = uiElement.GetComponentInParent<Canvas>();
19+
var useCamera = (canvas.renderMode != RenderMode.ScreenSpaceOverlay);
20+
if (canvas && useCamera)
21+
{
22+
var camera = canvas.worldCamera;
23+
if (!camera) camera = Camera.main;
24+
25+
for (var i = 0; i < worldCorners.Length; i++)
26+
{
27+
worldCorners[i] = camera.WorldToScreenPoint(worldCorners[i]);
28+
}
29+
}
30+
31+
var min = new Vector3(float.MaxValue, float.MaxValue);
32+
var max = new Vector3(float.MinValue, float.MinValue);
33+
for (var i = 0; i < worldCorners.Length; i++)
34+
{
35+
min.x = Mathf.Min(min.x, worldCorners[i].x);
36+
min.y = Mathf.Min(min.y, worldCorners[i].y);
37+
max.x = Mathf.Max(max.x, worldCorners[i].x);
38+
max.y = Mathf.Max(max.y, worldCorners[i].y);
39+
}
40+
41+
return new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
42+
}
43+
44+
}
45+
}

0 commit comments

Comments
 (0)