Esempio n. 1
0
        public override void Enter()
        {
            base.Enter();
            //playerPos = cubePlayer.transform.position;
            //Vector3 InitPos = playerPos + new Vector3(1, 0, 1);
            RigidBuildInfo info = new RigidBuildInfo
            {
                category    = StageObjectCategory.Dynamic,
                id          = StageManager.instance.GetMaxID(StageObjectCategory.Dynamic) + 1,
                mass        = 50,
                useGravity  = false,
                drag        = 0f,
                angularDrag = 0f,
                prefabName  = "RoadBlock",
                constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ,
                sendFlags   = SendFlag.Position | SendFlag.Rotation | SendFlag.LocalScale,
                //position = InitPos,
                //rotation = Quaternion.identity,
                //initForce = Vector3.zero,
            };

            Vector3 playerPos = cubePlayer.transform.position;
            List <BaseStageObject> objList = new List <BaseStageObject>();

            for (int i = 0; i < 8; i++)
            {
                RigidBuildInfo newInfo = (RigidBuildInfo)info.Clone();
                newInfo.position      = playerPos + initPosList[i];
                newInfo.initForce     = initPosList[i] * 5;
                newInfo.initForceMode = ForceMode.VelocityChange;
                newInfo.id           += i;
                BaseStageObject obj = GameManager.instance.SpawnStageObject(newInfo, BuildType.Server);
                Player.AddPlayerPrefix(obj.gameObject, cubePlayer); //只有服务端名字会改掉,用于标识这是player的所有物
                //obj.transform.parent = cubePlayer.transform; //不能设为player的子物体,不然player转的时候会一起转
                //obj.transform.forward = initPosList[i].normalized;
                objList.Add(obj);
                ServerSend.StageObjectSpawned(newInfo);
            }
            //Rigidbody rig = obj.GetComponent<Rigidbody>();
            GameManager.instance.StartCoroutine(BlockMove(playerPos, objList)); //不这么写的话关掉游戏携程跑不完,那些块块就不会销毁,所以得挂在一个场景中不会被销毁的东西上
            Exit();
        }
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);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void InitClientPlayer(int clientID, string prefabName)
        {
            int          teamID = TeamManager.instance.DistributeOneTeam();
            Team         team   = TeamManager.instance.teams[teamID];
            TeamDescribe desc   = team.GetDescribe();

            if (team.HasNoGoal)
            {
                Goal          goal     = TeamManager.instance.DistributeOneGoal();
                GoalBuildInfo goalInfo = new GoalBuildInfo
                {
                    id       = goal.id > 0 ? goal.id : StageManager.instance.GetMaxID(StageObjectCategory.Goal) + 1,
                    teamID   = team.id,
                    goalName = goal.name,
                    score    = 0
                };
                GameManager.instance.SpawnStageObject(goalInfo, BuildType.Server);
                ServerSend.StageObjectSpawned(goalInfo);
            }

            (Vector3 playerPos, Quaternion playerRot) = Player.GetSpawnInfo(team);
            PlayerBuildInfo info = new PlayerBuildInfo
            {
                id           = clientID,
                prefabName   = prefabName,
                playerType   = "Demo",
                playerName   = Server.clients[clientID].username,
                firstBar     = StageManager.instance.GetMaxID(StageObjectCategory.Dynamic) + 1,
                teamDescribe = desc,
                score        = 0,
                position     = playerPos,
                rotation     = playerRot
            };

            GameManager.instance.SpawnStageObject(info, BuildType.Server);
            ServerSend.StageObjectSpawned(info);
        }