コード例 #1
0
 void Update()
 {
     if (isLocalPlayer)
     {
         // 计算奔跑时间
         float lastShowRunEnergy = showRunEnergy;
         float now = Time.realtimeSinceStartup;
         if (inputRun)
         {
             showRunEnergy = Mathf.Max(Mathf.Min(leftRunEnergy - (now - runStartTime) * CONSUME_SPEED, runEnergy), 0);
         }
         else
         {
             showRunEnergy = Mathf.Max(Mathf.Min(leftRunEnergy + (now - runEndTime) * RECOVER_SPEED, runEnergy), 0);
         }
         if (!lastShowRunEnergy.Equals(showRunEnergy))
         {
             EventMgr.instance.TriggerEvent <float, float>("RefreshRunEnergy", showRunEnergy, runEnergy);
         }
         if (hudControl != null)
         {
             hudControl.ShowSliderEnergy(showRunEnergy, runEnergy);
         }
         // 计算视野
         bool warn = false;
         SightMgr.instance.Check(sightController, sightRange, sightAngle, bodyRadius * 6, ref targetsInSight, ref targetsOutSight);
         for (int i = 0; i < targetsInSight.Count; i++)
         {
             targetsInSight[i].BecameVisible();
         }
         for (int i = 0; i < targetsOutSight.Count; i++)
         {
             SightController target = targetsOutSight[i];
             target.BecameInvisible();
             if (!warn)
             {
                 TestController player = target.GetComponent <TestController>();
                 if (player != null && player.inputRun && Vector3.Distance(sightController.transform.position, player.thisTransform.position) < WARN_DISTANCE)
                 {
                     warn = true;
                 }
             }
         }
         if (hudControl != null)
         {
             if (warn && !hudControl.IsWarnShow())
             {
                 // 显示警戒标识和提示
                 hudControl.ShowWarnIcon();
                 hudControl.ShoweHudTip("听到脚步声!");
             }
             else if (!warn && hudControl.IsWarnShow())
             {
                 // 隐藏警戒标识
                 hudControl.HideWarnIcon();
             }
         }
     }
 }