Skip to content

Commit

Permalink
feat: タイトルにデバイス種別を表示
Browse files Browse the repository at this point in the history
  • Loading branch information
IwamotoKakeru committed May 12, 2024
1 parent 525aa4c commit 26a4351
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 10 deletions.
29 changes: 19 additions & 10 deletions Assets/Plugins/CheckTouchDevice.jslib
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const plugin = {};

/**
* タッチできるデバイスかどうかを確認します
* @returns {Boolean} 真ならタッチ可能
Expand All @@ -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);
93 changes: 93 additions & 0 deletions Assets/Scenes/Title.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions Assets/Scripts/DeviceTypeText.cs
Original file line number Diff line number Diff line change
@@ -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<Text>();
#if UNITY_WEBGL && !UNITY_EDITOR
deviceType = WebGL.GetDeviceType();
#endif
}

void Start()
{
text.text = "デバイス: " + deviceType;
}

}
11 changes: 11 additions & 0 deletions Assets/Scripts/DeviceTypeText.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Assets/Scripts/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public static class WebGL
/// </summary>
/// <returns>真ならタッチ可能</returns>
[DllImport("__Internal")] public static extern bool CheckTouchDevice();

/// <summary>
/// デバイス種別を確認します
/// </summary>
/// <returns>デバイス種別の文字列</returns>
[DllImport("__Internal")] public static extern string GetDeviceType();
}
#endif
}

0 comments on commit 26a4351

Please sign in to comment.