///// <summary> 对字节数组加密或解密 </summary> ///// <param name="key"> 密钥. 同一个密钥使用偶数次可以消除这个密钥对数据的影响 </param> ///// <param name="array"> 执行加密或解密的数组 </param> ///// <param name="index"> 数组开始加密或解密的下标 </param> ///// <param name="count"> 需要加密或解密的字节总数, 非正值表示直到数组尾部 </param> ///// <returns> 校验码. 如果同一个密钥在两次处理数据之间其他密钥处理次数都是偶数, 那么这两次返回的校验码是相同的. 校验码可以用来判断数据是否被修改 </returns> //public static int EncryptDecrypt(uint key, byte[] array, int index = 0, int count = 0) //{ // Random random = new Random(key); // byte byte0 = (byte)random.Range(0, 256); // byte byte1 = (byte)random.Range(0, 256); // byte byte2 = byte0; // byte byte3 = byte1; // if (count > 0) count += index; // else count = array.Length; // for (int i = index; i < count; i++) // { // byte0 += array[i]; // byte1 -= array[i]; // array[i] ^= (byte)random.Range(0, 256); // byte2 += array[i]; // byte3 -= array[i]; // } // if (byte0 > byte2) Swap(ref byte0, ref byte2); // if (byte1 < byte3) Swap(ref byte1, ref byte3); // return (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (int)byte3; //} /// <summary> /// 将 Vector2 值写入字节数组 /// </summary> /// <param name="buffer"> 字节数组 </param> /// <param name="offset"> 写入字节数组的开始下标, 操作完成后增加 8 </param> /// <param name="value"> 被写入的值 </param> public static void Write(IList<byte> buffer, ref int offset, Vector2 value) { Union8 union = new Union8(); union.floatValue = value.x; union.WriteFloat(buffer, ref offset); union.floatValue = value.y; union.WriteFloat(buffer, ref offset); }
/// <summary> /// 将 Rect 值写入字节数组 /// </summary> /// <param name="buffer"> 字节数组 </param> /// <param name="offset"> 写入字节数组的开始下标, 操作完成后增加 16 </param> /// <param name="value"> 被写入的值 </param> public static void Write(IList<byte> buffer, ref int offset, Rect value) { Union8 union = new Union8(); union.floatValue = value.x; union.WriteFloat(buffer, ref offset); union.floatValue = value.y; union.WriteFloat(buffer, ref offset); union.floatValue = value.width; union.WriteFloat(buffer, ref offset); union.floatValue = value.height; union.WriteFloat(buffer, ref offset); }
/// <summary> /// 将 Color 值写入字节数组 /// </summary> /// <param name="buffer"> 字节数组 </param> /// <param name="offset"> 写入字节数组的开始下标, 操作完成后增加 16 </param> /// <param name="value"> 被写入的值 </param> public static void Write(IList<byte> buffer, ref int offset, Color value) { Union8 union = new Union8(); union.floatValue = value.r; union.WriteFloat(buffer, ref offset); union.floatValue = value.g; union.WriteFloat(buffer, ref offset); union.floatValue = value.b; union.WriteFloat(buffer, ref offset); union.floatValue = value.a; union.WriteFloat(buffer, ref offset); }
/// <summary> /// 将 Bounds 值写入字节数组 /// </summary> /// <param name="buffer"> 字节数组 </param> /// <param name="offset"> 写入字节数组的开始下标, 操作完成后增加 24 </param> /// <param name="value"> 被写入的值 </param> public static void Write(IList<byte> buffer, ref int offset, Bounds value) { Union8 union = new Union8(); var v3 = value.center; union.floatValue = v3.x; union.WriteFloat(buffer, ref offset); union.floatValue = v3.y; union.WriteFloat(buffer, ref offset); union.floatValue = v3.z; union.WriteFloat(buffer, ref offset); v3 = value.size; union.floatValue = v3.x; union.WriteFloat(buffer, ref offset); union.floatValue = v3.y; union.WriteFloat(buffer, ref offset); union.floatValue = v3.z; union.WriteFloat(buffer, ref offset); }