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.
54 lines
1.3 KiB
54 lines
1.3 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using AX.Serialization; |
|
using System.IO; |
|
|
|
public class SaveInputHistory : MonoBehaviour { |
|
|
|
// Use this for initialization |
|
void Start () { |
|
|
|
} |
|
|
|
// Update is called once per frame |
|
void Update () { |
|
|
|
} |
|
|
|
private void OnEnable() |
|
{ |
|
gameObject.GetComponent<Button>().onClick.AddListener(OnClick); |
|
} |
|
|
|
private void OnDisable() |
|
{ |
|
gameObject.GetComponent<Button>().onClick.RemoveListener(OnClick); |
|
} |
|
|
|
private void OnDestroy() |
|
{ |
|
gameObject.GetComponent<Button>().onClick.RemoveListener(OnClick); |
|
} |
|
|
|
private void OnClick() |
|
{ |
|
var inputHistoryData = InputHistory.Instance.CompressedSerialize(); |
|
|
|
var directory = Application.dataPath + "/" + "HistoryData"; |
|
if (!Directory.Exists(directory)) |
|
Directory.CreateDirectory(directory); |
|
|
|
var fileName = System.Guid.NewGuid().ToString("N").ToUpper() + ".replay"; |
|
var filePath = directory + "/" + fileName; |
|
|
|
using (var filestream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite)) |
|
{ |
|
filestream.Write(inputHistoryData, 0, inputHistoryData.Length); |
|
} |
|
|
|
gameObject.GetComponent<Button>().interactable = false; |
|
} |
|
}
|
|
|