public void OnCarEnterCheckPoint(NetworkPlayer player, int cpIndex) { CarNetworkInitWrapper comp = NetworkConnection.GetInst().playerObjMap[player]; CheckPoint cp = checkPointList[cpIndex]; OnCarEnterCheckPoint(comp, cp); }
public void OnBtnResetClicked() { if (UIManager.GetInst().MainPlayerCarCtrl != null) { CarNetworkInitWrapper car = UIManager.GetInst().MainPlayerCarCtrl.GetComponent <CarNetworkInitWrapper>(); if (car != null) { Quaternion q = new Quaternion(); q.SetLookRotation(car.transform.forward, Vector3.up); car.networkView.RPC("ResetPlayerTransformS2C", RPCMode.AllBuffered, car.netPlayer, car.transform.position, q); } } }
void OnTriggerEnter(Collider col) { Transform topParentTrans = col.transform; while (topParentTrans.parent != null) { topParentTrans = topParentTrans.parent; } CarNetworkInitWrapper netwrap = topParentTrans.GetComponent <CarNetworkInitWrapper>(); if (netwrap != null) { // 检测到本地玩家进入计时触发器 if (netwrap.netPlayer == Network.player) { // 通知服务器本地玩家控制的车辆进入某个触发器 lapCollector.networkView.RPC("LocalPlayerTriggerEnterC2S", RPCMode.AllBuffered, Network.player, index); } } }
public void OnCarEnterCheckPoint(CarNetworkInitWrapper car, CheckPoint cp) { List <SinglePlayerLapInfo> laps = null; if (playerLapInfos.lapInfos.ContainsKey(car.netPlayer)) { laps = playerLapInfos.lapInfos[car.netPlayer]; } else { laps = new List <SinglePlayerLapInfo>(); playerLapInfos.lapInfos.Add(car.netPlayer, laps); } SinglePlayerLapInfo li = null; if (laps.Count == 0) { li = new SinglePlayerLapInfo(); li.mStartTimeStamp = Time.realtimeSinceStartup; li.mCompleted = false; li.mLapTime = 0.0f; li.mLastCheckPoint = cp.index; li.mCompletedTimeStamp = 0.0f; li.mLapIndex = laps.Count; laps.Add(li); // 通知客户端更新游戏信息 networkView.RPC("PlayerLapInfoChangedS2C", RPCMode.AllBuffered, car.netPlayer, li.mCompleted, li.mLastCheckPoint, li.mLapTime, li.mStartTimeStamp, li.mCompletedTimeStamp, li.mLapIndex, true); } else { li = laps[laps.Count - 1]; // next check point if (cp.index - li.mLastCheckPoint == 1) { li.mLastCheckPoint = cp.index; // 通知客户端更新游戏信息 networkView.RPC("PlayerLapInfoChangedS2C", RPCMode.AllBuffered, car.netPlayer, li.mCompleted, li.mLastCheckPoint, li.mLapTime, li.mStartTimeStamp, li.mCompletedTimeStamp, li.mLapIndex, false); } // from the last check point to the first check point, one lap completed else if (li.mLastCheckPoint == checkPointList.Length - 1 && cp.index == 0) { li.mCompleted = true; li.mCompletedTimeStamp = Time.realtimeSinceStartup; li.mLapTime = li.mCompletedTimeStamp - li.mStartTimeStamp; // 通知客户端更新游戏信息 networkView.RPC("PlayerLapInfoChangedS2C", RPCMode.AllBuffered, car.netPlayer, li.mCompleted, li.mLastCheckPoint, li.mLapTime, li.mStartTimeStamp, li.mCompletedTimeStamp, li.mLapIndex, false); SinglePlayerLapInfo newLap = new SinglePlayerLapInfo(); newLap.mStartTimeStamp = Time.realtimeSinceStartup; newLap.mCompleted = false; newLap.mLapTime = 0.0f; newLap.mLastCheckPoint = cp.index; newLap.mCompletedTimeStamp = 0.0f; newLap.mLapIndex = laps.Count; laps.Add(newLap); // 通知客户端更新游戏信息 networkView.RPC("PlayerLapInfoChangedS2C", RPCMode.AllBuffered, car.netPlayer, newLap.mCompleted, newLap.mLastCheckPoint, newLap.mLapTime, newLap.mStartTimeStamp, newLap.mCompletedTimeStamp, newLap.mLapIndex, true); } // reverse lap else if (cp.index - li.mLastCheckPoint == -1 || li.mLastCheckPoint == 0 && cp.index == checkPointList.Length - 1) { // 通知客户端车辆位置重置 car.networkView.RPC("ResetPlayerTransformS2C", RPCMode.AllBuffered, car.netPlayer, cp.transform.position, cp.transform.rotation); } } }