public void Start(bool replay = false, string recordName = "") { //----------------------------------- //本地帧同步开始 LocalFrameSynServer.Start(); //----------------------------------- //监听事件 RegistEvent(); //初始化数据 fsData = new FrameSynchronData(1000) { //初始为暂停状态 PauseState = true }; //回放 if (replay) { fsData.ReplayState = true; LoadBattleData(recordName); } //初始化帧同步逻辑对象 LockStep = new LockStep(fsData); //游戏运行速度 GTime.TimeScale = 1; isStart = true; }
public void FixedUpdate() { if (fsData.PauseState) { return; } LockStep.FixedUpdate(); }
public BattleSystem() { battleData = new BattleData(); lockStep = new LockStep(); sceneManager = new SceneManager(battleData); battleController = null; pvpBattleController = new PVPBattleController(battleData, this); singleBattleController = new SingleBattleController(battleData, this); }
void Start() { _PhysicalSystem.Open(); _UnityUdpSocket.Open(); mFrameData = new FrameData(); mLockStep = gameObject.AddComponent <LockStep>(); for (int i = 0; i < NetData.Instance.mFightData.PlayerHeroInfoList.Count; i++) { PlayerHeroInfo info = NetData.Instance.mFightData.PlayerHeroInfoList[i]; uint userid = info.userid; uint heroid = info.heroid; GameObject actorobj = _AssetManager.GetGameObject("prefab/hero/yase/yase_prefab"); Actor actor; if (userid == NetData.Instance.mUserData.Userid) { actor = actorobj.AddComponent <PlayerActor>(); } else { actor = actorobj.AddComponent <RoleActor>(); } if (mActorParent == null) { mActorParent = GameObject.Find("ActorParent").transform; } actor.transform.parent = mActorParent; actor.Position = new CustomVector3(0, 0, 0); actor.Speed = new FixedPointF(300, 100); actor.Angle = 0; actor.Id = userid; AddActor(userid, actor); } _UnityUdpSocket.Connect(); }
void Start() { instance = this; Application.runInBackground = true; ICommunicator communicator = null; //初始化通信 //if (!PhotonNetwork.connected || !PhotonNetwork.inRoom) { // Debug.LogWarning("You are not connected to Photon. TrueSync will start in offline mode."); //} else { // communicator = new PhotonTrueSyncCommunicator(PhotonNetwork.networkingPeer); //} TrueSyncConfig activeConfig = ActiveConfig; //创建lockstep lockstep = AbstractLockstep.NewInstance( lockedTimeStep.AsFloat(), communicator, PhysicsManager.instance, activeConfig.syncWindow, activeConfig.panicWindow, activeConfig.rollbackWindow, OnGameStarted, OnGamePaused, OnGameUnPaused, OnGameEnded, OnPlayerDisconnection, OnStepUpdate, ProvideInputData ); //========================================================================== mFrameData = new FrameData(); mLockStep = gameObject.AddComponent <LockStep>(); gameObject.AddComponent <GameProcessManager_Dota>(); gameObject.AddComponent <MyTimerDriver>(); PB_MatchTeamFight_FMS2GS2C mMatchTeamFight = (PB_MatchTeamFight_FMS2GS2C)NetData.Instance.Query(MsgID.S2CMatch, (uint)MatchMsgID.Fms2Gs2CMatchFight); FRS2C_Host = mMatchTeamFight.Frs2Chost; FRS2C_Port = mMatchTeamFight.Frs2Cport; guanqia = mMatchTeamFight.Guanqia; teamid = mMatchTeamFight.Teamid; fightroomid = mMatchTeamFight.Fightroomid; randomseed = mMatchTeamFight.Seed; fps = mMatchTeamFight.Fps; foreach (PB_FightPlayerInfo mFightPlayerInfo in mMatchTeamFight.Playersdata) { GameObject actorobj; Actor actor; if (mFightPlayerInfo.ChooseHero == 1) { actorobj = _AssetManager.GetGameObject("prefab/hero/yase/yase_prefab"); actor = actorobj.GetComponent <PlayerActor_yase>(); } else { actorobj = _AssetManager.GetGameObject("prefab/hero/houyi/houyi_prefab"); actor = actorobj.GetComponent <PlayerActor_houyi>(); } //actor.ownerIndex =(int) mFightPlayerInfo.Playeridx; if (mFightPlayerInfo.Pid == NetData.Instance.PlayerID) { actor.IsETCControl = true; playeridx = mFightPlayerInfo.Playeridx; hellokey = mFightPlayerInfo.Hellokey; //actor.localOwner = new TSPlayerInfo((byte)mFightPlayerInfo.Pid, mFightPlayerInfo.Name); } else { actor.IsETCControl = false; //actor.owner = new TSPlayerInfo((byte)mFightPlayerInfo.Pid, mFightPlayerInfo.Name); } if (mActorParent == null) { mActorParent = GameObject.Find("ActorParent").transform; } actor.transform.parent = mActorParent; //actor.Position = new CustomVector3(0, 0, 0); actor.Speed = (FP)0.1f; actor.mActorAttr.HpMax = (FP)100; actor.mActorAttr.Hp = (FP)50; actor.mActorAttr.Name = mFightPlayerInfo.Name; actor.RotateTSTransform.LookAt(TSVector.left); actor.AllTSTransform.LookAt(TSVector.left); actor.Angle = new TSVector(); actor.OwnerID = mFightPlayerInfo.Playeridx; if (actor.OwnerID % 2 == 0) //临时的阵营分配规则 { actor.OwnerCamp = GameCamp.BLUE; } else { actor.OwnerCamp = GameCamp.RED; } AddPlayerActor(actor.OwnerID, actor); } OnBattleStart(); //========================================================================== //检测是否是录像模式, 如果是就加载录像 //if (ReplayRecord.replayMode == ReplayMode.LOAD_REPLAY) { // ReplayPicker.replayToLoad.Load(); // ReplayRecord replayRecord = ReplayRecord.replayToLoad; // if (replayRecord == null) { // Debug.LogError("Replay Record can't be loaded"); // gameObject.SetActive(false); // return; // } else { // lockstep.ReplayRecord = replayRecord; // } //} //如果配置了显示TrueSyncStats,那就初始化 if (activeConfig.showStats) { this.gameObject.AddComponent <TrueSyncStats>().Lockstep = lockstep; } //创建协程调度 scheduler = new CoroutineScheduler(lockstep); //非录像模式下 初始化帧的玩家列表 if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY) { lockstep.AddPlayer(0, "Local_Player", true); //if (communicator == null) { // lockstep.AddPlayer(0, "Local_Player", true); //} else { // List<PhotonPlayer> players = new List<PhotonPlayer>(PhotonNetwork.playerList); // players.Sort(UnityUtils.playerComparer); // for (int index = 0, length = players.Count; index < length; index++) { // PhotonPlayer p = players[index]; // lockstep.AddPlayer((byte) p.ID, p.NickName, p.IsLocal); // } //} } //初始化场景中现有的帧同步行为 TrueSyncBehaviour[] behavioursArray = FindObjectsOfType <TrueSyncBehaviour>(); for (int index = 0, length = behavioursArray.Length; index < length; index++) { generalBehaviours.Add(NewManagedBehavior(behavioursArray[index])); } //实例化玩家预设playerPrefabs和同步其行为的拥有者 initBehaviors(); //初始化行为拥有者,并分配给对于玩家。没有继承TrueSyncBehaviour的就继续放到普通行为列表 initGeneralBehaviors(generalBehaviours, false); //添加物理对象移除监听 PhysicsManager.instance.OnRemoveBody(OnRemovedRigidBody); //设置启动状态 startState = StartState.BEHAVIOR_INITIALIZED; }