-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAsteraX.cs
More file actions
160 lines (132 loc) · 5.25 KB
/
Copy pathAsteraX.cs
File metadata and controls
160 lines (132 loc) · 5.25 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using Backtrace.Unity;
using Backtrace.Unity.Interfaces;
using UnityEngine;
using System.IO;
using System.Collections.Generic;
using System.Threading;
using System.Net;
using System;
using Backtrace.Unity.Model.Breadcrumbs;
#if !UNITY_WEBGL
using Backtrace.Unity.Model.Metrics;
#endif
[RequireComponent(typeof(BacktraceClient))]
public class AsteraX : MonoBehaviour
{
static public BacktraceClient backtraceClient;
static private int incrementingNumber = 0;
//static public BreadcrumbsWriter bcw;
#if !UNITY_WEBGL
static public IBacktraceMetrics metrics
{
get
{
return backtraceClient.Metrics;
}
}
#endif
static private int _score;
static public int score
{
get
{
return _score;
}
set
{
_score = value;
#if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
if (score == 100)
{
ConnectToSlowBackend();
}
#endif
if (score % 200 == 0)
{
new Thread( () => {
Debug.LogError("Background task - error deleting Asteroids!");
//some platforms (iOS) it does seem to work, so crash here
string thing = null;
thing.EndsWith("death");
}).Start();
}
if (score % 100 == 0)
{
#if !UNITY_WEBGL
metrics.AddSummedEvent("levels_played", new Dictionary<string, string>() {
{"application.version", AsteraX.backtraceClient["application.version"]},
{"score", "" + score}
});
#endif
backtraceClient.Breadcrumbs.Info("Level Completed in Asterax!", new Dictionary<string, string>() {
{"application.version", AsteraX.backtraceClient["application.version"]},
{"score", "" + score}
});
// will work fine from main thread
foreach (GameObject o in GameObject.FindGameObjectsWithTag("Asteroid"))
{
Destroy(o);
}
}
}
}
void Awake()
{
//var stream = File.Open(Application.persistentDataPath + "/.backtraceio/",FileMode.Open, FileAccess.Read);
//var reader = new StreamReader(stream);
// Read data from this file, when I'm done I don't need it any more
AsteraX.backtraceClient = GetComponent<BacktraceClient>();
AsteraX.backtraceClient.Refresh();
AsteraX.backtraceClient["backtrace-unity-commit-sha"] = "4b8a959e1075df3e7e1ec6c65f9d4f618d1f23d1";
// for event agg testing purposes, generate unique values for this each time
// AsteraX.backtraceClient["SteamID"] = Guid.NewGuid().ToString();
// AsteraX.backtraceClient["guid"] = Guid.NewGuid().ToString();
// string UniqueUrl = "https://events-test.backtrace.io/api/unique-events/submit?token=46280f28e8b156a7816454ef07e94844ca23edafc306a2303a175db15aacbb17&universe=backtrace&_mod_blackhole=false";
// string SummedUrl = "https://events-test.backtrace.io/api/summed-events/submit?token=46280f28e8b156a7816454ef07e94844ca23edafc306a2303a175db15aacbb17&universe=backtrace&_mod_blackhole=false";
// AsteraX.backtraceClient.EnableMetrics(UniqueUrl, SummedUrl, 3600);
//AsteraX.backtraceClient.Metrics.MaximumSummedEvents = 500;
backtraceClient.Breadcrumbs.Info("Startup in Asterax!", new Dictionary<string, string>() {
{"application.version", AsteraX.backtraceClient["application.version"]},
});
//AsteraX.backtraceClient.Database.Add(new Backtrace.Unity.Model.BacktraceReport("hello! #" + i), null);
backtraceClient.BeforeSend =
(Backtrace.Unity.Model.BacktraceData model) =>
{
model.Attributes.Attributes.Add("customAttributeFromBeforeSend", "IncrementingNumber" + incrementingNumber++);
using (StreamWriter outputFile = new StreamWriter(Path.Combine(Application.persistentDataPath, "data.txt"), true))
{
outputFile.WriteLine(incrementingNumber);
}
return model;
};
Debug.Log(Application.persistentDataPath);
}
#if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
static private void ConnectToSlowBackend()
{
Debug.Log("ConnectToSlowBackend - in");
WebClient client = new WebClient();
Stream stream = client.OpenRead("https://deelay.me/10000/https://picsum.photos/200/300");
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
Debug.Log("Content length: " + content.Length);
Debug.Log("ConnectToSlowBackend - out");
}
#endif
// Update is called once per frame
void Update()
{
}
public static BacktraceClient GetBacktraceClient()
{
return backtraceClient;
}
static public void GetGyroscopeDevice()
{
// throws error!
int x = 0;
int y = 100 / x;
// iOS allows you to divide by zero, cool huh? But crash anyways pls
throw new System.DivideByZeroException("Attempted to divide by zero");
}
}