Exemplo n.º 1
0
        /// <summary>
        /// Objectデータをbyteの配列へ変換する
        /// </summary>
        /// <typeparam name="T">変換するObjectの型</typeparam>
        /// <param name="src">変換するObject</param>
        /// <param name="dst">byte型の配列</param>
        public static void ObjectToBytes <T>(T src, out byte[] dst)
#if SERIALIZATION_BINARFORMATTER
        {
            UnityChoseKun.Log("Start Serialize");
            var bf = new BinaryFormatter();
            var ms = new MemoryStream();

            try
            {
                bf.Serialize(ms, src);
                dst = ms.ToArray();
            }
            finally
            {
                ms.Close();
                UnityChoseKun.Log("End Serialize");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// メッセージの受信CB
        /// </summary>
        /// <param name="args">メッセージデータ</param>
        private void OnMessageEvent(UnityEngine.Networking.PlayerConnection.MessageEventArgs args)
        {
            MemoryStream memoryStream = new MemoryStream(args.data);
            BinaryReader binaryReader = new BinaryReader(memoryStream);

            var messageID = (UnityChoseKun.MessageID)binaryReader.ReadInt32();



            UnityChoseKun.Log("UnityChosekunEditorWindow.OnMessageEvent(playerID: " + args.playerId + ",message.id" + messageID + ")");
            if (onMessageFuncDict != null && onMessageFuncDict.ContainsKey(messageID) == true)
            {
                var func = onMessageFuncDict[messageID];
                func(binaryReader);
            }

            binaryReader.Close();
            memoryStream.Close();
        }