public override void OnSendData()
    {
        BufferedNetworkUtilsServer.SendSerializableClass(CustomClassDataInstance);

        BufferedNetworkUtilsServer.SendInt(IntInstance);

        BufferedNetworkUtilsServer.SendVector3(Vector3Instance);

        BufferedNetworkUtilsServer.SendString(StringInstance);

        BufferedNetworkUtilsServer.SendStruct(CustomDataInstance);

        BufferedNetworkUtilsServer.SendList <InsideCustomData>(ListData);

        BufferedNetworkUtilsServer.SendDic <string, Vector3>(DicData);
    }
        void switchCaseFunc(FduMultiAttributeObserverOP op, ref NetworkState.NETWORK_STATE_TYPE state)
        {
            if (_ObservedComponent == null || _props == null)
            {
                return;
            }

            for (int i = 0; i < _bitArray.Length; ++i)
            {
                if (!_bitArray[i])
                {
                    continue;
                }
                if (op == FduMultiAttributeObserverOP.SendData)
                {
                    if (_props[i].PropertyType.IsEnum)
                    {
                        BufferedNetworkUtilsServer.SendInt(System.Convert.ToInt32(_props[i].GetValue(_ObservedComponent, null)));
                    }
                    else if (_props[i].PropertyType.Equals(typeof(string)))
                    {
                        BufferedNetworkUtilsServer.SendString((string)_props[i].GetValue(_ObservedComponent, null));
                    }
                    else
                    {
                        BufferedNetworkUtilsServer.SendStruct(_props[i].GetValue(_ObservedComponent, null));
                    }
                }
                else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                {
                    if (_props[i].PropertyType.IsEnum)
                    {
                        _props[i].SetValue(_ObservedComponent, BufferedNetworkUtilsClient.ReadInt(ref state), null);
                    }
                    else if (_props[i].PropertyType.Equals(typeof(string)))
                    {
                        _props[i].SetValue(_ObservedComponent, BufferedNetworkUtilsClient.ReadString(ref state), null);
                    }
                    else
                    {
                        _props[i].SetValue(_ObservedComponent, BufferedNetworkUtilsClient.ReadStruct(_props[i].PropertyType, ref state), null);
                    }
                }
            }
        }
Exemple #3
0
 public override void Serialize()
 {
     BufferedNetworkUtilsServer.SendStruct(Random.state);
 }
Exemple #4
0
        internal void SerializeGenericData()
        {
            var enu = _genericMap.GetEnumerator();

            BufferedNetworkUtilsServer.SendInt(_genericMap.Count);
            while (enu.MoveNext())
            {
                BufferedNetworkUtilsServer.SendString(enu.Current.Key);
                genericData _data = enu.Current.Value;
                BufferedNetworkUtilsServer.SendString(_data.keyTypeName);
                BufferedNetworkUtilsServer.SendString(_data.valueTypeName);
                BufferedNetworkUtilsServer.SendString(_data.containerTypeName);
                int count = _data.valueData.Count;
                BufferedNetworkUtilsServer.SendInt(count);

                bool        isStringK = false; bool isStringV = false;
                System.Type typeK = System.Type.GetType(_data.keyTypeName);
                System.Type typeV = System.Type.GetType(_data.valueTypeName);

                if (typeV != null && typeV.Equals(typeof(string)))
                {
                    isStringV = true;
                }
                if (typeK != null && typeK.Equals(typeof(string)))
                {
                    isStringK = true;
                }

                if (_data.containerTypeName == "dic")
                {
                    for (int i = 0; i < _data.valueData.Count; i = i + 2)
                    {
                        if (isStringK)
                        {
                            BufferedNetworkUtilsServer.SendString((string)_data.valueData[i]);
                        }
                        else if (typeK.IsEnum)
                        {
                            BufferedNetworkUtilsServer.SendInt(System.Convert.ToInt32(_data.valueData[i]));
                        }
                        else
                        {
                            BufferedNetworkUtilsServer.SendStruct(_data.valueData[i]);
                        }

                        if (isStringV)
                        {
                            BufferedNetworkUtilsServer.SendString((string)_data.valueData[i + 1]);
                        }
                        else if (typeV.IsEnum)
                        {
                            BufferedNetworkUtilsServer.SendInt(System.Convert.ToInt32(_data.valueData[i + 1]));
                        }
                        else
                        {
                            BufferedNetworkUtilsServer.SendStruct(_data.valueData[i + 1]);
                        }
                    }
                }
                else if (_data.containerTypeName == "queue" || _data.containerTypeName == "list" || _data.containerTypeName == "stack")
                {
                    for (int i = 0; i < _data.valueData.Count; ++i)
                    {
                        if (isStringV)
                        {
                            BufferedNetworkUtilsServer.SendString((string)_data.valueData[i]);
                        }
                        else if (typeV.IsEnum)
                        {
                            BufferedNetworkUtilsServer.SendInt(System.Convert.ToInt32(_data.valueData[i]));
                        }
                        else
                        {
                            BufferedNetworkUtilsServer.SendStruct(_data.valueData[i]);
                        }
                    }
                }
            }
        }
