Esempio n. 1
0
        //根据rpc数据执行对应的rpc方法
        public object executeRpc(Dictionary <byte, object> rpcdata)
        {
            object returnValue = null;
            int    viewId      = (int)rpcdata[(byte)0];
            string methodName  = (string)rpcdata[(byte)1];
            int    paraCount   = (int)rpcdata[(byte)2];

            object[] parameters = (object[])rpcdata[(byte)3];

            FduClusterView view = FduClusterViewManager.getClusterView(viewId);

            if (view == null)
            {
                Debug.LogWarning("[FduRpc]FduSyncView not exist .View id is " + viewId + " method Name is " + methodName);
                return(returnValue);
            }

            bool isSent = false;

            List <FduObserverBase> .Enumerator observerEnum = view.getObservers();

            var monos = view.GetComponents <MonoBehaviour>();
            HashSet <MonoBehaviour> monoset = new HashSet <MonoBehaviour>(monos);

            while (observerEnum.MoveNext())
            {
                monoset.Add(observerEnum.Current);
            }
            foreach (MonoBehaviour mono in monoset)
            {
                List <MethodInfo> methodInfo = GetMethods(mono.GetType(), typeof(FduRPC));
                if (methodInfo == null)
                {
                    return(returnValue);
                }
                Type[] argTypes = new Type[paraCount];
                for (int i = 0; i < paraCount; i++)
                {
                    argTypes[i] = parameters[i].GetType();
                }

                for (int i = 0; i < methodInfo.Count; ++i)
                {
                    MethodInfo mi = methodInfo[i];
                    if (mi.Name.Equals(methodName))
                    {
                        ParameterInfo[] paraInfo = mi.GetParameters();
                        if (paraInfo.Length == parameters.Length)
                        {
                            if (this.CheckTypeMatch(paraInfo, argTypes))
                            {
                                if (!isSent)
                                {
                                    returnValue = mi.Invoke((object)mono, parameters);
                                    isSent      = true;
                                }
                                else
                                {
                                    Debug.LogWarning("[FduRpc]More than one function can match the method name and parameters. Please check.");
                                }
                            }
                        }
                    }
                }
            }
            if (!isSent)
            {
                Debug.LogWarning("[FduRpc]Parameters not matched for FduRpc Call. Method Name:" + methodName);
            }
            return(returnValue);
        }
        public override NetworkState.NETWORK_STATE_TYPE Deserialize()
        {
            NetworkState.NETWORK_STATE_TYPE state = NetworkState.NETWORK_STATE_TYPE.SUCCESS;

            //active部分数据
            int count = BufferedNetworkUtilsClient.ReadInt(ref state);
            int viewId, obCount; FduClusterView view;
            int obId, obFrameCount;

            for (int i = 0; i < count; ++i)
            {
                viewId  = BufferedNetworkUtilsClient.ReadInt(ref state);
                obCount = BufferedNetworkUtilsClient.ReadInt(ref state);
                view    = FduClusterViewManager.getClusterView(viewId);
                if (view != null)
                {
                    try
                    {
                        for (int j = 0; j < obCount; ++j)
                        {
                            obId         = BufferedNetworkUtilsClient.ReadInt(ref state);
                            obFrameCount = BufferedNetworkUtilsClient.ReadInt(ref state);
                            view.setFrameCountForEveryNFrameDTS(obId, obFrameCount);
                        }
                        view.gameObject.SetActive(true);
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
                else
                {
                    //view是空的也要读完
                    for (int j = 0; j < obCount; ++j)
                    {
                        obId         = BufferedNetworkUtilsClient.ReadInt(ref state);
                        obFrameCount = BufferedNetworkUtilsClient.ReadInt(ref state);
                    }
                    Debug.LogWarning("[FduActiveSyncManager-active]Can not find a view with ViewId " + viewId);
                }
            }
            //Inactive部分数据
            count = BufferedNetworkUtilsClient.ReadInt(ref state);
            for (int i = 0; i < count; ++i)
            {
                viewId  = BufferedNetworkUtilsClient.ReadInt(ref state);
                obCount = BufferedNetworkUtilsClient.ReadInt(ref state);
                view    = FduClusterViewManager.getClusterView(viewId);
                if (view != null)
                {
                    try
                    {
                        for (int j = 0; j < obCount; ++j)
                        {
                            obId         = BufferedNetworkUtilsClient.ReadInt(ref state);
                            obFrameCount = BufferedNetworkUtilsClient.ReadInt(ref state);
                            view.setFrameCountForEveryNFrameDTS(obId, obFrameCount);
                        }
                        view.gameObject.SetActive(false);
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
                else
                {
                    //view是空的也要读完
                    for (int j = 0; j < obCount; ++j)
                    {
                        obId         = BufferedNetworkUtilsClient.ReadInt(ref state);
                        obFrameCount = BufferedNetworkUtilsClient.ReadInt(ref state);
                    }
                    Debug.LogWarning("[FduActiveSyncManager-Inactive]Can not find a view with ViewId " + viewId);
                }
            }
            if (BufferedNetworkUtilsClient.ReadString(ref state) != "FduActieSyncManagerEndFlag")
            {
                Debug.LogError("Wrong end of FduActiveSyncManager!");
            }
            return(state);
        }
Esempio n. 3
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);
        }