void DeserializeOnePara(byte propertyType, Material mat, string propertyName, ref NetworkState.NETWORK_STATE_TYPE state)
        {
            switch (propertyType)
            {
            case 0:    //Color
                mat.SetColor(propertyName, BufferedNetworkUtilsClient.ReadColor(ref state));
                break;

            case 1:    //Vector
                mat.SetVector(propertyName, BufferedNetworkUtilsClient.ReadVector4(ref state));
                break;

            case 2:    //Float
                mat.SetFloat(propertyName, BufferedNetworkUtilsClient.ReadFloat(ref state));
                break;

            case 3:    //Range
                mat.SetFloat(propertyName, BufferedNetworkUtilsClient.ReadFloat(ref state));
                break;

            case 4:    //TexEnv
                break;
            }
        }
Exemple #2
0
        void switchCaseFunc(FduMultiAttributeObserverOP op, ref NetworkState.NETWORK_STATE_TYPE state)
        {
            for (int i = 1; i < attrList.Length; ++i)
            {
                if (!getObservedState(i))
                {
                    continue;
                }
                switch (i)
                {
                case 1:    //Color
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            image.color = FduInterpolationInterface.getNextColorValue_new(image.color, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendColor(image.color);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        image.color = BufferedNetworkUtilsClient.ReadColor(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadColor(ref state));
                    }
                    break;

                case 2:    //RaycastTarget
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(image.raycastTarget);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        image.raycastTarget = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 3:    //FillMethod
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendByte((byte)image.fillMethod);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        image.fillMethod = (Image.FillMethod)BufferedNetworkUtilsClient.ReadByte(ref state);
                    }
                    break;

                case 4:    //FillAmount
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            image.fillAmount = FduInterpolationInterface.getNextFloatValue_new(image.fillAmount, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendFloat(image.fillAmount);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        image.fillAmount = BufferedNetworkUtilsClient.ReadFloat(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadFloat(ref state));
                    }
                    break;

                case 5:    //FillCenter
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(image.fillCenter);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        image.fillCenter = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 6:    //FillClockwise
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(image.fillClockwise);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        image.fillClockwise = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 7:    //FillOrigin
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            image.fillOrigin = FduInterpolationInterface.getNextIntValue_new(image.fillOrigin, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendInt(image.fillOrigin);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        image.fillOrigin = BufferedNetworkUtilsClient.ReadInt(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadInt(ref state));
                    }
                    break;

                case 8:    //ImageType
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendByte((byte)image.type);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        image.type = (Image.Type)BufferedNetworkUtilsClient.ReadByte(ref state);
                    }
                    break;

                case 9:    //Image
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        bool changeFlag = false;
                        if (image.sprite != null && image.sprite.GetInstanceID() != spriteId)
                        {     //通过对比InstanceId判断该精灵是否被替换
                            changeFlag = true;
                            spriteId   = image.sprite.GetInstanceID();
                        }

                        BufferedNetworkUtilsServer.SendBool(changeFlag);
                        if (changeFlag)    //若已经变化了 则将图片分解为JPG格式传送至节点
                        {
                            byte[] arr;
                            try
                            {
                                arr = image.sprite.texture.EncodeToJPG();
                                BufferedNetworkUtilsServer.SendByteArray(arr);
                                BufferedNetworkUtilsServer.SendRect(image.sprite.textureRect);
                                BufferedNetworkUtilsServer.SendVector2(image.sprite.pivot);
                            }
                            catch (System.Exception e)
                            {
                                Debug.LogError(e.Message);
                            }
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)     //从节点先判断有没有图片传来 然后再解析
                    {
                        bool changeFlag = BufferedNetworkUtilsClient.ReadBool(ref state);
                        if (changeFlag)
                        {
                            byte[]    bytes   = BufferedNetworkUtilsClient.ReadByteArray(ref state);
                            Rect      rect    = BufferedNetworkUtilsClient.ReadRect(ref state);
                            Vector2   pivot   = BufferedNetworkUtilsClient.ReadVector2(ref state);
                            Texture2D texture = new Texture2D((int)GetComponent <RectTransform>().rect.width, (int)GetComponent <RectTransform>().rect.height);
                            texture.LoadImage(bytes);
                            image.sprite = Sprite.Create(texture, rect, pivot);
                        }
                    }
                    break;
                }
            }
        }
        void switchCaseFunc(FduMultiAttributeObserverOP op, ref NetworkState.NETWORK_STATE_TYPE state)
        {
            for (int i = 1; i < attrList.Length; ++i)
            {
                if (!getObservedState(i))
                {
                    continue;
                }
                switch (i)
                {
                case 1:     //TextContent
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendString(text.text);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.text = BufferedNetworkUtilsClient.ReadString(ref state);
                    }
                    break;

                case 2:    //Color
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            text.color = FduInterpolationInterface.getNextColorValue_new(text.color, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendColor(text.color);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        text.color = BufferedNetworkUtilsClient.ReadColor(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadColor(ref state));
                    }
                    break;

                case 3:     //FontStyle
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendByte((byte)text.fontStyle);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.fontStyle = (FontStyle)BufferedNetworkUtilsClient.ReadByte(ref state);
                    }
                    break;

                case 4:    //FontSize
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            text.fontSize = FduInterpolationInterface.getNextIntValue_new(text.fontSize, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendInt(text.fontSize);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        text.fontSize = BufferedNetworkUtilsClient.ReadInt(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty(i, BufferedNetworkUtilsClient.ReadInt(ref state));
                    }
                    break;

                case 5:    //LineSpacing
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            text.lineSpacing = FduInterpolationInterface.getNextFloatValue_new(text.lineSpacing, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendFloat(text.lineSpacing);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        text.lineSpacing = BufferedNetworkUtilsClient.ReadFloat(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty(i, BufferedNetworkUtilsClient.ReadFloat(ref state));
                    }
                    break;

                case 6:    //SupportRichText
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(text.supportRichText);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.supportRichText = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 7:    //Aligment
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendByte((byte)text.alignment);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.alignment = (TextAnchor)BufferedNetworkUtilsClient.ReadByte(ref state);
                    }
                    break;

                case 8:    //AlignByGeometry
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(text.alignByGeometry);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.alignByGeometry = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 9:    //HorizontalOverflow
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendByte((byte)text.horizontalOverflow);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.horizontalOverflow = (HorizontalWrapMode)BufferedNetworkUtilsClient.ReadByte(ref state);
                    }
                    break;

                case 10:    //VerticalOverflow
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendByte((byte)text.verticalOverflow);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.verticalOverflow = (VerticalWrapMode)BufferedNetworkUtilsClient.ReadByte(ref state);
                    }
                    break;

                case 11:    //BestFit
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(text.resizeTextForBestFit);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.resizeTextForBestFit = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 12:    //RaycastTarget
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendBool(text.raycastTarget);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        text.raycastTarget = BufferedNetworkUtilsClient.ReadBool(ref state);
                    }
                    break;

                case 31:    //Interpolation Option
                    break;
                }
            }
        }
Exemple #4
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);
        }