Exemple #5
0
        //序列化一个可传送的参数
        public static void serializeOneParameter(object para)
        {
            FduSendableParameter typeCode = FduGlobalConfig.getSendableParameterCode(para);

            BufferedNetworkUtilsServer.SendByte((byte)typeCode);
            switch (typeCode)
            {
            case FduSendableParameter.Int:
                BufferedNetworkUtilsServer.SendInt((int)para);
                break;

            case FduSendableParameter.IntArray:
                BufferedNetworkUtilsServer.SendIntArray((int[])para);
                break;

            case FduSendableParameter.Byte:
                BufferedNetworkUtilsServer.SendByte((byte)para);
                break;

            case FduSendableParameter.ByteArray:
                BufferedNetworkUtilsServer.SendByteArray((byte[])para);
                break;

            case FduSendableParameter.Float:
                BufferedNetworkUtilsServer.SendFloat((float)para);
                break;

            case FduSendableParameter.FloatArray:
                BufferedNetworkUtilsServer.SendFloatArray((float[])para);
                break;

            case FduSendableParameter.Bool:
                BufferedNetworkUtilsServer.SendBool((bool)para);
                break;

            case FduSendableParameter.BoolArray:
                bool[] bolarr = (bool[])para;
                int    bollen = bolarr.Length;
                BufferedNetworkUtilsServer.SendInt(bollen);
                for (int i = 0; i < bollen; ++i)
                {
                    BufferedNetworkUtilsServer.SendBool(bolarr[i]);
                }
                break;

            case FduSendableParameter.String:
                BufferedNetworkUtilsServer.SendString((string)para);
                break;

            case FduSendableParameter.StringArray:
                string[] strarr = (string[])para;
                int      strlen = strarr.Length;
                BufferedNetworkUtilsServer.SendInt(strlen);
                for (int i = 0; i < strlen; ++i)
                {
                    BufferedNetworkUtilsServer.SendString(strarr[i]);
                }
                break;

            case FduSendableParameter.Vector2:
                BufferedNetworkUtilsServer.SendVector2((Vector2)para);
                break;

            case FduSendableParameter.Vector2Array:
                Vector2[] v2arr = (Vector2[])para;
                int       v2len = v2arr.Length;
                BufferedNetworkUtilsServer.SendInt(v2len);
                for (int i = 0; i < v2len; ++i)
                {
                    BufferedNetworkUtilsServer.SendVector2(v2arr[i]);
                }
                break;

            case FduSendableParameter.Vector3:
                BufferedNetworkUtilsServer.SendVector3((Vector3)para);
                break;

            case FduSendableParameter.Vector3Array:
                Vector3[] v3arr = (Vector3[])para;
                int       v3len = v3arr.Length;
                BufferedNetworkUtilsServer.SendInt(v3len);
                for (int i = 0; i < v3len; ++i)
                {
                    BufferedNetworkUtilsServer.SendVector3(v3arr[i]);
                }
                break;

            case FduSendableParameter.Vector4:
                BufferedNetworkUtilsServer.SendVector4((Vector4)para);
                break;

            case FduSendableParameter.Vector4Array:
                Vector4[] v4arr = (Vector4[])para;
                int       v4len = v4arr.Length;
                BufferedNetworkUtilsServer.SendInt(v4len);
                for (int i = 0; i < v4len; ++i)
                {
                    BufferedNetworkUtilsServer.SendVector3(v4arr[i]);
                }
                break;

            case FduSendableParameter.Color:
                BufferedNetworkUtilsServer.SendColor((Color)para);
                break;

            case FduSendableParameter.ColorArray:
                Color[] carray = (Color[])para;
                int     clen   = carray.Length;
                BufferedNetworkUtilsServer.SendInt(clen);
                for (int i = 0; i < clen; ++i)
                {
                    BufferedNetworkUtilsServer.SendColor(carray[i]);
                }
                break;

            case FduSendableParameter.Quaternion:
                BufferedNetworkUtilsServer.SendQuaternion((Quaternion)para);
                break;

            case FduSendableParameter.QuaternionArray:
                Quaternion[] qarr = (Quaternion[])para;
                int          qlen = qarr.Length;
                BufferedNetworkUtilsServer.SendInt(qlen);
                for (int i = 0; i < qlen; i++)
                {
                    BufferedNetworkUtilsServer.SendQuaternion(qarr[i]);
                }
                break;

            case FduSendableParameter.GameObject:
                if (((GameObject)para).GetClusterView() != null)
                {
                    BufferedNetworkUtilsServer.SendBool(true);
                    BufferedNetworkUtilsServer.SendInt(((GameObject)para).GetClusterView().ViewId);
                }
                else
                {
                    BufferedNetworkUtilsServer.SendBool(false);
                    BufferedNetworkUtilsServer.SendString(FduSupportClass.getGameObjectPath((GameObject)para));
                }
                break;

            case FduSendableParameter.ClusterView:
                BufferedNetworkUtilsServer.SendInt(((FduClusterView)para).ViewId);
                break;

            case FduSendableParameter.Matrix4X4:
                BufferedNetworkUtilsServer.SendMatrix4x4((Matrix4x4)para);
                break;

            case FduSendableParameter.Matrix4X4Array:
                Matrix4x4[] matarr = (Matrix4x4[])para;
                int         mlen   = matarr.Length;
                BufferedNetworkUtilsServer.SendInt(mlen);
                for (int i = 0; i < mlen; ++i)
                {
                    BufferedNetworkUtilsServer.SendMatrix4x4(matarr[i]);
                }
                break;

            case FduSendableParameter.Rect:
                BufferedNetworkUtilsServer.SendRect((Rect)para);
                break;

            case FduSendableParameter.RectArray:
                Rect[] rectArr = (Rect[])para;
                int    rectlen = rectArr.Length;
                BufferedNetworkUtilsServer.SendInt(rectlen);
                for (int i = 0; i < rectlen; ++i)
                {
                    BufferedNetworkUtilsServer.SendRect(rectArr[i]);
                }
                break;

            case FduSendableParameter.Struct:
                BufferedNetworkUtilsServer.SendString(para.GetType().AssemblyQualifiedName);
                BufferedNetworkUtilsServer.SendStruct(para);
                break;

            case FduSendableParameter.SerializableClass:
                BufferedNetworkUtilsServer.SendSerializableClass(para);
                break;

            case FduSendableParameter.Enum:
                BufferedNetworkUtilsServer.SendInt(System.Convert.ToInt32(para));
                break;

            default:
                throw new InvalidSendableDataException("Such type of data can not be sent. Type name:" + para.GetType().FullName);
            }
        }