public override void OnReceiveData(ref NetworkState.NETWORK_STATE_TYPE state)
    {
        CustomClassDataInstance = (CustomClassData)BufferedNetworkUtilsClient.ReadSerializableClass(ref state);

        IntInstance = BufferedNetworkUtilsClient.ReadInt(ref state);

        Vector3Instance = BufferedNetworkUtilsClient.ReadVector3(ref state);

        StringInstance = BufferedNetworkUtilsClient.ReadString(ref state);

        CustomDataInstance = (CustomStructData)BufferedNetworkUtilsClient.ReadStruct(typeof(CustomStructData), ref state);

        ListData = BufferedNetworkUtilsClient.ReadList <InsideCustomData>(ref state);

        DicData = BufferedNetworkUtilsClient.ReadDic <string, Vector3>(ref state);
    }
예제 #2
0
        //反序列化一个可传输的参数
        public static object deserializeOneParameter(ref NetworkState.NETWORK_STATE_TYPE state)
        {
            FduSendableParameter typeCode = (FduSendableParameter)BufferedNetworkUtilsClient.ReadByte(ref state);
            object result;

            switch (typeCode)
            {
            case FduSendableParameter.Int:
                result = BufferedNetworkUtilsClient.ReadInt(ref state);
                break;

            case FduSendableParameter.IntArray:
                result = BufferedNetworkUtilsClient.ReadIntArray(ref state);
                break;

            case FduSendableParameter.Byte:
                result = BufferedNetworkUtilsClient.ReadByte(ref state);
                break;

            case FduSendableParameter.ByteArray:
                result = BufferedNetworkUtilsClient.ReadByteArray(ref state);
                break;

            case FduSendableParameter.Float:
                result = BufferedNetworkUtilsClient.ReadFloat(ref state);
                break;

            case FduSendableParameter.FloatArray:
                result = BufferedNetworkUtilsClient.ReadFloatArray(ref state);
                break;

            case FduSendableParameter.Bool:
                result = BufferedNetworkUtilsClient.ReadBool(ref state);
                break;

            case FduSendableParameter.BoolArray:
                int    bollen = BufferedNetworkUtilsClient.ReadInt(ref state);
                bool[] bolarr = new bool[bollen];
                for (int i = 0; i < bollen; ++i)
                {
                    bolarr[i] = BufferedNetworkUtilsClient.ReadBool(ref state);
                }
                result = bolarr;
                break;

            case FduSendableParameter.String:
                result = BufferedNetworkUtilsClient.ReadString(ref state);
                break;

            case FduSendableParameter.StringArray:

                int      strlen = BufferedNetworkUtilsClient.ReadInt(ref state);
                string[] strarr = new string[strlen];
                for (int i = 0; i < strlen; ++i)
                {
                    strarr[i] = BufferedNetworkUtilsClient.ReadString(ref state);
                }
                result = strarr;
                break;

            case FduSendableParameter.Vector2:
                result = BufferedNetworkUtilsClient.ReadVector2(ref state);
                break;

            case FduSendableParameter.Vector2Array:
                int       v2len = BufferedNetworkUtilsClient.ReadInt(ref state);
                Vector2[] v2arr = new Vector2[v2len];
                for (int i = 0; i < v2len; ++i)
                {
                    v2arr[i] = BufferedNetworkUtilsClient.ReadVector2(ref state);
                }
                result = v2arr;
                break;

            case FduSendableParameter.Vector3:
                result = BufferedNetworkUtilsClient.ReadVector3(ref state);
                break;

            case FduSendableParameter.Vector3Array:
                int       v3len = BufferedNetworkUtilsClient.ReadInt(ref state);
                Vector3[] v3arr = new Vector3[v3len];
                for (int i = 0; i < v3len; ++i)
                {
                    v3arr[i] = BufferedNetworkUtilsClient.ReadVector3(ref state);
                }
                result = v3arr;
                break;

            case FduSendableParameter.Vector4:
                result = BufferedNetworkUtilsClient.ReadVector4(ref state);
                break;

            case FduSendableParameter.Vector4Array:
                int       v4len = BufferedNetworkUtilsClient.ReadInt(ref state);
                Vector4[] v4arr = new Vector4[v4len];
                for (int i = 0; i < v4len; ++i)
                {
                    v4arr[i] = BufferedNetworkUtilsClient.ReadVector4(ref state);
                }
                result = v4arr;
                break;

            case FduSendableParameter.Color:
                result = BufferedNetworkUtilsClient.ReadColor(ref state);
                break;

            case FduSendableParameter.ColorArray:
                int     clen   = BufferedNetworkUtilsClient.ReadInt(ref state);
                Color[] carray = new Color[clen];
                for (int i = 0; i < clen; ++i)
                {
                    carray[i] = BufferedNetworkUtilsClient.ReadColor(ref state);
                }
                result = carray;
                break;

            case FduSendableParameter.Quaternion:
                result = BufferedNetworkUtilsClient.ReadQuaternion(ref state);
                break;

            case FduSendableParameter.QuaternionArray:
                int          qlen = BufferedNetworkUtilsClient.ReadInt(ref state);
                Quaternion[] qarr = new Quaternion[qlen];
                for (int i = 0; i < qlen; i++)
                {
                    qarr[i] = BufferedNetworkUtilsClient.ReadQuaternion(ref state);
                }
                result = qarr;
                break;

            case FduSendableParameter.Matrix4X4:
                result = BufferedNetworkUtilsClient.ReadMatrix4x4(ref state);
                break;

            case FduSendableParameter.Matrix4X4Array:
                int          matlen = BufferedNetworkUtilsClient.ReadInt(ref state);
                Matrix4x4 [] matArr = new Matrix4x4[matlen];
                for (int i = 0; i < matlen; ++i)
                {
                    matArr[i] = BufferedNetworkUtilsClient.ReadMatrix4x4(ref state);
                }
                result = matArr;
                break;

            case FduSendableParameter.Rect:
                result = BufferedNetworkUtilsClient.ReadRect(ref state);
                break;

            case FduSendableParameter.RectArray:
                int    rectlen = BufferedNetworkUtilsClient.ReadInt(ref state);
                Rect[] rectArr = new Rect[rectlen];
                for (int i = 0; i < rectlen; ++i)
                {
                    rectArr[i] = BufferedNetworkUtilsClient.ReadRect(ref state);
                }
                result = rectArr;
                break;

            case FduSendableParameter.GameObject:
                bool goType = BufferedNetworkUtilsClient.ReadBool(ref state);
                if (goType)     //有clusterview的物体
                {
                    var view = FduClusterViewManager.getClusterView(BufferedNetworkUtilsClient.ReadInt(ref state));
                    if (view != null)
                    {
                        result = view.gameObject;
                    }
                    else
                    {
                        result = null;
                    }
                }
                else     //有唯一路径的gameobject
                {
                    string path = BufferedNetworkUtilsClient.ReadString(ref state);
                    result = FduSupportClass.getGameObjectByPath(path);
                }
                break;

            case FduSendableParameter.ClusterView:
                result = FduClusterViewManager.getClusterView(BufferedNetworkUtilsClient.ReadInt(ref state));
                break;

            case FduSendableParameter.Struct:
                try
                {
                    string      typeName = BufferedNetworkUtilsClient.ReadString(ref state);
                    System.Type type     = System.Type.GetType(typeName);
                    result = BufferedNetworkUtilsClient.ReadStruct(type, ref state);
                }
                catch (System.Exception e) { Debug.LogError("Error occured in reading struct data. Details: " + e.Message); throw; }
                break;

            case FduSendableParameter.SerializableClass:
                result = BufferedNetworkUtilsClient.ReadSerializableClass(ref state);
                break;

            case FduSendableParameter.Enum:
                result = BufferedNetworkUtilsClient.ReadInt(ref state);
                break;

            default:
                throw new InvalidSendableDataException("Received unsendable data type, type code:" + typeCode);
            }
            return(result);
        }