73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using UnityEngine;
|
|
using CustomExtensions;
|
|
using System;
|
|
|
|
public struct InputState{
|
|
public int Tick;
|
|
public Vector2 Input;
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"tick: {Tick}, input: {Input}";
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
InputState _obj = (InputState) obj;
|
|
if(_obj.Input == Input){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool CloseEnough(InputState other, float threshold) => Mathf.Abs((other.Input-Input).magnitude) < threshold;
|
|
}
|
|
|
|
public struct PlayerState{
|
|
public int Tick;
|
|
public Vector3 Position;
|
|
public Quaternion Rotation;
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"tick: {Tick},pos: {Position}, rot: {Rotation}";
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
PlayerState _obj = (PlayerState) obj;
|
|
if(_obj.Position == Position && _obj.Rotation == Rotation){
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool CloseEnough(PlayerState other, float threshold) => Mathf.Abs((other.Position-Position).magnitude) < threshold && Rotation.Approximately(other.Rotation, threshold);
|
|
|
|
public float Difference(PlayerState other){
|
|
return (Mathf.Abs((other.Position-Position).magnitude) + Rotation.Difference(other.Rotation))/2f;
|
|
}
|
|
|
|
}
|
|
|
|
public class Helpers{
|
|
public static int unixTimestamp = (int)System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1)).TotalSeconds;
|
|
|
|
}
|
|
|
|
namespace CustomExtensions{
|
|
public static class QuaternionExtensions{
|
|
public static bool Approximately(this Quaternion quatA, Quaternion value, float acceptableRange)
|
|
{
|
|
return 1 - Mathf.Abs(Quaternion.Dot(quatA, value)) < acceptableRange;
|
|
}
|
|
public static float Difference(this Quaternion quatA, Quaternion value){
|
|
return 1 - Mathf.Abs(Quaternion.Dot(quatA, value));
|
|
}
|
|
|
|
public static long ToUnix(this DateTime time){
|
|
return (long)time.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
|
|
}
|
|
}
|
|
} |