Exemplo n.º 1
0
        /// <summary>
        /// Add a new entry into the dictionary and create a new ResourceUIPrefab to manage
        /// </summary>
        /// <param name="resource">Resource to add</param>
        public void AddResourceUI(Mod_Resource resource)
        {
            if (!resource)
            {
                return;
            }

            // Check if already in the dictionary
            if (!resourceUIDict.ContainsKey(resource.ResourceName))
            {
                // Check that the parent and prefab being used are valid
                if (ResourceUIPrefab && ResourceUIOwner)
                {
                    // Create a new prefab and set the parent
                    resourcePrefab = Instantiate(ResourceUIPrefab, ResourceUIOwner.transform);

                    resourceDisplay = Helper.GetComponent <UIDisplay>(resourcePrefab);

                    // Add the display to the dictionary
                    if (resourceDisplay)
                    {
                        resourceDisplay.InitialiseUI(resource.ResourceIcon, "");
                        resourceUIDict.Add(resource.ResourceName, resourceDisplay);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void UpdateResourceUI(Mod_Resource resource, int resourceCount)
        {
            if (!resource)
            {
                return;
            }

            UpdateResourceUI(resource.ResourceName, resourceCount);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if the player can afford something of type resource.ResourceName and cost value
        /// </summary>
        /// <param name="resource">Resource to check if can afford</param>
        /// <param name="value">The value to see if the player can afford</param>
        /// <returns></returns>
        public bool CanAfford(Mod_Resource resource, int value)
        {
            if (!resource)
            {
                return(false);
            }

            // Checks if the resource.ResourceName is valid
            if (SyncedResources.ContainsKey(resource.ResourceName))
            {
                return(SyncedResources[resource.ResourceName].CanAfford(value));
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds an amount of resources to a resource.ResourceName type
        /// </summary>
        /// <param name="resource">The type of resource.ResourceName to add to</param>
        /// <param name="amount">The amount to add</param>
        /// <returns>Whether the amount was successfully added</returns>
        public bool AddResource(Mod_Resource resource, int amount, bool overwrite = false)
        {
            if (!resource)
            {
                return(false);
            }

            if (SyncedResources.ContainsKey(resource.ResourceName) || overwrite)
            {
                if (!isServer)
                {
                    CmdAddToSyncDict(resource.ResourceName, amount);
                }
                else
                {
                    ServAddToSynceDict(resource.ResourceName, amount);
                }
            }

            return(false);
        }