示例#1
0
    private void InitResourceContainer(GameObject go, Vector3Int cellPosition)
    {
        Transform interactor = go.transform.Find("interactor");

        if (interactor)
        {
            ResourceContainer container = interactor.GetComponent <ResourceContainer>();
            if (container && persistantData.resourceContainersSave.ContainsKey(cellPosition))
            {
                foreach (KeyValuePair <string, int> entry in persistantData.resourceContainersSave[cellPosition])
                {
                    container.AddItem(entry.Key, entry.Value);
                }
            }
        }
    }
示例#2
0
    public GameObject GetResourcePile(Dictionary <string, int> ressourcesList)
    {
        GameObject pile = Instantiate(resourcePilePrefab);

        pile.name = "ResourcePile";
        pile.transform.rotation   = Quaternion.Euler(0, Random.Range(0, 4) * 90f, 0);
        pile.transform.localScale = Vector3.one;

        ResourceContainer pileContainer = pile.transform.Find("interactor").gameObject.GetComponent <ResourceContainer>();

        pileContainer.capacity = 0;

        foreach (KeyValuePair <string, int> entry in ressourcesList)
        {
            pileContainer.AddItem(entry.Key, entry.Value);
        }
        pileContainer.UpdateContent();
        return(pile);
    }