From 26a4351d142e8988150edf51fc294fc9cc6d7467 Mon Sep 17 00:00:00 2001 From: IwamotoKakeru Date: Sun, 12 May 2024 22:47:58 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB?= =?UTF-8?q?=E3=81=AB=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E7=A8=AE=E5=88=A5?= =?UTF-8?q?=E3=82=92=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Plugins/CheckTouchDevice.jslib | 29 ++++++--- Assets/Scenes/Title.unity | 93 +++++++++++++++++++++++++++ Assets/Scripts/DeviceTypeText.cs | 25 +++++++ Assets/Scripts/DeviceTypeText.cs.meta | 11 ++++ Assets/Scripts/Utility.cs | 6 ++ 5 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/DeviceTypeText.cs create mode 100644 Assets/Scripts/DeviceTypeText.cs.meta diff --git a/Assets/Plugins/CheckTouchDevice.jslib b/Assets/Plugins/CheckTouchDevice.jslib index 6e74475..1ec7192 100644 --- a/Assets/Plugins/CheckTouchDevice.jslib +++ b/Assets/Plugins/CheckTouchDevice.jslib @@ -1,5 +1,3 @@ -const plugin = {}; - /** * タッチできるデバイスかどうかを確認します * @returns {Boolean} 真ならタッチ可能 @@ -8,32 +6,43 @@ function CheckTouchDevice() { var touchEvent = window.ontouchstart; let touchPoints = navigator.maxTouchPoints; - var userAgent = window.navigator.userAgent.toLocaleLowerCase(); - // 端末がタッチに対応している if (touchEvent !== undefined && touchPoints > 0) { return true; } + return false; +} + +/** + * デバイス種別を確認します + * @returns {String} デバイス種別 + */ +function GetDeviceType() { + var userAgent = window.navigator.userAgent.toLocaleLowerCase(); + // iPhone if (userAgent.indexOf("iphone") != -1) { - return true; + return "iPhone"; } // iPad if (userAgent.indexOf("ipad") != -1) { - return true; + return "iPad"; } // android端末 if (userAgent.indexOf("android") != -1) { - return true; + return "Android"; } - return false; + // PC + return "PC"; } -plugin[CheckTouchDevice.name] = CheckTouchDevice; +const plugins = {}; +plugins[CheckTouchDevice.name] = CheckTouchDevice; +plugins[GetDeviceType.name] = GetDeviceType; // Unity側へ反映 -mergeInto(LibraryManager.library, plugin); +mergeInto(LibraryManager.library, plugins); diff --git a/Assets/Scenes/Title.unity b/Assets/Scenes/Title.unity index c347ece..3941716 100644 --- a/Assets/Scenes/Title.unity +++ b/Assets/Scenes/Title.unity @@ -219,6 +219,7 @@ RectTransform: m_Children: - {fileID: 286217875} - {fileID: 990477082} + - {fileID: 1867554084} - {fileID: 374588864} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -3178,6 +3179,98 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 570d41d9663e09845bf92f2ff40a7500, type: 3} +--- !u!1 &1867554083 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1867554084} + - component: {fileID: 1867554087} + - component: {fileID: 1867554086} + - component: {fileID: 1867554085} + m_Layer: 5 + m_Name: DeviceType + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1867554084 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1867554083} + 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: 232318860} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 310, y: 220} + m_SizeDelta: {x: 300, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1867554085 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1867554083} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 12800000, guid: bacbf1a90b8e34ca9a11eef6ce0e0aec, type: 3} + m_FontSize: 30 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 0 + m_MaxSize: 100 + m_Alignment: 2 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: "\u30C7\u30D0\u30A4\u30B9: PC" +--- !u!114 &1867554086 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1867554083} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2fef72b18d93243989c8abf174b9081f, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!222 &1867554087 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1867554083} + m_CullTransparentMesh: 1 --- !u!1 &1922002212 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/DeviceTypeText.cs b/Assets/Scripts/DeviceTypeText.cs new file mode 100644 index 0000000..13cbaf1 --- /dev/null +++ b/Assets/Scripts/DeviceTypeText.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using Utility; + +public class DeviceTypeText : MonoBehaviour +{ + private Text text; + private string deviceType = "PC"; + + void Awake() + { + text = GetComponent(); +#if UNITY_WEBGL && !UNITY_EDITOR + deviceType = WebGL.GetDeviceType(); +#endif + } + + void Start() + { + text.text = "デバイス: " + deviceType; + } + +} diff --git a/Assets/Scripts/DeviceTypeText.cs.meta b/Assets/Scripts/DeviceTypeText.cs.meta new file mode 100644 index 0000000..71e0215 --- /dev/null +++ b/Assets/Scripts/DeviceTypeText.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2fef72b18d93243989c8abf174b9081f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utility.cs b/Assets/Scripts/Utility.cs index 43ba501..3bcb8be 100644 --- a/Assets/Scripts/Utility.cs +++ b/Assets/Scripts/Utility.cs @@ -95,6 +95,12 @@ public static class WebGL /// /// 真ならタッチ可能 [DllImport("__Internal")] public static extern bool CheckTouchDevice(); + + /// + /// デバイス種別を確認します + /// + /// デバイス種別の文字列 + [DllImport("__Internal")] public static extern string GetDeviceType(); } #endif }