Esempio n. 1
0
 public void CopyFrom(SinglePlayerLapInfo other)
 {
     mCompleted          = other.mCompleted;
     mLastCheckPoint     = other.mLastCheckPoint;
     mLapTime            = other.mLapTime;
     mStartTimeStamp     = other.mStartTimeStamp;
     mCompletedTimeStamp = other.mCompletedTimeStamp;
     mLapIndex           = other.mLapIndex;
 }
Esempio n. 2
0
 void PlayerLapInfoChangedS2C(NetworkPlayer player,
                              bool mCompleted,
                              int mLastCheckPoint,
                              float mLapTime,
                              float mStartTimeStamp,
                              float mCompletedTimeStamp,
                              int mLapIndex,
                              bool isAdd)
 {
     if (Network.isClient)
     {
         List <SinglePlayerLapInfo> laps = null;
         if (playerLapInfos.lapInfos.ContainsKey(player))
         {
             laps = playerLapInfos.lapInfos[player];
         }
         else
         {
             laps = new List <SinglePlayerLapInfo>();
             playerLapInfos.lapInfos.Add(player, laps);
         }
         SinglePlayerLapInfo lapi = null;
         if (isAdd)
         {
             lapi = new SinglePlayerLapInfo();
             laps.Add(lapi);
         }
         else
         {
             lapi = laps[laps.Count - 1];
         }
         lapi.mCompleted          = mCompleted;
         lapi.mLastCheckPoint     = mLastCheckPoint;
         lapi.mLapTime            = mLapTime;
         lapi.mStartTimeStamp     = mStartTimeStamp;
         lapi.mCompletedTimeStamp = mCompletedTimeStamp;
         lapi.mLapIndex           = mLapIndex;
     }
 }
Esempio n. 3
0
    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);
            }
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (carCamCtrl == null)
        {
            GameObject go = GameObject.Find("Car Camera");
            if (go != null)
            {
                carCamCtrl = go.GetComponent <CarCameraController>();
            }
        }

        if (UIManager.GetInst().MainPlayerCarCtrl != null)
        {
            int speed = (int)(UIManager.GetInst().MainPlayerCarCtrl.rigidbody.velocity.magnitude * 3.6f);
            speedText.text = speed.ToString() + " kmh";
            gearText.text  = "[" + UIManager.GetInst().MainPlayerCarCtrl.CurGear.ToString() + "]";
        }
        else
        {
            speedText.text = "0 kmh";
            gearText.text  = "[1]";
        }

        float maxWidth = (nitroTrans.parent as RectTransform).rect.width;

        if (UIManager.GetInst().MainPlayerCarCtrl != null)
        {
            Drivetrain dt = UIManager.GetInst().MainPlayerCarCtrl.GetComponent <Drivetrain>();
            nitroTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, dt.curNitroContainer / dt.NitroContainerMax * maxWidth);
        }
        else
        {
            nitroTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, maxWidth);
        }

        lapText.text         = "";
        rankingText.text     = "";
        bestLapTimeText.text = "";

        if (lapCollector != null)
        {
            float bestLapTime      = -1.0f;
            SinglePlayerLapInfo pi = lapCollector.GetLocalPlayerLapInfo(ref bestLapTime);
            if (pi != null)
            {
                if (lapCollector.maxLap <= 0)
                {
                    lapText.text = "Lap " + (pi.mLapIndex + 1).ToString();
                }
                else
                {
                    lapText.text = "Lap " + (pi.mLapIndex + 1).ToString() + " / " + lapCollector.maxLap.ToString();
                }

                float lapTime = Time.realtimeSinceStartup - pi.mStartTimeStamp;
                if (lapTime < 60.0f)
                {
                    rankingText.text = lapTime.ToString("#0.00");
                }
                else if (lapTime < 3600.0f)
                {
                    int   m = (int)lapTime / 60;
                    float s = lapTime - m * 60.0f;
                    rankingText.text = m.ToString() + ":" + s.ToString("#0.00");
                }

                if (bestLapTime > 0.0f)
                {
                    if (bestLapTime < 60.0f)
                    {
                        bestLapTimeText.text = bestLapTime.ToString("#0.00");
                    }
                    else if (bestLapTime < 3600.0f)
                    {
                        int   m = (int)bestLapTime / 60;
                        float s = bestLapTime - m * 60.0f;
                        bestLapTimeText.text = m.ToString() + ":" + s.ToString("#0.00");
                    }
                }
            }
        }
    }