60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using BrewMonster;
|
|
using CSNetwork.GPDataType;
|
|
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using static EC_Player;
|
|
|
|
public static class EC_Utility
|
|
{
|
|
public static byte glb_CompressDirH(float x, float z)
|
|
{
|
|
const float fInvInter = 256.0f / 360.0f;
|
|
|
|
if (Math.Abs(x) < 0.00001f)
|
|
{
|
|
if (z > 0.0f)
|
|
return 64;
|
|
else
|
|
return 192;
|
|
}
|
|
else
|
|
{
|
|
// atan2 trong C# trả về radian, cần đổi sang độ
|
|
float fDeg = (float)(Math.Atan2(z, x) * (180.0 / Math.PI));
|
|
|
|
// đảm bảo góc nằm trong [0, 360)
|
|
if (fDeg < 0)
|
|
fDeg += 360.0f;
|
|
|
|
return (byte)(fDeg * fInvInter);
|
|
}
|
|
}
|
|
public static System.Numerics.Vector3 ToNumerics(this UnityEngine.Vector3 v)
|
|
{
|
|
return new System.Numerics.Vector3(v.x, v.y, v.z);
|
|
}
|
|
public static Vector3 ToVector3(A3DVECTOR3 a3DVECTOR3)
|
|
{
|
|
return new Vector3(a3DVECTOR3.x, a3DVECTOR3.y, a3DVECTOR3.z);
|
|
}
|
|
public static float MagnitudeH(this Vector3 v)
|
|
{
|
|
return Mathf.Sqrt(v.x * v.x + v.z * v.z);
|
|
}
|
|
public static string BuildActionName(PLAYER_ACTION action, int weaponType)
|
|
{
|
|
string prefix = action.data.ActionPrefix ?? string.Empty;
|
|
string suffix = string.Empty;
|
|
|
|
if (action.data.action_weapon_suffix != null
|
|
&& weaponType >= 0
|
|
&& weaponType < action.data.action_weapon_suffix.Length)
|
|
{
|
|
suffix = action.data.action_weapon_suffix[weaponType].Suffix ?? string.Empty;
|
|
}
|
|
|
|
return $"{prefix}_{suffix}";
|
|
}
|
|
}
|