forked from Zero101011/UnityHeatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataRecorder.cs
More file actions
61 lines (58 loc) · 2.63 KB
/
Copy pathDataRecorder.cs
File metadata and controls
61 lines (58 loc) · 2.63 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
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
/*
* this Heatmap tool was originally developed by: Garen O'Donnell
* Date Created: 04/10/2019
* Modified by: Hadi Mehrpouya
* Date last modified: 14/10/2020
*/
public static class DataRecorder {
public static string m_path= "Assets/Resources/Text/";
/*
* This function will open the file using the path variable
* and then adds whatever the user is sending to the end of the file
* If you don't specify a seperator for this function, it will automatically uses ;
* if the user doesn'tspecity whether to add timestamp. by default this funciton will add it as the last column for each line or before the seperator.
*/
public static bool recordDeathPosition3D(Vector3 _pos)
{
string filePath = m_path + SceneManager.GetActiveScene().name;
bool result = false;
string lineToAdd= _pos.x + "," + _pos.y + "," + _pos.z;
Debug.Log(lineToAdd);
using (StreamWriter sw = File.AppendText(filePath+".txt")) //This line will try to open the file and if it doesn't exist, it will make it!
{
//Write death position vector to our text file as a new line
sw.WriteLine(lineToAdd);
sw.Close();
}
////Re-import the file to update the reference in the editor
AssetDatabase.ImportAsset(filePath+".txt");
TextAsset asset = Resources.Load<TextAsset>(filePath + ".txt");
////Print the text from the file
result = true;//If we get to this part of our code, this means things went ok, so we return true.
return result;
}
public static bool recordDeathPosition2D(Vector2 _pos)
{
string filePath = m_path + SceneManager.GetActiveScene().name + ".txt";
bool result = false;
string lineToAdd = _pos.x + "," + _pos.y;
using (StreamWriter sw = File.AppendText(m_path + ".txt")) //This line will try to open the file and if it doesn't exist, if will make it!
{
//Write death position vector to our text file as a new line
sw.WriteLine(lineToAdd);
sw.Close();
}
////Re-import the file to update the reference in the editor
AssetDatabase.ImportAsset(filePath);
TextAsset asset = Resources.Load<TextAsset>(filePath + ".txt");
////Print the text from the file
result = true;//If we get to this part of our code, this means things went ok, so we return true.
return result;
}
}