You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WriteReadXML;
using System;
using System.IO;
using UnityEngine.UI;
public class MousePositionRecorder : MonoBehaviour {
private float startTime;
private string path;
[SerializeField]
private bool record;
MouseRecordData recordData;
private bool saving =false;
[SerializeField]
GameObject InputFileName;
// Use this for initialization
void Start () {
record = false;
recordData = new MouseRecordData();
path = Application.dataPath + "/../TUIOData";
}
// Update is called once per frame
void Update () {
if (saving)
return;
if(Input.GetKeyDown(KeyCode.LeftControl))
if (!record)
{
StartReocrd();
}
if(Input.GetKeyUp(KeyCode.LeftControl))
if (record)
StopRecord();
if (Input.GetKey(KeyCode.LeftControl))
{
if(Input.GetMouseButtonDown(0))
{
recordData.AddData(Time.time - startTime, Input.mousePosition, (int)TouchPhase.Began);
}
if (Input.GetMouseButton(0))
{
if (record && Time.frameCount % 2 == 0)
{
recordData.AddData(Time.time - startTime, Input.mousePosition,(int)TouchPhase.Moved);
}
}
if (Input.GetMouseButtonUp(0))
{
recordData.AddData(Time.time - startTime, Input.mousePosition, (int)TouchPhase.Ended);
}
}
}
void StartReocrd()
{
print("start record");
record = true;
startTime = Time.time;
recordData = new MouseRecordData();
}
void StopRecord()
{
print("stop record");
record = false;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
saving = true;
InputFileName.GetComponentInChildren<InputField>().textComponent.text = "";
InputFileName.GetComponentInChildren<InputField>().text = "";
InputFileName.SetActive(saving);
}
public void SaveData(string filename)
{
if(filename != "")
WriteRead_XML.write(path + "/" + filename + ".xml", recordData);
else
WriteRead_XML.write(path + "/" + DateTime.Now.ToString("yyyy-MMdd-HHmmss") + ".xml", recordData);
saving = false;
InputFileName.SetActive(saving);
}
}