服务器c# 自己写,前端用u3d,调试的时候服务器不够直观。于是想到做个小的unity端做debug用。
http://neil.wyh.blog.163.com/blog/static/3161151201361480843/
当前线程不在单线程单元中,因此无法实例化 ActiveX 控件解决办法
http://blog.csdn.net/xuehuic/article/details/6426284
C#中char[]与string之间的转换
http://www.cnblogs.com/wintalen/archive/2010/12/20/1911599.html
类序列化到string
public static class Util
{
public static string SerializeToString(object data)
{
var bts = Serialize(data);
string str = CharsToString(BytesToChars(bts));
str = @str.Replace("\0", "|% (");
return str;
}
public static object DescrializeFromString(string str)
{
str = @str.Replace("|% (","\0");
var cs = StringToChars(str);
var bts = CharsToBytes(cs);
var obj = Deserialize(bts);
return obj;
}
private static char[] BytesToChars(byte[] bts)
{
char[] tmp = new char[bts.Length];
for (int i = 0; i < bts.Length; i++)
{
tmp[i] = (char)bts[i];
}
return tmp;
}
private static byte[] CharsToBytes(char[] cs)
{
byte[] bts = new byte[cs.Length];
for (int i = 0; i < bts.Length; i++)
{
bts[i] = (byte)cs[i];
}
return bts;
}
private static char[] StringToChars(string str)
{
return str.ToCharArray();
}
private static string CharsToString(char[] cs)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var item in cs)
{
sb.Append(item);
}
string s = sb.ToString();
return s;
}
private static byte[] Serialize(object data)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream rems = new System.IO.MemoryStream();
formatter.Serialize(rems, data);
return rems.GetBuffer();
}
private static object Deserialize(byte[] data)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream rems = new System.IO.MemoryStream(data);
data = null;
return formatter.Deserialize(rems);
}
}