Example #1
0
        //add/remove to/from the resource locally
        public void AddAmountLocal(int value, Unit source)
        {
            if (collected == false) //if the resource hasn't been collected before now
            {
                collected = true;

                if (secondaryModel != null) //if there's a secondary model, enable it and disable the initial one
                {
                    ToggleModel(false);     //hide the primary model
                    secondaryModel.SetActive(true);

                    if (secondarySelection != null)            //if there's a secondary selection
                    {
                        selection.DisableMinimapIcon();        //disable the first minimap icon
                        selection.gameObject.SetActive(false); //disable the selection object

                        //enable the secondary one:
                        secondarySelection.gameObject.SetActive(true);

                        selection = secondarySelection;
                        gameMgr.MinimapIconMgr?.Assign(selection); //ask the minimap icon manager to create the a minimap icon for this resource and link it to the secondary selection
                    }
                }
            }

            if (infiniteAmount == false) //only change the amount if the resource doesn't have infinite amount
            {
                amount += Mathf.FloorToInt(value);
                CustomEvents.OnResourceAmountUpdated(this); //trigger custom event
            }

            if (gameMgr.ResourceMgr.CanAutoCollect())                                                 //if resources are automatically collected
            {
                gameMgr.ResourceMgr.UpdateResource(source.FactionID, resourceType.GetName(), -value); //then add the resource to the faction.
            }
            else //resources need to dropped off at a building
            {
                source.CollectorComp.UpdateDropOffResources(ID, -value);
            }

            if (amount <= 0 && infiniteAmount == false) //if the resource is empty
            {
                DestroyResource(source);
            }
        }