Пример #1
0
    /* public void TryOffload(ResourceInventory Target)
     * {
     *   string temp;
     *   TryOffload(Target,out temp);
     * }*/


    public void TryOffload(ResourceInventory Target)
    {
        if (Target.CanAdd(NaniteResource, NaniteOffloadAmount))
        {
            if (LinkedInventory.GetResource(NaniteResource) >= NaniteOffloadAmount)
            {
                //player-facing poptext
                if (AntiSpamTimer <= Time.time)
                {
                    var poptext = Instantiate(popText); //No this doesn't cause memleaks, I know it looks bad but it doesn't
                    poptext.popText.SetText($"{NaniteResource.DisplayName} added");
                    AntiSpamTimer = Time.time + AntiSpam;
                }


                Target.AddResource(NaniteResource, NaniteOffloadAmount);
                LinkedInventory.RemoveResource(NaniteResource, NaniteOffloadAmount);
                Debug.Log(Target.GetResource(NaniteResource));
            }
            else
            {
                //player-facing poptext
                if (AntiSpamTimer <= Time.time)
                {
                    var poptext = Instantiate(popText);
                    poptext.popText.SetText($"No {NaniteResource.DisplayName} available");
                    AntiSpamTimer = Time.time + AntiSpam;
                }

                //error = OffloadEmptyMsg;
                return;
            }
        }
        else
        {
            //player-facing poptext
            var poptext = Instantiate(popText);
            poptext.popText.SetText($"{NaniteResource.DisplayName} full");

            //error = OffloadFullMsg;
            Debug.Log("Player Inv Full");
            return;
        }
        //error = null;
    }