diff --git a/Assets/Sample.cs b/Assets/Sample.cs index f944081..a87c29b 100644 --- a/Assets/Sample.cs +++ b/Assets/Sample.cs @@ -1,10 +1,22 @@ using UnityEngine; using UnityEngine.UI; +using UnityEngine.UIElements; using WebGLSupport; public class Sample : MonoBehaviour { + [SerializeField] UIDocument uiDocument; + + public void Start() + { + uiDocument.rootVisualElement.Query().ForEach(v => + { + v.AddManipulator(new WebGLInputManipulator()); + }); ; + + } + public void OnValueChange(InputField o) { Debug.Log(string.Format("Sample:OnValueChange[{1}] ({0})", o.text, o.name)); diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 1329914..abb44fd 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1500,6 +1500,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e7b65eb28cdc6bb44bf45aeaba1146ca, type: 3} m_Name: m_EditorClassIdentifier: + uiDocument: {fileID: 1957403019} --- !u!4 &624294021 Transform: m_ObjectHideFlags: 0 @@ -1553,7 +1554,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: -30, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 34, y: 271} + m_AnchoredPosition: {x: 34, y: 247.17} m_SizeDelta: {x: 249.9, y: 40} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &702547720 @@ -4350,6 +4351,55 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1925124777} m_CullTransparentMesh: 0 +--- !u!1 &1957403018 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1957403020} + - component: {fileID: 1957403019} + m_Layer: 0 + m_Name: UIDocument + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1957403019 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1957403018} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0} + m_Name: + m_EditorClassIdentifier: + m_PanelSettings: {fileID: 11400000, guid: 46525ae93b53540469da5b6f766e93bc, type: 2} + m_ParentUI: {fileID: 0} + sourceAsset: {fileID: 9197481963319205126, guid: fd713ff242a072842a2cc05ba67b2e6c, + type: 3} + m_SortingOrder: 0 +--- !u!4 &1957403020 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1957403018} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1976214885 GameObject: m_ObjectHideFlags: 0 @@ -4592,7 +4642,7 @@ MonoBehaviour: m_FallbackScreenDPI: 96 m_DefaultSpriteDPI: 96 m_DynamicPixelsPerUnit: 1 - m_PresetInfoIsWorld: 0 + m_PresetInfoIsWorld: 1 --- !u!223 &2055003929 Canvas: m_ObjectHideFlags: 0 @@ -4633,7 +4683,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: -1833, y: 219} + m_AnchoredPosition: {x: -1833, y: 250} m_SizeDelta: {x: 960, y: 600} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &2084303610 @@ -4726,3 +4776,4 @@ SceneRoots: - {fileID: 624294021} - {fileID: 2055003930} - {fileID: 611509715} + - {fileID: 1957403020} diff --git a/Assets/UI Toolkit.meta b/Assets/UI Toolkit.meta new file mode 100644 index 0000000..fab765d --- /dev/null +++ b/Assets/UI Toolkit.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f5d160c3784b58c4097738937597e803 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI Toolkit/UnityThemes.meta b/Assets/UI Toolkit/UnityThemes.meta new file mode 100644 index 0000000..40cbacf --- /dev/null +++ b/Assets/UI Toolkit/UnityThemes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8718aee011a1523489d8cf6c14298fea +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss b/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss new file mode 100644 index 0000000..1056e07 --- /dev/null +++ b/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss @@ -0,0 +1 @@ +@import url("unity-theme://default"); \ No newline at end of file diff --git a/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss.meta b/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss.meta new file mode 100644 index 0000000..ab59f44 --- /dev/null +++ b/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d798a9891369254dae4ec1c2a28fcf6 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 diff --git a/Assets/UI Toolkit/sample.asset b/Assets/UI Toolkit/sample.asset new file mode 100644 index 0000000..7c1c220 --- /dev/null +++ b/Assets/UI Toolkit/sample.asset @@ -0,0 +1,44 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0} + m_Name: sample + m_EditorClassIdentifier: + themeUss: {fileID: -4733365628477956816, guid: 3d798a9891369254dae4ec1c2a28fcf6, + type: 3} + m_TargetTexture: {fileID: 0} + m_RenderMode: 0 + m_WorldSpaceLayer: 0 + m_ScaleMode: 1 + m_ReferenceSpritePixelsPerUnit: 100 + m_PixelsPerUnit: 100 + m_Scale: 1 + m_ReferenceDpi: 96 + m_FallbackDpi: 96 + m_ReferenceResolution: {x: 1200, y: 800} + m_ScreenMatchMode: 0 + m_Match: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 + m_BindingLogLevel: 0 + m_ClearDepthStencil: 1 + m_ClearColor: 0 + m_ColorClearValue: {r: 0, g: 0, b: 0, a: 0} + m_VertexBudget: 0 + m_DynamicAtlasSettings: + m_MinAtlasSize: 64 + m_MaxAtlasSize: 4096 + m_MaxSubTextureSize: 64 + m_ActiveFilters: -1 + m_AtlasBlitShader: {fileID: 9101, guid: 0000000000000000f000000000000000, type: 0} + m_RuntimeShader: {fileID: 9100, guid: 0000000000000000f000000000000000, type: 0} + m_RuntimeWorldShader: {fileID: 9102, guid: 0000000000000000f000000000000000, type: 0} + textSettings: {fileID: 0} diff --git a/Assets/UI Toolkit/sample.asset.meta b/Assets/UI Toolkit/sample.asset.meta new file mode 100644 index 0000000..b716495 --- /dev/null +++ b/Assets/UI Toolkit/sample.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 46525ae93b53540469da5b6f766e93bc +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI Toolkit/sample.uxml b/Assets/UI Toolkit/sample.uxml new file mode 100644 index 0000000..1c01812 --- /dev/null +++ b/Assets/UI Toolkit/sample.uxml @@ -0,0 +1,4 @@ + + + + diff --git a/Assets/UI Toolkit/sample.uxml.meta b/Assets/UI Toolkit/sample.uxml.meta new file mode 100644 index 0000000..245211d --- /dev/null +++ b/Assets/UI Toolkit/sample.uxml.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: fd713ff242a072842a2cc05ba67b2e6c +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0} diff --git a/Assets/UnityDefaultRuntimeTheme.tss b/Assets/UnityDefaultRuntimeTheme.tss new file mode 100644 index 0000000..79453c7 --- /dev/null +++ b/Assets/UnityDefaultRuntimeTheme.tss @@ -0,0 +1,2 @@ +@import url("unity-theme://default"); +VisualElement {} \ No newline at end of file diff --git a/Assets/UnityDefaultRuntimeTheme.tss.meta b/Assets/UnityDefaultRuntimeTheme.tss.meta new file mode 100644 index 0000000..4d94288 --- /dev/null +++ b/Assets/UnityDefaultRuntimeTheme.tss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3cea5759671c7f54f92621a39da946d6 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 diff --git a/Assets/WebGLSupport/WebGLInput/Detail/Support.cs b/Assets/WebGLSupport/WebGLInput/Detail/Support.cs new file mode 100644 index 0000000..163dae5 --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/Detail/Support.cs @@ -0,0 +1,45 @@ +using UnityEngine; + +namespace WebGLSupport.Detail +{ + public static class Support + { + /// + /// ‰æ–Ê“à‚Ì•`‰æ”͈͂ðŽæ“¾‚·‚é + /// + /// + /// + public static Rect GetScreenCoordinates(RectTransform uiElement) + { + var worldCorners = new Vector3[4]; + uiElement.GetWorldCorners(worldCorners); + + // try to support RenderMode:WorldSpace + var canvas = uiElement.GetComponentInParent(); + var useCamera = (canvas.renderMode != RenderMode.ScreenSpaceOverlay); + if (canvas && useCamera) + { + var camera = canvas.worldCamera; + if (!camera) camera = Camera.main; + + for (var i = 0; i < worldCorners.Length; i++) + { + worldCorners[i] = camera.WorldToScreenPoint(worldCorners[i]); + } + } + + var min = new Vector3(float.MaxValue, float.MaxValue); + var max = new Vector3(float.MinValue, float.MinValue); + for (var i = 0; i < worldCorners.Length; i++) + { + min.x = Mathf.Min(min.x, worldCorners[i].x); + min.y = Mathf.Min(min.y, worldCorners[i].y); + max.x = Mathf.Max(max.x, worldCorners[i].x); + max.y = Mathf.Max(max.y, worldCorners[i].y); + } + + return new Rect(min.x, min.y, max.x - min.x, max.y - min.y); + } + + } +} \ No newline at end of file diff --git a/Assets/WebGLSupport/WebGLInput/Detail/Support.cs.meta b/Assets/WebGLSupport/WebGLInput/Detail/Support.cs.meta new file mode 100644 index 0000000..29dbd0a --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/Detail/Support.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 12cf2979a42548647b4a59fab831a36b \ No newline at end of file diff --git a/Assets/WebGLSupport/WebGLInput/Mobile/WebGLInputMobile.cs b/Assets/WebGLSupport/WebGLInput/Mobile/WebGLInputMobile.cs index 69d64ac..0d1738e 100644 --- a/Assets/WebGLSupport/WebGLInput/Mobile/WebGLInputMobile.cs +++ b/Assets/WebGLSupport/WebGLInput/Mobile/WebGLInputMobile.cs @@ -1,87 +1,87 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.EventSystems; -using System.Runtime.InteropServices; // for DllImport -using AOT; -using System; - -namespace WebGLSupport -{ - class WebGLInputMobilePlugin - { -#if UNITY_WEBGL && !UNITY_EDITOR - [DllImport("__Internal")] - public static extern int WebGLInputMobileRegister(Action OnTouchEnd); - - [DllImport("__Internal")] - public static extern void WebGLInputMobileOnFocusOut(int id, Action OnFocusOut); -#else - /// - /// ID を割り振り - /// - /// - public static int WebGLInputMobileRegister(Action OnTouchEnd) { return 0; } - - public static void WebGLInputMobileOnFocusOut(int id, Action OnFocusOut) {} -#endif - } - - public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler - { - static Dictionary instances = new Dictionary(); - - int id = -1; - - private void Awake() - { -#if !(UNITY_WEBGL && !UNITY_EDITOR) - // WebGL 以外ã€æ›´æ–°ãƒ¡ã‚½ãƒƒãƒ‰ã¯å‹•ä½œã—ãªã„よã†ã«ã—ã¾ã™ - enabled = false; -#endif - } - - /// - /// 押ã•ã‚ŒãŸã‚‰ã€touchend イベントを登録ã™ã‚‹ - /// - /// - public void OnPointerDown(PointerEventData eventData) - { - if (id != -1) return; - id = WebGLInputMobilePlugin.WebGLInputMobileRegister(OnTouchEnd); - instances[id] = this; - } - - [MonoPInvokeCallback(typeof(Action))] - static void OnTouchEnd(int id) - { - var @this = instances[id]; - @this.GetComponent().OnSelect(); - @this.StartCoroutine(RegisterOnFocusOut(id)); - } - - static IEnumerator RegisterOnFocusOut(int id) - { - yield return null; // wait one frame. - WebGLInputMobilePlugin.WebGLInputMobileOnFocusOut(id, OnFocusOut); - } - - [MonoPInvokeCallback(typeof(Action))] - static void OnFocusOut(int id) - { - var @this = instances[id]; - @this.StartCoroutine(ExecFocusOut(id)); - } - +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; +using System.Runtime.InteropServices; // for DllImport +using AOT; +using System; + +namespace WebGLSupport +{ + class WebGLInputMobilePlugin + { +#if UNITY_WEBGL && !UNITY_EDITOR + [DllImport("__Internal")] + public static extern int WebGLInputMobileRegister(Action OnTouchEnd); + + [DllImport("__Internal")] + public static extern void WebGLInputMobileOnFocusOut(int id, Action OnFocusOut); +#else + /// + /// ID を割り振り + /// + /// + public static int WebGLInputMobileRegister(Action OnTouchEnd) { return 0; } + + public static void WebGLInputMobileOnFocusOut(int id, Action OnFocusOut) { } +#endif + } + + public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler + { + static Dictionary instances = new Dictionary(); + + int id = -1; + + private void Awake() + { +#if !(UNITY_WEBGL && !UNITY_EDITOR) + // WebGL 以外ã€æ›´æ–°ãƒ¡ã‚½ãƒƒãƒ‰ã¯å‹•ä½œã—ãªã„よã†ã«ã—ã¾ã™ + enabled = false; +#endif + } + + /// + /// 押ã•ã‚ŒãŸã‚‰ã€touchend イベントを登録ã™ã‚‹ + /// + /// + public void OnPointerDown(PointerEventData eventData) + { + if (id != -1) return; + id = WebGLInputMobilePlugin.WebGLInputMobileRegister(OnTouchEnd); + instances[id] = this; + } + + [MonoPInvokeCallback(typeof(Action))] + static void OnTouchEnd(int id) + { + var @this = instances[id]; + @this.GetComponent().OnSelect(); + @this.StartCoroutine(RegisterOnFocusOut(id)); + } + + static IEnumerator RegisterOnFocusOut(int id) + { + yield return null; // wait one frame. + WebGLInputMobilePlugin.WebGLInputMobileOnFocusOut(id, OnFocusOut); + } + + [MonoPInvokeCallback(typeof(Action))] + static void OnFocusOut(int id) + { + var @this = instances[id]; + @this.StartCoroutine(ExecFocusOut(id)); + } + static IEnumerator ExecFocusOut(int id) { - yield return null; // wait one frame. - var @this = instances[id]; - @this.GetComponent().DeactivateInputField(); - // release - @this.id = -1; - instances.Remove(id); - } - } -} - + yield return null; // wait one frame. + var @this = instances[id]; + @this.GetComponent().DeactivateInputField(); + // release + @this.id = -1; + instances.Remove(id); + } + } +} + diff --git a/Assets/WebGLSupport/WebGLInput/UIToolKit.meta b/Assets/WebGLSupport/WebGLInput/UIToolKit.meta new file mode 100644 index 0000000..9830ed8 --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/UIToolKit.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1b7dfc1c4073fb3428679dbe79406c59 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLInputManipulator.cs b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLInputManipulator.cs new file mode 100644 index 0000000..c16ce37 --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLInputManipulator.cs @@ -0,0 +1,59 @@ +using UnityEngine; +using UnityEngine.UIElements; + +namespace WebGLSupport +{ + public class WebGLInputManipulator : Manipulator + { + private GameObject go; + private bool showHtmlElement; + + public WebGLInputManipulator(bool showHtmlElement = false) + { + this.showHtmlElement = showHtmlElement; + } + protected override void RegisterCallbacksOnTarget() + { + var textInput = target.Q("unity-text-input"); + textInput.RegisterCallback(OnFocusInEvent); + textInput.RegisterCallback(OnFocusOutEvent); + } + protected override void UnregisterCallbacksFromTarget() + { + var textInput = target.Q("unity-text-input"); + textInput.UnregisterCallback(OnFocusInEvent); + textInput.UnregisterCallback(OnFocusOutEvent); + } + + private void OnFocusInEvent(FocusInEvent evt) + { + if (go != null) + { + GameObject.Destroy(go); + go = null; + } + + go = new GameObject("WebGLInputManipulator"); + + // add WebGLUIToolkitMonoBehaviour for hold TextField! + var uitoolkit = go.AddComponent(); + uitoolkit.TextField = target as TextField; + + // add WebGLInput to handle the event! + var webglInput = go.AddComponent(); + webglInput.showHtmlElement = showHtmlElement; + + // select it!! + webglInput.OnSelect(); + } + + private void OnFocusOutEvent(FocusOutEvent evt) + { + if (go != null) + { + GameObject.Destroy(go); + go = null; + } + } + } +} diff --git a/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLInputManipulator.cs.meta b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLInputManipulator.cs.meta new file mode 100644 index 0000000..7a9257d --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLInputManipulator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0235a2af8956c404c88f16d375fad74b \ No newline at end of file diff --git a/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLUIToolkitTextField.cs b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLUIToolkitTextField.cs new file mode 100644 index 0000000..df03f87 --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLUIToolkitTextField.cs @@ -0,0 +1,14 @@ +using UnityEngine; +using UnityEngine.UIElements; +using UnityEngine.Windows; + +namespace WebGLSupport +{ + /// + /// UIToolkit TextField + /// + public class WebGLUIToolkitTextField : MonoBehaviour + { + public TextField TextField { get; set; } + } +} diff --git a/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLUIToolkitTextField.cs.meta b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLUIToolkitTextField.cs.meta new file mode 100644 index 0000000..3bdfaa5 --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/UIToolKit/WebGLUIToolkitTextField.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 78226379c6d667741815566e6261c706 \ No newline at end of file diff --git a/Assets/WebGLSupport/WebGLInput/WebGLInput.cs b/Assets/WebGLSupport/WebGLInput/WebGLInput.cs index 5fdd7f5..71bccfd 100644 --- a/Assets/WebGLSupport/WebGLInput/WebGLInput.cs +++ b/Assets/WebGLSupport/WebGLInput/WebGLInput.cs @@ -125,9 +125,12 @@ static WebGLInput() private IInputField Setup() { if (GetComponent()) return new WrappedInputField(GetComponent()); + + if (GetComponent()) return new WrappedUIToolkit(GetComponent()); #if TMP_WEBGL_SUPPORT if (GetComponent()) return new WrappedTMPInputField(GetComponent()); #endif // TMP_WEBGL_SUPPORT + throw new Exception("Can not Setup WebGLInput!!"); } @@ -158,7 +161,7 @@ private void Awake() /// RectInt GetElemetRect() { - var rect = GetScreenCoordinates(input.RectTransform()); + var rect = input.GetScreenCoordinates(); // モãƒã‚¤ãƒ«ã®å ´åˆã€å¼·åˆ¶è¡¨ç¤ºã™ã‚‹ if (showHtmlElement || Application.isMobilePlatform) { @@ -207,6 +210,10 @@ public void OnSelect() { WebGLInputPlugin.WebGLInputSetSelectionRange(id, 0, input.text.Length); } + else + { + WebGLInputPlugin.WebGLInputSetSelectionRange(id, input.caretPosition, input.caretPosition); + } WebGLWindow.OnBlurEvent += OnWindowBlur; } @@ -216,43 +223,6 @@ void OnWindowBlur() blurBlock = true; } - /// - /// ç”»é¢å†…ã®æ画範囲をå–å¾—ã™ã‚‹ - /// - /// - /// - Rect GetScreenCoordinates(RectTransform uiElement) - { - var worldCorners = new Vector3[4]; - uiElement.GetWorldCorners(worldCorners); - - // try to support RenderMode:WorldSpace - var canvas = uiElement.GetComponentInParent(); - var useCamera = (canvas.renderMode != RenderMode.ScreenSpaceOverlay); - if (canvas && useCamera) - { - var camera = canvas.worldCamera; - if (!camera) camera = Camera.main; - - for (var i = 0; i < worldCorners.Length; i++) - { - worldCorners[i] = camera.WorldToScreenPoint(worldCorners[i]); - } - } - - var min = new Vector3(float.MaxValue, float.MaxValue); - var max = new Vector3(float.MinValue, float.MinValue); - for (var i = 0; i < worldCorners.Length; i++) - { - min.x = Mathf.Min(min.x, worldCorners[i].x); - min.y = Mathf.Min(min.y, worldCorners[i].y); - max.x = Mathf.Max(max.x, worldCorners[i].x); - max.y = Mathf.Max(max.y, worldCorners[i].y); - } - - return new Rect(min.x, min.y, max.x - min.x, max.y - min.y); - } - internal void DeactivateInputField() { if (!instances.ContainsKey(id)) return; @@ -412,8 +382,8 @@ private void OnDisable() } public int CompareTo(WebGLInput other) { - var a = GetScreenCoordinates(input.RectTransform()); - var b = GetScreenCoordinates(other.input.RectTransform()); + var a = input.GetScreenCoordinates(); + var b = other.input.GetScreenCoordinates(); var res = b.y.CompareTo(a.y); if (res == 0) res = a.x.CompareTo(b.x); return res; diff --git a/Assets/WebGLSupport/WebGLInput/Wrapper/IInputField.cs b/Assets/WebGLSupport/WebGLInput/Wrapper/IInputField.cs index b36bc04..bb05ab2 100644 --- a/Assets/WebGLSupport/WebGLInput/Wrapper/IInputField.cs +++ b/Assets/WebGLSupport/WebGLInput/Wrapper/IInputField.cs @@ -1,5 +1,4 @@ using UnityEngine; -using UnityEngine.UI; namespace WebGLSupport { @@ -38,7 +37,8 @@ public interface IInputField bool OnFocusSelectAll { get; } bool EnableMobileSupport { get; } - RectTransform RectTransform(); + Rect GetScreenCoordinates(); + void ActivateInputField(); void DeactivateInputField(); void Rebuild(); diff --git a/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedInputField.cs b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedInputField.cs index a8eff89..6b00fd1 100644 --- a/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedInputField.cs +++ b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedInputField.cs @@ -99,11 +99,6 @@ public WrappedInputField(InputField input) checker = new RebuildChecker(this); } - public RectTransform RectTransform() - { - return input.GetComponent(); - } - public void ActivateInputField() { input.ActivateInputField(); @@ -122,5 +117,10 @@ public void Rebuild() input.Rebuild(CanvasUpdate.LatePreRender); } } + + public Rect GetScreenCoordinates() + { + return Support.GetScreenCoordinates(input.GetComponent()); + } } } \ No newline at end of file diff --git a/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedTMPInputField.cs b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedTMPInputField.cs index 77e4789..144f03f 100644 --- a/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedTMPInputField.cs +++ b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedTMPInputField.cs @@ -132,15 +132,17 @@ public WrappedTMPInputField(TMP_InputField input) checker = new RebuildChecker(this); } - public RectTransform RectTransform() + public Rect GetScreenCoordinates() { // 表示範囲 // MEMO : // TMP ã§ã¯ textComponent を移動ã•ã›ã¦ã‚¯ãƒªãƒƒãƒ”ングã™ã‚‹ãŸã‚〠// 表示範囲外ã«ãªã‚‹å ´åˆãŒã‚ã‚‹ã®ã§ã€è‡ªåˆ†ã®ç¯„囲を返㙠- return input.GetComponent(); + return Support.GetScreenCoordinates(input.GetComponent()); } + + public void ActivateInputField() { input.ActivateInputField(); diff --git a/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedUIToolkit.cs b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedUIToolkit.cs new file mode 100644 index 0000000..741ece0 --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedUIToolkit.cs @@ -0,0 +1,148 @@ +using UnityEngine; +using UnityEngine.UIElements; + +namespace WebGLSupport +{ + /// + /// Wrapper for UnityEngine.UIElements.TextField + /// + class WrappedUIToolkit : IInputField + { + TextField input; + + public bool ReadOnly { get { return input.isReadOnly; } } + + public string text + { + get { return input.value; } + set { input.value = value; } + } + + public string placeholder + { + get + { + return input.textEdition.placeholder; + } + } + + public int fontSize + { + /// MEMO : how to get the fontsize? + get { return 20; } + } + + public ContentType contentType + { + get + { + if (input.isPasswordField) + { + return ContentType.Password; + } + + return input.keyboardType switch + { + TouchScreenKeyboardType.Default => ContentType.Standard, + TouchScreenKeyboardType.ASCIICapable => ContentType.Alphanumeric, + TouchScreenKeyboardType.NumbersAndPunctuation => ContentType.Standard, + TouchScreenKeyboardType.URL => ContentType.Standard, + TouchScreenKeyboardType.NumberPad => ContentType.IntegerNumber, + TouchScreenKeyboardType.PhonePad => ContentType.Standard, + TouchScreenKeyboardType.NamePhonePad => ContentType.Standard, + TouchScreenKeyboardType.EmailAddress => ContentType.EmailAddress, + //TouchScreenKeyboardType.NintendoNetworkAccount => throw new System.NotImplementedException(), + TouchScreenKeyboardType.Social => ContentType.Standard, + TouchScreenKeyboardType.Search => ContentType.Standard, + TouchScreenKeyboardType.DecimalPad => ContentType.DecimalNumber, + TouchScreenKeyboardType.OneTimeCode => ContentType.Standard, + _ => ContentType.Standard, + }; + } + } + + public LineType lineType + { + get + { + return input.multiline ? LineType.MultiLineNewline : LineType.SingleLine; + } + } + + public int characterLimit + { + get { return input.maxLength; } + } + + public int caretPosition + { + get { return input.cursorIndex; } + } + + public bool isFocused + { + get + { + return true; + } + } + + public int selectionFocusPosition + { + get { return input.cursorIndex; } + set { input.cursorIndex = value; } + } + + public int selectionAnchorPosition + { + get { return input.selectIndex; } + set { input.selectIndex = value; } + } + + public bool OnFocusSelectAll + { + get { return input.selectAllOnFocus || input.selectAllOnMouseUp; } + } + + public bool EnableMobileSupport + { + get + { + // 2022.1.0f1 + // https://unity.com/ja/releases/editor/whats-new/2022.1.0#release-notes + // WebGL: Added mobile keyboard support for WebGL to enter text in UI input fields. +#if UNITY_2022_1_OR_NEWER + // return false to use unity mobile keyboard support + return false; +#else + return true; +#endif + } + } + + public WrappedUIToolkit(WebGLUIToolkitTextField input) + { + this.input = input.TextField; + } + + public Rect GetScreenCoordinates() + { + var textInput = input.Q("unity-text-input"); + var rect = textInput.worldBound; + return new Rect(rect.x, Screen.height - (rect.y + rect.height), rect.width, rect.height); + } + + public void ActivateInputField() + { + } + + public void DeactivateInputField() + { + input.Blur(); + } + + public void Rebuild() + { + } + } +} \ No newline at end of file diff --git a/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedUIToolkit.cs.meta b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedUIToolkit.cs.meta new file mode 100644 index 0000000..c8c8a2b --- /dev/null +++ b/Assets/WebGLSupport/WebGLInput/Wrapper/WrappedUIToolkit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a84ff74590e7172468127b13d7c934da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/Packages/com.unity.services.core/Settings.json b/ProjectSettings/Packages/com.unity.services.core/Settings.json new file mode 100644 index 0000000..e69de29 diff --git a/ProjectSettings/SceneTemplateSettings.json b/ProjectSettings/SceneTemplateSettings.json new file mode 100644 index 0000000..5e97f83 --- /dev/null +++ b/ProjectSettings/SceneTemplateSettings.json @@ -0,0 +1,121 @@ +{ + "templatePinStates": [], + "dependencyTypeInfos": [ + { + "userAdded": false, + "type": "UnityEngine.AnimationClip", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEditor.Animations.AnimatorController", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.AnimatorOverrideController", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEditor.Audio.AudioMixerController", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.ComputeShader", + "defaultInstantiationMode": 1 + }, + { + "userAdded": false, + "type": "UnityEngine.Cubemap", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.GameObject", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEditor.LightingDataAsset", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.LightingSettings", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.Material", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEditor.MonoScript", + "defaultInstantiationMode": 1 + }, + { + "userAdded": false, + "type": "UnityEngine.PhysicMaterial", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.PhysicsMaterial2D", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.Rendering.PostProcessing.PostProcessProfile", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.Rendering.PostProcessing.PostProcessResources", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.Rendering.VolumeProfile", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEditor.SceneAsset", + "defaultInstantiationMode": 1 + }, + { + "userAdded": false, + "type": "UnityEngine.Shader", + "defaultInstantiationMode": 1 + }, + { + "userAdded": false, + "type": "UnityEngine.ShaderVariantCollection", + "defaultInstantiationMode": 1 + }, + { + "userAdded": false, + "type": "UnityEngine.Texture", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.Texture2D", + "defaultInstantiationMode": 0 + }, + { + "userAdded": false, + "type": "UnityEngine.Timeline.TimelineAsset", + "defaultInstantiationMode": 0 + } + ], + "defaultDependencyTypeInfo": { + "userAdded": false, + "type": "", + "defaultInstantiationMode": 1 + }, + "newSceneOverride": 0 +} \ No newline at end of file diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index 06db74a..699db18 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -9,6 +9,7 @@ UnityConnectSettings: m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events m_ConfigUrl: https://config.uca.cloud.unity3d.com + m_DashboardUrl: https://dashboard.unity3d.com m_TestInitMode: 0 CrashReportingSettings: m_EventUrl: https://perf-events.cloud.unity3d.com @@ -22,6 +23,7 @@ UnityConnectSettings: m_Enabled: 1 m_TestMode: 0 m_InitializeOnStartup: 1 + m_PackageRequiringCoreStatsPresent: 0 UnityAdsSettings: m_Enabled: 0 m_InitializeOnStartup: 1