Skip to content

Commit

Permalink
Merge pull request #44 from IwamotoKakeru/feat/clear-times
Browse files Browse the repository at this point in the history
feat: クリア回数を取得・保存
  • Loading branch information
IwamotoKakeru authored May 18, 2024
2 parents 3d4fe34 + fad177a commit f2a1b7a
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 9 deletions.
23 changes: 23 additions & 0 deletions Assets/Plugins/CookieManager.jslib
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function SetClearTimes(clearTimes) {
document.cookie = "clear_times=" + clearTimes + ";max-age=31536000";
console.log("Set clearTimes = %d ", clearTimes);
}

// TODO: 現在の実装だとclearTimes以外の保存したいデータに対応できないので修正
function GetClearTimes() {
var clearTimes;
try {
clearTimes = parseInt(document.cookie.split("=")[1]);
console.log("clearTimes = %d ", clearTimes);
} catch {
console.log("Unable Get clearTimes", clearTimes);
}
return clearTimes;
}

const cookiePlugins = {};
cookiePlugins[SetClearTimes.name] = SetClearTimes;
cookiePlugins[GetClearTimes.name] = GetClearTimes;

// Unity側へ反映
mergeInto(LibraryManager.library, cookiePlugins);
32 changes: 32 additions & 0 deletions Assets/Plugins/CookieManager.jslib.meta

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

95 changes: 94 additions & 1 deletion Assets/Scenes/Title.unity
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,98 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &166402754
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 166402755}
- component: {fileID: 166402758}
- component: {fileID: 166402756}
- component: {fileID: 166402759}
m_Layer: 5
m_Name: ClearTimes
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &166402755
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 166402754}
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: 180}
m_SizeDelta: {x: 300, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &166402756
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 166402754}
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: "\u30AF\u30EA\u30A2\u56DE\u6570: --"
--- !u!222 &166402758
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 166402754}
m_CullTransparentMesh: 1
--- !u!114 &166402759
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 166402754}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ddfcfaff71e0d4dd1afcb3460ff78739, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &232318856
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -220,6 +312,7 @@ RectTransform:
- {fileID: 286217875}
- {fileID: 990477082}
- {fileID: 1867554084}
- {fileID: 166402755}
- {fileID: 374588864}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -3250,7 +3343,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'Device: PC'
m_Text: 'Device: --'
--- !u!114 &1867554086
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
28 changes: 28 additions & 0 deletions Assets/Scripts/ClearTimesText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Utility;

/// <summary>
/// タイトルでクリア回数を表示する
/// </summary>
public class ClearTimesText : MonoBehaviour
{
private Text text;
private int clearTimes = -1;

void Awake()
{
text = GetComponent<Text>();
#if UNITY_WEBGL && !UNITY_EDITOR
clearTimes = WebGL.GetClearTimes();
#endif
text.text = "クリア回数: " + clearTimes.ToString();
}

void Start()
{
}

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

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

3 changes: 3 additions & 0 deletions Assets/Scripts/DeviceTypeText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using UnityEngine.UI;
using Utility;

/// <summary>
/// タイトルでデバイス種別を表示するためのスクリプト
/// </summary>
public class DeviceTypeText : MonoBehaviour
{
private Text text;
Expand Down
21 changes: 14 additions & 7 deletions Assets/Scripts/Endroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,33 @@ public class Endroll : MonoBehaviour
};
private string company = "九州工業大学\nプログラミング研究会";
private string clearTimeText;
private int clearTimes = -1;

private Vector3 logoPos = new Vector3(0.0f, 1.6f, 0.0f);

void Start()
void Awake()
{
tex = GetComponent<Text>();

stopWatch = GameObject.Find("StopWatch").GetComponent<StopWatch>().stopWatch;
float totalSec = (float)(stopWatch.Elapsed.TotalMilliseconds / 1000);

#if UNITY_WEBGL && !UNITY_EDITOR
clearTimes = WebGL.GetClearTimes();
#endif
}

void Start()
{
float totalSec = (float)(stopWatch.Elapsed.TotalMilliseconds / 1000);
clearTimeText = "クリアタイム\n" + stopWatch.Elapsed.ToString(@"mm\:ss\.ff") + "\nCongratulation!!!\n";
clearTimeText += totalSec.ToString() + "秒としてランキングに掲載しました";

#if UNITY_EDITOR
// 何もしない
// エディター上で実行した際のタイムを登録しないようにするため
#else
#if UNITY_WEBGL && !UNITY_EDITOR
// unityroomのランキングへ登録
UnityroomApiClient.Instance.SendScore(1, totalSec, ScoreboardWriteMode.HighScoreDesc);

WebGL.SetClearTimes(clearTimes+1);
#endif
Debug.Log(clearTimes);

StartCoroutine(RunEndroll());
}
Expand Down
14 changes: 13 additions & 1 deletion Assets/Scripts/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class Tags
/// <summary>
/// ホバーのために用いる
/// </summary>
[ObsoleteAttribute("現在ホバーはEventTrigger経由で使用されるため非推奨")] public const string Hover = "Hover";
[Obsolete("現在ホバーはEventTrigger経由で使用されるため非推奨")] public const string Hover = "Hover";

/// <summary>
/// キャラクタが歩く地面や壁等に用いる
Expand Down Expand Up @@ -101,6 +101,18 @@ public static class WebGL
/// </summary>
/// <returns>デバイス種別の文字列</returns>
[DllImport("__Internal")] public static extern string GetDeviceType();


/// <summary>
/// cookieにクリア回数を書き込みます
/// </summary>
[DllImport("__Internal")] public static extern void SetClearTimes(int clearTimes);

/// <summary>
/// cookieからクリア回数を読み込みます
/// </summary>
/// <returns>クリア回数</returns>
[DllImport("__Internal")] public static extern int GetClearTimes();
}
#endif
}

0 comments on commit f2a1b7a

Please sign in to comment.