B9PartSwitch.PartExtensions.AddOrCreateResource C# (CSharp) Метод

AddOrCreateResource() публичный статический Метод

public static AddOrCreateResource ( this part, PartResourceDefinition info, float maxAmount, float amount ) : PartResource
part this
info PartResourceDefinition
maxAmount float
amount float
Результат PartResource
        public static PartResource AddOrCreateResource(this Part part, PartResourceDefinition info, float maxAmount, float amount)
        {
            if (amount > maxAmount)
            {
                part.LogWarning($"Cannot add resource '{info.name}' with amount > maxAmount, will use maxAmount (amount = {amount}, maxAmount = {maxAmount})");
                amount = maxAmount;
            }

            PartResource resource = part.Resources[info.name];

            if (resource == null)
            {
                if (amount < 0f)
                    amount = maxAmount;

                resource = part.AddResource(info, maxAmount, amount);
            }
            else
            {
                resource.maxAmount = maxAmount;

                if (amount >= 0f)
                    resource.amount = amount;
            }

            return resource;
        }