金铉Unity插件库
Unity版本2018.4.32f
目前包含本地化存储功能(根据类名存储读写),TCP客户端监听类型功能
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.
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using LitJson;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace JXSoft {
|
|
|
|
//协议规则解析通用方法扩展
|
|
|
|
public static class ProtocolRulesExtention
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 根据Byte类型数据获取对应的值。
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="self">只能包含A-F,0-9</param>
|
|
|
|
/// <param name="start">起始位置</param>
|
|
|
|
/// <param name="length">长度</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static byte[] toByteArray(this string self) {
|
|
|
|
int hexlen = self.Length;
|
|
|
|
byte[] result;
|
|
|
|
if (hexlen % 2 == 1)
|
|
|
|
{
|
|
|
|
//奇数
|
|
|
|
hexlen++;
|
|
|
|
result = new byte[(hexlen / 2)];
|
|
|
|
self += "0" ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//偶数
|
|
|
|
result = new byte[(hexlen / 2)];
|
|
|
|
}
|
|
|
|
int j = 0;
|
|
|
|
for (int i = 0; i < hexlen; i += 2)
|
|
|
|
{
|
|
|
|
result[j] = (byte)int.Parse(self.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|