示例#1
0
 private bool Enter(EntityQueueSpot spot)
 {
     return(spot.Enter(gameObject, (next) =>
     {
         if (next == null)
         {
             Debug.Log("Exiting queue");
             SetState(State.DESTINATION);
         }
         else
         {
             Debug.Log("Enter next spot");
             Enter(next);
             WalkTo(next.transform.position);
         }
     }));
 }
        internal void Process()
        {
            if (onProcess == null)
            {
                return;
            }
            occupier = null;
            Action <EntityQueueSpot> action = onProcess;

            onProcess = null;
            // allow to skip spot if it becomes empty in mean time
            EntityQueueSpot target = next;

            while (target != null && target.next != null && !target.next.IsOccupied())
            {
                target = target.next;
            }
            // reset stuff before invoking
            action.Invoke(target);
        }
示例#3
0
        private void SetState(State state, float delay = 0)
        {
            if (delay > 0)
            {
                StartCoroutine(SetStateWithDelay(state, delay));
                return;
            }
            if (this.state == state)
            {
                return;
            }
            // exit
            switch (this.state)
            {
            case State.IDLE:
                break;

            case State.WALKING:
                break;
            }
            this.state = state;
            // enter
            switch (this.state)
            {
            case State.IDLE:
                WalkTo(overflow.position, () => {
                    Debug.Log("Destination reached");
                });
                break;

            case State.WALKING:

                break;

            case State.OVERFLOW:
                WalkTo(overflow.position, () => {
                    Debug.Log("Oerflow reached " + name);
                    Destroy(gameObject);
                });
                break;

            case State.DESTINATION:
                WalkTo(destination.position, () => {
                    Debug.Log("Destination reached " + name);
                    Destroy(gameObject);
                });
                break;

            case State.QUEUE:
                EntityQueueSpot spot = queue.FindEmptySpot();
                // we want to know if this spot is taken before we get to it
                enterQueueCount++;
                WalkTo(spot.transform.position, () => {
                    Debug.Log("Destination reached " + name);
                    if (Enter(spot))
                    {
                        // we are in spot, waiting to move to next spot
                        SetState(State.IN_QUEUE);
                    }
                    else
                    {
                        TryQueue();
                    }
                });
                spot.Incoming(gameObject, () =>
                {
                    TryQueue();
                });
                break;
            }
        }