/* * private void TimeCount() * { * timeUse += Time.deltaTime; * } */ IEnumerator BlockMove(Vector3 playerPos, List <BaseStageObject> objList) { float timeUse = 0; Vector3 originScale = objList[0].transform.localScale; while (timeUse < 4) { /* * for (int i = 0; i < 8; i++) * { * //objList[i].transform.position = Vector3.MoveTowards(objList[i].transform.position, playerPos + endPosList[i], 10 * Time.fixedDeltaTime); * objList[i].transform.position += objList[i].transform.forward * blockSpeedFactor; * //objList[i].transform.Translate(objList[i].transform.forward * blockSpeedFactor); * //Debug.Log("大招位置:" + objList[0].transform.position + "判定位置:" + playerPos + endPosList[0] + "距离:" + Vector3.Distance(objList[0].transform.position, playerPos + endPosList[0])); * } */ timeUse += Time.fixedDeltaTime; for (int i = 0; i < 8; i++) { objList[i].SetLocalScale(originScale + Vector3.one * timeUse / 2.0f); } yield return(new WaitForFixedUpdate()); } List <StageObjectPair> despawnObjList = new List <StageObjectPair>(); for (int i = 0; i < 8; i++) { GameManager.instance.DespawnStageObject(objList[i].category, objList[i].id); despawnObjList.Add(new StageObjectPair { category = objList[i].category, id = objList[i].id }); } ServerSend.StageObjectDespawned(despawnObjList); Debug.Log($"大招结束,用时{timeUse}"); }
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); } } } }
public static void PlayerDisconnected(int playerID) { BaseStageObject obj = StageManager.instance.GetStageObject(StageObjectCategory.Player, playerID); if (obj) { Player player = (Player)obj; int score = player.Score; TeamManager.instance.RemoveFromTeam(player); ServerSend.TeamLeft(playerID, score); List <StageObjectPair> bars = new List <StageObjectPair>(); player.barList.ForEach((Bar bar) => { bars.Add(new StageObjectPair { category = bar.category, id = bar.id }); StageManager.instance.RemoveStageObject(bar.category, bar.id); }); ServerSend.StageObjectRemoved(bars); GameManager.instance.DespawnStageObject(StageObjectCategory.Player, playerID); ServerSend.StageObjectDespawned(StageObjectCategory.Player, playerID); } }