public override ISimplePlacement GetPlacement(IPurchasable purchasable, IResourceContainer resources) { var placement = new StructurePlacement(() => resources.HasEnough(purchasable.Cost) ? null : "Not enough resources"); placement.OnPlaced += OnPlaced; return(placement); }
public void Handle(IContentCachedPrefab prefab) { GameObject go = prefab.GetCache(); IPurchasable purchasable = go.GetComponent <IPurchasable>(); IResourceContainer resources = GetComponent <IResourceContainer>(); if (resources.HasEnough(purchasable.Cost)) { GameObject instance = prefab.Instantiate(); ReflectionUtils.DynamicBroadcastInvoke(instance, "OnInstantiated", true); // Definitively hacky, but better than immidiate alternative. instance.SetActive(true); ISimplePlacement placement = GetPlacement(purchasable, resources); placement.Pickup(instance); placement.OnPlaced += (obj) => resources.TrySpend(purchasable.Cost); PlacementController.Instance.TakePlacement(placement); } }
protected virtual bool IsInteractable() { return(_resourceContainer.HasEnough(_purchasable.Cost)); }
private void UpdateAvailableCount() { int amount = Controller.GetAvailable().Where(x => _resourceContainer.HasEnough(x.ResourceCost)).Count(); AvailableOptionsCount.text = $"{amount} available research option(s)"; }