public virtual void Serialize() { if (_mouseState != null) { _mouseState.buttonStateList.ForEach(buttonState_ => { BufferedNetworkUtilsServer.SendInt((int)buttonState_.button); BufferedNetworkUtilsServer.SendVector2(buttonState_.position); BufferedNetworkUtilsServer.SendVector2(buttonState_.delta); BufferedNetworkUtilsServer.SendVector2(buttonState_.scrollDelta); BufferedNetworkUtilsServer.SendInt((int)buttonState_.buttonState); }); } }
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: //AnchoredPosition if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.anchoredPosition = FduInterpolationInterface.getNextVector2Value_new(rectTransform.anchoredPosition, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.anchoredPosition); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.anchoredPosition = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; case 2: //AnchoredPosition3D if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.anchoredPosition3D = FduInterpolationInterface.getNextVector3Value_new(rectTransform.anchoredPosition3D, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector3(rectTransform.anchoredPosition3D); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.anchoredPosition3D = BufferedNetworkUtilsClient.ReadVector3(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state)); } break; case 3: //Rotation if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.rotation = FduInterpolationInterface.getNextQuaternionValue_new(rectTransform.rotation, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendQuaternion(rectTransform.rotation); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.rotation = BufferedNetworkUtilsClient.ReadQuaternion(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadQuaternion(ref state)); } break; case 4: //Scale if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.localScale = FduInterpolationInterface.getNextVector3Value_new(rectTransform.localScale, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector3(rectTransform.localScale); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.localScale = BufferedNetworkUtilsClient.ReadVector3(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state)); } break; case 5: //Parent if (op == FduMultiAttributeObserverOP.SendData) { string parentPath; if (rectTransform.parent == null) { parentPath = ""; } else { parentPath = FduSupportClass.getGameObjectPath(rectTransform.parent.gameObject); } if (parentPath == null) { parentPath = ""; } BufferedNetworkUtilsServer.SendString(parentPath); } else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation) { string parentPath; if (rectTransform.parent == null) { parentPath = ""; } else { parentPath = FduSupportClass.getGameObjectPath(rectTransform.parent.gameObject); } if (parentPath == null) { parentPath = ""; } string getPath = BufferedNetworkUtilsClient.ReadString(ref state); if (parentPath != getPath) //hierarchy changed { GameObject go = FduSupportClass.getGameObjectByPath(getPath); if (go == null) { rectTransform.SetParent(null); } else { rectTransform.SetParent(go.transform); } } } break; case 6: //AnchorMax if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.anchorMax = FduInterpolationInterface.getNextVector2Value_new(rectTransform.anchorMax, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.anchorMax); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.anchorMax = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; case 7: //AnchorMin if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.anchorMin = FduInterpolationInterface.getNextVector2Value_new(rectTransform.anchorMin, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.anchorMin); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.anchorMin = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; case 8: //OffsetMax if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.offsetMax = FduInterpolationInterface.getNextVector2Value_new(rectTransform.offsetMax, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.offsetMax); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.offsetMax = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; case 9: //OffsetMin if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.offsetMin = FduInterpolationInterface.getNextVector2Value_new(rectTransform.offsetMin, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.offsetMin); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.offsetMin = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; case 10: //Pivot if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.pivot = FduInterpolationInterface.getNextVector2Value_new(rectTransform.pivot, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.pivot); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.pivot = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; case 11: //SizeDelta if (op == FduMultiAttributeObserverOP.Update) { if (getCachedProperytyCount(i) > 0) { rectTransform.sizeDelta = FduInterpolationInterface.getNextVector2Value_new(rectTransform.sizeDelta, i, this); } } else if (op == FduMultiAttributeObserverOP.SendData) { BufferedNetworkUtilsServer.SendVector2(rectTransform.sizeDelta); } else if (op == FduMultiAttributeObserverOP.Receive_Direct) { rectTransform.sizeDelta = BufferedNetworkUtilsClient.ReadVector2(ref state); } else if (op == FduMultiAttributeObserverOP.Receive_Interpolation) { setCachedProperty(i, BufferedNetworkUtilsClient.ReadVector2(ref state)); } break; } } }
//序列化一个可传送的参数 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); } }