コード例 #1
0
        public void Act(float deltaTime)
        {
            var currentPosition   = View.transform.position.X0Z();
            var goalChairPosition = GoalChair.View.transform.position.X0Z();

            bool stopMove = false;

            if ((currentPosition - goalChairPosition).magnitude < GoalChair.Radius)
            {
                if (!GoalChair.Busy)
                {
                    GoalChair.Busy = true;
                    _sittingChair  = GoalChair;
                }
                else
                {
                    stopMove = (_sittingChair != GoalChair);
                }
            }
            // if need to move
            if (GoalChair != null && !_stopMove)
            {
                var   goalVector = (goalChairPosition - currentPosition);
                float clamp      = GoalChair.Radius / 100f;
                var   delta      = goalVector.normalized * (_velocity * deltaTime);
                delta = goalVector.magnitude > clamp ? delta : Vector3.zero;
                View.transform.position += delta;
            }
        }
コード例 #2
0
 public Unit(GameObject unityRef, float velocity, float changeChairProbability, SitOnChairSystem chairSystem)
 {
     View                    = unityRef;
     _chairSystem            = chairSystem;
     _sittingChair           = null;
     _changeChairProbability = changeChairProbability;
     _velocity               = velocity;
     GoalChair               = null;
 }
コード例 #3
0
        /// <summary>
        /// Force unit to choose one free chair from given chairs list
        /// </summary>
        /// <param name="chairs">chairs list</param>
        /// <returns>false if no free chairs</returns>
        public bool ChooseChair(List <Chair> chairs)
        {
            var freeChairs = _chairSystem.GetFreeChairs();

            if (freeChairs.Count < 1)
            {
                return(false);
            }

            GoalChair = freeChairs[Random.Range(0, freeChairs.Count)];
            return(true);
        }
コード例 #4
0
 /// <summary>
 /// Unit can chagne goal chair with probabilty of ChangeChairProbability
 /// </summary>
 private void MaybeChooseAnotherChair()
 {
     if (Random.Range(0, 1f) < _changeChairProbability)
     {
         var freeChairs = _chairSystem.GetFreeChairs();
         if (freeChairs.Count > 0)
         {
             if (_sittingChair != null)
             {
                 GoalChair.Busy = false;
                 _sittingChair  = null;
             }
             GoalChair = freeChairs[Random.Range(0, freeChairs.Count)];
         }
     }
 }