//Only called in matser node 通知一个新的view出现
        public static void NotifyOneNewViewAppear(int assetId, FduClusterView view)
        {
            ClusterGameObjectCreatePara para = new ClusterGameObjectCreatePara(view.ViewId, assetId, view.transform.position, view.transform.rotation);

            if (view.transform.parent != null)
            {
                para.parentPath = FduSupportClass.getGameObjectPath(view.transform.parent.gameObject);
            }
            para.viewInstance = view;
            var subViews = view.getSubViews();

            if (subViews != null)
            {
                for (int i = 0; i < subViews.Count; ++i)
                {
                    if (subViews[i] != null)
                    {
                        if (!subViews[i].gameObject.activeSelf)
                        {
                            subViews[i].ObjectID = FduSyncBaseIDManager.ApplyNextAvaliableId();
                            FduClusterViewManager.RegistToViewManager(subViews[i]);
                        }
                    }
                    else
                    {
                        Debug.LogError("Find Invalid sub view in one FduClusterView.View id :" + view.ViewId + " Object name:" + view.name + ". Please press the Refresh Button in Inspector");
                    }
                }
            }
            if (_waitForCreateList.Count == 0)
            {
                levelPrefix = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
            }
            _waitForCreateList.Add(para);
        }
 public override bool getObservedState(string name)
 {
     if (name == null)
     {
         return(false);
     }
     if (name == null || _ObservedComponent == null)
     {
         return(false);
     }
     if (_ComponentType == null || _props == null)
     {
         Init();
     }
     for (int i = 0; i < _props.Length; ++i)
     {
         if (FduSupportClass.isSendableGenericType(_props[i].PropertyType) && _props[i].CanRead && _props[i].CanWrite)
         {
             if (_props[i].Name.ToUpper().Equals(name))
             {
                 return(_bitArray[i]);
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        public override void OnReceiveData(ref NetworkState.NETWORK_STATE_TYPE state)
        {
            _operationList.Clear();
            int opCount = BufferedNetworkUtilsClient.ReadInt(ref state);

            for (int i = 0; i < opCount; ++i)
            {
                FduParticleSystemOP.Operation operationType = (FduParticleSystemOP.Operation)BufferedNetworkUtilsClient.ReadByte(ref state);
                int paraCount          = BufferedNetworkUtilsClient.ReadInt(ref state);
                FduParticleSystemOP op = new FduParticleSystemOP();
                op.operation = operationType;
                if (paraCount > 0)
                {
                    op.paras = new object[paraCount];
                }
                for (int j = 0; j < paraCount; ++j)
                {
                    op.paras[j] = FduSupportClass.deserializeOneParameter(ref state);
                }
                _operationList.Add(op);
            }
            //反序列化结束 执行每一项粒子系统的操作
            foreach (FduParticleSystemOP op in _operationList)
            {
                op.executeOpOnSlave(particleSys);
            }
            _operationList.Clear();
        }
Exemplo n.º 4
0
 void typeCheck(System.Type type)
 {
     if (!FduSupportClass.isSendableGenericType(type))
     {
         throw new InvalidSendableDataException("[FduClusterCommand]Data must be a struct or string.");
     }
 }
Exemplo n.º 5
0
        //简易的创建函数 不支持被创建物体包含多个子view的情况
        public static GameObject createGameObjectWithClusterView(int viewId, int AssetId, Vector3 position, Quaternion rotation, string parentPath)
        {
            GameObject go = FduClusterAssetManager.Instance.getGameObjectFromId(AssetId);

            if (go == null)
            {
                return(null);
            }

            GameObject parent = FduSupportClass.getGameObjectByPath(parentPath);
            GameObject instance;

            if (parent == null)
            {
                instance = GameObject.Instantiate(go, position, rotation);
            }
            else
            {
                instance = GameObject.Instantiate(go, position, rotation, parent.transform);
            }



            if (instance.GetComponent <FduClusterView>() != null)
            {
                instance.GetComponent <FduClusterView>().ObjectID = viewId;
                FduSyncBaseIDManager.ReceiveIdFromMaster(viewId);
            }
            return(instance);
        }
        public override bool setObservedState(string name, bool value)
        {
#if !UNSAFE_MODE
            if (name == null || _ObservedComponent == null)
            {
                return(false);
            }
            if (_ComponentType == null || _props == null)
            {
                Init();
            }
            for (int i = 0; i < _props.Length; ++i)
            {
                if (FduSupportClass.isSendableGenericType(_props[i].PropertyType) && _props[i].CanRead && _props[i].CanWrite)
                {
                    if (_props[i].Name.ToUpper().Equals(name.ToUpper()))
                    {
                        _bitArray[i] = value;
                        return(true);
                    }
                }
            }
            return(false);
#else
            Debug.LogWarning("You can not use setObservedState method in unsafe mode!");
            return(false);
#endif
        }
Exemplo n.º 7
0
 internal void SerializeParameterData()
 {
     Dictionary <string, object> .Enumerator enumerator = _paraMap.GetEnumerator();
     BufferedNetworkUtilsServer.SendString(_CommandName); //Name of Command
     BufferedNetworkUtilsServer.SendInt(_paraMap.Count);  //Count of Command parameters
     while (enumerator.MoveNext())
     {
         BufferedNetworkUtilsServer.SendString(enumerator.Current.Key);   //parameter name
         FduSupportClass.serializeOneParameter(enumerator.Current.Value); //parameter value
     }
 }
Exemplo n.º 8
0
        internal void DeserializeParameterData(ref NetworkState.NETWORK_STATE_TYPE state)
        {
            _CommandName = BufferedNetworkUtilsClient.ReadString(ref state);    //Name of Command
            int parameterCount = BufferedNetworkUtilsClient.ReadInt(ref state); //Count of Command parameters

            for (int j = 0; j < parameterCount; ++j)
            {
                string paraName = BufferedNetworkUtilsClient.ReadString(ref state);   //Name of parameter
                object para     = FduSupportClass.deserializeOneParameter(ref state); //Value of parameter
                addParameter(paraName, para);
            }
        }
Exemplo n.º 9
0
        //创建函数 para包含了所有创建该物体所必须的参数 包括位置信息、父节点信息、子节点信息等等
        public static GameObject createGameObjectWithClusterView(FduClusterViewManager.ClusterGameObjectCreatePara para)
        {
            GameObject go = FduClusterAssetManager.Instance.getGameObjectFromId(para.assetId);

            if (go == null)
            {
                return(null);
            }

            GameObject parent = FduSupportClass.getGameObjectByPath(para.parentPath);
            GameObject instance;

            if (parent == null)
            {
                instance = GameObject.Instantiate(go, para.position, para.rotation);
            }
            else
            {
                instance = GameObject.Instantiate(go, para.position, para.rotation, parent.transform);
            }

            FduClusterView view = instance.GetComponent <FduClusterView>();

            if (view != null)
            {
                view.ObjectID = para.viewId;
                FduSyncBaseIDManager.ReceiveIdFromMaster(para.viewId);
            }

            var subViewList = instance.GetClusterView().getSubViews();
            int index       = 0;

            foreach (FduClusterView subView in subViewList)
            {
                if (subView != null)
                {
                    subView.ObjectID = para.subViewId[index++];
                    FduSyncBaseIDManager.ReceiveIdFromMaster(subView.ViewId);
                }
                else
                {
                    Debug.LogError("Find Invalid sub view in one FduClusterView.View id :" + view.ViewId + " Object name:" + view.name + ". Please press the Refresh Button in Inspector");
                }
            }
            if (index != subViewList.Count)
            {
                Debug.LogError("[FduClusterGameObjectCreator]Sub View Count Not matched!");
            }

            return(instance);
        }
Exemplo n.º 10
0
        //将rpc事件中的各项参数都序列化发出去
        void serializeParameters()
        {
            BufferedNetworkUtilsServer.SendInt((int)_rpcData[(byte)0]);
            BufferedNetworkUtilsServer.SendString((string)_rpcData[(byte)1]);
            int paraCount = ((int)_rpcData[(byte)2]);

            BufferedNetworkUtilsServer.SendInt(paraCount);
            object[] parameters = (object[])_rpcData[(byte)3];
            try
            {
                for (int i = 0; i < paraCount; ++i)
                {
                    FduSupportClass.serializeOneParameter(parameters[i]);
                }
            }
            catch (InvalidSendableDataException e)
            {
                Debug.LogError(e.Message);
            }
        }
Exemplo n.º 11
0
 public override void OnSendData()
 {
     BufferedNetworkUtilsServer.SendInt(_operationList.Count);
     foreach (FduParticleSystemOP op in _operationList)
     {
         BufferedNetworkUtilsServer.SendByte((byte)op.operation);
         if (op.paras != null)
         {
             BufferedNetworkUtilsServer.SendInt(op.paras.Length);
             for (int i = 0; i < op.paras.Length; ++i)
             {
                 FduSupportClass.serializeOneParameter(op.paras[i]);
             }
         }
         else
         {
             BufferedNetworkUtilsServer.SendInt(0);
         }
     }
     _operationList.Clear();
 }
Exemplo n.º 12
0
        //接收到rpc事件中的数据 反序列化为可用的事件实例
        void deserializeParameters(ref NetworkState.NETWORK_STATE_TYPE state)
        {
            _rpcData.Clear();
            _rpcData.Add((byte)0, BufferedNetworkUtilsClient.ReadInt(ref state));
            _rpcData.Add((byte)1, BufferedNetworkUtilsClient.ReadString(ref state));
            int paraCount = BufferedNetworkUtilsClient.ReadInt(ref state);

            _rpcData.Add((byte)2, paraCount);
            object[] parameters = new object[paraCount];
            try
            {
                for (int i = 0; i < paraCount; ++i)
                {
                    object ob = FduSupportClass.deserializeOneParameter(ref state);
                    parameters[i] = ob;
                }
            }
            catch (InvalidSendableDataException e)
            {
                Debug.LogError(e.Message);
                return;
            }
            _rpcData.Add((byte)3, (object[])parameters);
        }
Exemplo n.º 13
0
        void switchCaseFunc(FduMultiAttributeObserverOP op, ref NetworkState.NETWORK_STATE_TYPE state)
        {
            for (int i = 1; i < attributeList.Length; ++i)
            {
                if (!getObservedState(i)) //如果editor中没有选择监控该属性 则直接跳过
                {
                    continue;
                }

                switch (i)
                {
                case 1:    //position
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.position = FduInterpolationInterface.getNextVector3Value_new(_transform.position, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendVector3(_transform.position);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.position = BufferedNetworkUtilsClient.ReadVector3(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state));
                    }
                    break;

                case 2:    //rotation
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.rotation = FduInterpolationInterface.getNextQuaternionValue_new(_transform.rotation, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendQuaternion(_transform.rotation);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.rotation = BufferedNetworkUtilsClient.ReadQuaternion(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadQuaternion(ref state));
                    }
                    break;

                case 3:    //scale
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.localScale = FduInterpolationInterface.getNextVector3Value_new(_transform.localScale, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendVector3(_transform.localScale);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.localScale = BufferedNetworkUtilsClient.ReadVector3(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state));
                    }
                    break;

                case 4:    //parent: 对于父节点的监控 这里只是一个不完全的解决方案 获取到父节点的路径 传输过去 然后在从节点解析。如果路径不唯一(因为可以同名)就会找不到对于的父节点
                    if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        string parentPath;
                        if (_transform.parent == null)
                        {
                            parentPath = "";
                        }
                        else
                        {
                            parentPath = FduSupportClass.getGameObjectPath(_transform.parent.gameObject);
                        }

                        if (parentPath == null)
                        {
                            parentPath = "";
                        }
                        BufferedNetworkUtilsServer.SendString(parentPath);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct || op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        string parentPath;
                        if (_transform.parent == null)
                        {
                            parentPath = "";
                        }
                        else
                        {
                            parentPath = FduSupportClass.getGameObjectPath(_transform.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)
                            {
                                _transform.SetParent(null);
                            }
                            else
                            {
                                _transform.SetParent(go.transform);
                            }
                        }
                    }
                    break;

                case 5:    //LocalPosition
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.localPosition = FduInterpolationInterface.getNextVector3Value_new(_transform.localPosition, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendVector3(_transform.localPosition);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.localPosition = BufferedNetworkUtilsClient.ReadVector3(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state));
                    }
                    break;

                case 6:    //LocalRotation;
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.localRotation = FduInterpolationInterface.getNextQuaternionValue_new(_transform.localRotation, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendQuaternion(_transform.localRotation);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.localRotation = BufferedNetworkUtilsClient.ReadQuaternion(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadQuaternion(ref state));
                    }
                    break;

                case 7:    //LocalScale
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.localScale = FduInterpolationInterface.getNextVector3Value_new(_transform.localScale, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendVector3(_transform.localScale);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.localScale = BufferedNetworkUtilsClient.ReadVector3(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state));
                    }
                    break;

                case 8:    //EulerAngle
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.eulerAngles = FduInterpolationInterface.getNextVector3Value_new(_transform.eulerAngles, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendVector3(_transform.eulerAngles);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.eulerAngles = BufferedNetworkUtilsClient.ReadVector3(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state));
                    }
                    break;

                case 9:    //LocalEulerAngle
                    if (op == FduMultiAttributeObserverOP.Update)
                    {
                        if (getCachedProperytyCount(i) > 0)
                        {
                            _transform.localEulerAngles = FduInterpolationInterface.getNextVector3Value_new(_transform.localEulerAngles, i, this);
                        }
                    }
                    else if (op == FduMultiAttributeObserverOP.SendData)
                    {
                        BufferedNetworkUtilsServer.SendVector3(_transform.localEulerAngles);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Direct)
                    {
                        _transform.localEulerAngles = BufferedNetworkUtilsClient.ReadVector3(ref state);
                    }
                    else if (op == FduMultiAttributeObserverOP.Receive_Interpolation)
                    {
                        setCachedProperty_append(i, BufferedNetworkUtilsClient.ReadVector3(ref state));
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 14
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:     //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;
                }
            }
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
            }
        }