예제 #1
0
        private IEnumerator LoadCoroutine()
        {
            yield return(LoadAnimation());

            _isLoaded  = true;
            _isLoading = false;
            OnLoad();
            OnLoadEvent?.Invoke();
        }
예제 #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);
            }
        }
예제 #3
0
 public void OnLoad(bool isLoaded)
 {
     OnLoadEvent?.Invoke(this, isLoaded);
 }