Ejemplo n.º 1
0
        /// <summary>
        /// Chiamata appena lo stato è stato cambiato.
        /// </summary>
        private void StateChanged(UnitState oldState)
        {
            if (!anim)
            {
                anim = GetComponentInChildren <Animator>();
            }
            if (movable == null)
            {
                movable = GetComponent <IMovable>();
            }

            switch (CurrentState)
            {
            case UnitState.not_ready:
                break;

            case UnitState.idle:
                // anim idle
                anim.SetInteger("State", 1);
                movable.Wait(Random.Range(GM.I.CurrentConfiguration.WaitTimeAverage - GM.I.CurrentConfiguration.WaitTimeVariation, GM.I.CurrentConfiguration.WaitTimeAverage + GM.I.CurrentConfiguration.WaitTimeVariation));
                break;

            case UnitState.walk:
                // anim walk
                anim.SetInteger("State", 2);
                // movimento verso direzione target
                movable.MoveTo(GM.I.GetRandomSpownPosition(movable.CurrentPosition));
                break;

            case UnitState.collision_cooldown_positive:
                anim.SetInteger("State", 1);
                movable.Collide();
                if (GlobalEventManager.OnUnitCollisionPositive != null)
                {
                    GlobalEventManager.OnUnitCollisionPositive(movable as UnitBase);
                }
                break;

            case UnitState.collision_cooldown_negative:
                anim.SetInteger("State", 1);
                movable.Collide();
                if (GlobalEventManager.OnUnitCollisionNegative != null)
                {
                    GlobalEventManager.OnUnitCollisionNegative(movable as UnitBase);
                }
                break;

            default:
                break;
            }

            if (OnStateChanged != null)
            {
                OnStateChanged(CurrentState, oldState);
            }
        }