Beispiel #1
0
        private IEnumerator UnloadCoroutine()
        {
            yield return(UnloadAnimation());

            OnUnload();
            OnUnloadEvent?.Invoke();
            _isLoaded = false;
        }
Beispiel #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);
            }
        }