Пример #1
0
        public void Step()
        {
            if (m_NavMeshAgent.enabled == false)
            {
                return;
            }
            if (!m_Owner.CheckActorState(ActorStateType.IsAutoToMove))
            {
                return;
            }
            if (!CheckReached())
            {
                return;
            }

            OnArriveEvent?.Invoke();

            if (m_OnFinished == null)
            {
                return;
            }

            m_OnFinished();
            m_OnFinished = null;
        }
Пример #2
0
        public void Transfer(Warehouse location, Warehouse destination, int transferTime, IReadOnlyList <Cargo> cargos)
        {
            Location     = location;
            Destination  = destination;
            TransferTime = transferTime;
            Cargos       = cargos;

            if (cargos.Any())
            {
                var loadTask = new TransportTask("Load", LoadTime);
                if (0 < LoadTime)
                {
                    loadTask.OnStartedEvent += () => OnLoadEvent?.Invoke(new LoadEvent(this, location, LoadTime, cargos));
                }
                AddTask(loadTask);
            }

            var transferTask = new TransportTask("Transfer", transferTime);

            transferTask.OnStartedEvent   += () => OnDepartEvent?.Invoke(new DepartEvent(this, location, destination, cargos));
            transferTask.OnCompletedEvent += () =>
            {
                Location    = destination;
                Destination = null;
                OnArriveEvent?.Invoke(new ArriveEvent(this, destination, cargos));
            };
            AddTask(transferTask);

            if (cargos.Any())
            {
                var unloadTask = new TransportTask("Unload", UnloadTime);
                unloadTask.OnStartedEvent += () =>
                {
                    if (0 < UnloadTime)
                    {
                        OnUnloadEvent?.Invoke(new UnloadEvent(this, location, UnloadTime, cargos));
                    }
                };
                unloadTask.OnCompletedEvent += () =>
                {
                    destination.Cargos.AddRange(Cargos);
                    Cargos = new List <Cargo>();
                    Transfer(destination, location, transferTime, new List <Cargo>());
                };
                AddTask(unloadTask);
            }
        }