45 lines
1.2 KiB
C#
Executable File
45 lines
1.2 KiB
C#
Executable File
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using Mirror;
|
|
|
|
public class PositionUnitTest : NetworkBehaviour
|
|
{
|
|
Logger logger = null;
|
|
SpaceshipController _controller;
|
|
void Start(){
|
|
_controller = GetComponent<SpaceshipController>();
|
|
}
|
|
void FixedUpdate()
|
|
{
|
|
if(logger == null){
|
|
if(_controller.pname.Length>0){
|
|
logger= new Logger(_controller.pname);
|
|
}
|
|
return;
|
|
}
|
|
logger.Log($"time: {NetworkTime.time}, pos: {transform.position}, rot: {transform.rotation}");
|
|
}
|
|
}
|
|
|
|
|
|
public class Logger{
|
|
private string name;
|
|
public string Name=> name;
|
|
public string FileLocation => $"{Application.dataPath}/{name}.log";
|
|
|
|
public Logger(string _name){
|
|
name=_name;
|
|
if(File.Exists(FileLocation)){
|
|
File.Delete(FileLocation);
|
|
}
|
|
File.WriteAllText(FileLocation, $"[{System.DateTime.Now}]Log Created\n");
|
|
Debug.Log($"Logger initiated at {FileLocation}");
|
|
}
|
|
|
|
public void Log(string newData){
|
|
File.AppendAllText(FileLocation, $"{newData}\n");
|
|
}
|
|
}
|