-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThinksyLink.cs
80 lines (68 loc) · 1.91 KB
/
ThinksyLink.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
class ThinksyLink : MonoBehaviour
{
public string gameAccessToken = null;
//this is your developer access token obtained from
//the Senseix website.
private static ThinksyLink singletonInstance;
private const int reconnectRetryInterval = 3000;
private static uint heartbeatInterval = 1401;
static private ThinksyLink GetSingletonInstance()
{
if (singletonInstance == null)
{
singletonInstance = FindObjectOfType<ThinksyLink>();
}
if (singletonInstance == null)
{
throw new Exception("There is no Thinksy Link");
}
return singletonInstance;
}
void OnApplicationFocus(bool isFocused)
{
if (isFocused) StaticReinitialize ();
}
void Awake()
{
if (gameAccessToken == null || gameAccessToken == "")
throw new Exception ("Please enter a game access token.");
}
void Update()
{
if (!Senseix.SenseixSession.GetSessionState() && Time.frameCount%reconnectRetryInterval == 0)
{
Debug.Log ("Attempting to reconnect...");
StartCoroutine(Senseix.SenseixSession.InitializeSenseix(gameAccessToken));
}
if (Senseix.SenseixSession.GetSessionState() && Time.frameCount%heartbeatInterval == 0 && Time.frameCount != 0)
{
Senseix.Logger.BasicLog("Getting encouragements...");
Senseix.SenseixSession.Heartbeat();
}
}
public static void NewHeartbeatTiming(uint newTiming)
{
if (newTiming < 100)
return;
heartbeatInterval = newTiming;
}
public static void StaticReinitialize()
{
GetSingletonInstance().Reinitialize ();
}
/// <summary>
/// Resends all the server communication involved in initializing the game.
/// </summary>
public void Reinitialize()
{
StartCoroutine(Senseix.SenseixSession.LimitedInitializeSenseix (gameAccessToken));
}
public static void SetAccessToken(string newAccessToken)
{
GetSingletonInstance().gameAccessToken = newAccessToken;
}
}