136 lines
3.8 KiB
C#
136 lines
3.8 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ͨ<>ù<EFBFBD><C3B9><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class CommonTools
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD>Ƕ<EFBFBD>
|
|||
|
|
/// </summary>.
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static float GetDu(string data1, string data2)
|
|||
|
|
{
|
|||
|
|
float loData = (Convert.ToInt32(data1, 16) << 8 | Convert.ToInt32(data2, 16)) / 100f;
|
|||
|
|
if (loData > 360)
|
|||
|
|
{
|
|||
|
|
loData = 360 - (Convert.ToInt32("0xffff", 16) - (Convert.ToInt32(data1, 16) << 8 | Convert.ToInt32(data2, 16))) / 100f;
|
|||
|
|
}
|
|||
|
|
return loData;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="data1"></param>
|
|||
|
|
/// <param name="data2"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static float GetShuJu(string data1, string data2)
|
|||
|
|
{
|
|||
|
|
return Convert.ToInt32(data1, 16) * 256 + Convert.ToInt32(data2, 16);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD>Ƕ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static Quaternion GetEuler(float pitch, float yaw, float roll)
|
|||
|
|
{
|
|||
|
|
Vector3 eulerAngles2 = new(pitch, yaw, roll);
|
|||
|
|
return Quaternion.Euler(eulerAngles2);
|
|||
|
|
}
|
|||
|
|
#region 16<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>ת16<31><36><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static string byteToHexStr(byte[] bytes)
|
|||
|
|
{
|
|||
|
|
string returnStr = "";
|
|||
|
|
if (bytes != null)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < bytes.Length; i++)
|
|||
|
|
{
|
|||
|
|
returnStr += bytes[i].ToString("X2");
|
|||
|
|
returnStr += "-";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return returnStr;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ַ<EFBFBD><D6B7><EFBFBD>ת16<31><36><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input">Ҫת<D2AA><D7AA>ʽ<EFBFBD><CABD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
|
|||
|
|
/// <returns>ת<><D7AA>Ϊ16<31><36><EFBFBD>Ƶ<EFBFBD><C6B5>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|||
|
|
private static string ToSixteen(string input)
|
|||
|
|
{
|
|||
|
|
char[] values = input.ToCharArray();
|
|||
|
|
string end = string.Empty;
|
|||
|
|
foreach (char letter in values)
|
|||
|
|
{
|
|||
|
|
int value = Convert.ToInt32(letter);
|
|||
|
|
string hexoutput = string.Format("{0:X}", value); //0 <20><>ʾռλ<D5BC><CEBB> x<><78>X<EFBFBD><58>ʾʮ<CABE><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
end += hexoutput + "_";
|
|||
|
|
}
|
|||
|
|
end = end.Remove(end.Length - 1);
|
|||
|
|
return end;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 16<31><36><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input">16<31><36><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <returns>ת<>ص<EFBFBD><D8B5>ַ<EFBFBD><D6B7><EFBFBD></returns>
|
|||
|
|
private static string ToMyString(string input)
|
|||
|
|
{
|
|||
|
|
string[] hexvaluesplit = input.Split('_');
|
|||
|
|
string end = string.Empty;
|
|||
|
|
foreach (string hex in hexvaluesplit)
|
|||
|
|
{
|
|||
|
|
int value = Convert.ToInt32(hex, 16);
|
|||
|
|
string stringvalue = char.ConvertFromUtf32(value);
|
|||
|
|
char charValue = (char)value;
|
|||
|
|
end += charValue;
|
|||
|
|
}
|
|||
|
|
return end;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="hexStr"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static byte[] HexStringToBytes(string hexStr)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(hexStr))
|
|||
|
|
{
|
|||
|
|
return new byte[0];
|
|||
|
|
}
|
|||
|
|
if (hexStr.StartsWith("0x"))
|
|||
|
|
{
|
|||
|
|
hexStr = hexStr.Remove(0, 2);
|
|||
|
|
}
|
|||
|
|
var count = hexStr.Length;
|
|||
|
|
var byteCount = count / 2;
|
|||
|
|
var result = new byte[byteCount];
|
|||
|
|
for (int ii = 0; ii < byteCount; ++ii)
|
|||
|
|
{
|
|||
|
|
var tempBytes = Byte.Parse(hexStr.Substring(2 * ii, 2), System.Globalization.NumberStyles.HexNumber);
|
|||
|
|
result[ii] = tempBytes;
|
|||
|
|
}
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> -- <20>Ƽ<EFBFBD><C6BC>÷<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static byte[] Convert16(string strText)
|
|||
|
|
{
|
|||
|
|
strText = strText.Replace(" ", "");
|
|||
|
|
byte[] bText = new byte[strText.Length / 2];
|
|||
|
|
for (int i = 0; i < strText.Length / 2; i++)
|
|||
|
|
{
|
|||
|
|
bText[i] = Convert.ToByte(Convert.ToInt32(strText.Substring(i * 2, 2), 16));
|
|||
|
|
}
|
|||
|
|
return bText;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|