Esempio n. 1
0
        public static void UpdateMain()
        {
            List <Vector3Holder>    posList        = ReleaseList(positionBuffer);
            List <QuaternionHolder> rotList        = ReleaseList(rotationBuffer);
            List <Vector3Holder>    localPosList   = ReleaseList(localPositionBuffer);
            List <QuaternionHolder> localRotList   = ReleaseList(localRotationBuffer);
            List <Vector3Holder>    localScaleList = ReleaseList(localScaleBuffer);

            if (posList != null)
            {
                ServerSend.StageObjectPositions(posList);
            }
            if (rotList != null)
            {
                ServerSend.StageObjectRotations(rotList);
            }
            if (localPosList != null)
            {
                ServerSend.StageObjectLocalPositions(localPosList);
            }
            if (localRotList != null)
            {
                ServerSend.StageObjectLocalRotations(localRotList);
            }
            if (localScaleList != null)
            {
                ServerSend.StageObjectLocalScales(localScaleList);
            }
        }
Esempio n. 2
0
        public static void StageSynchronize(int clientID, List <StageObjectPair> clientObjs)
        {
            Debug.Log($"收到了 客户端{clientID} 发来的场景同步请求");
            List <StageObjectPair> serverObjs = StageManager.instance.GetStageObjectPairs(new List <StageObjectPair> {
                new StageObjectPair {
                    category = StageObjectCategory.Player, id = clientID
                }
            }); //得到除去该客户端Player以外的元素
            IEnumerable <StageObjectPair> intersection = serverObjs.Intersect(clientObjs);
            IEnumerable <StageObjectPair> serverOnly   = serverObjs.Except(intersection);
            IEnumerable <StageObjectPair> clientOnly   = clientObjs.Except(intersection);

            Debug.Log($"当前:{serverObjs.Count},客户端:{clientObjs.Count},交集:{intersection.Count()},服务器独有:{serverOnly.Count()},客户端独有:{clientOnly.Count()}");
            List <Vector3Holder>    posList = new List <Vector3Holder>();
            List <QuaternionHolder> rotList = new List <QuaternionHolder>();

            foreach (StageObjectPair pair in intersection)
            {
                BaseStageObject obj = StageManager.instance.GetStageObject(pair.category, pair.id);
                posList.Add(new Vector3Holder {
                    category = pair.category, id = pair.id, vect = obj.transform.position
                });
                rotList.Add(new QuaternionHolder {
                    category = pair.category, id = pair.id, quat = obj.transform.rotation
                });
            }
            ServerSend.StageObjectPositions(clientID, posList);
            ServerSend.StageObjectRotations(clientID, rotList);
            ServerSend.StageObjectDespawned(clientID, clientOnly.ToList());
            foreach (StageObjectPair pair in serverOnly)
            {
                BaseStageObject obj = StageManager.instance.GetStageObject(pair.category, pair.id);
                if (obj.builder != null)
                {
                    BaseBuildInfo info = obj.builder.GenerateBuildInfo(obj);
                    if (info != null)
                    {
                        ServerSend.StageObjectSpawned(clientID, info);
                    }
                }
            }
        }