Esempio n. 1
0
 public void initFarmGameObjects()
 {
     prefabDictionary = farmDB.initAndGetDictionary();
     foreach (Tile tile in farm.farmMatrix)
     {
         GameObject gameObjectprefab;
         Vector2Int cords    = tile.getCords();
         string     typename = tile.getTypeString();
         if (!prefabDictionary.ContainsKey(typename))
         {
             Debug.LogError("can't init farm controller, missing a prefab with name " + typename);
             return;
         }
         prefabDictionary.TryGetValue(typename, out gameObjectprefab);
         GameObject myGameObject = Instantiate(gameObjectprefab, new Vector3(cords.x + offset.x + inGamelocation.x, cords.y + offset.y + inGamelocation.y), Quaternion.identity);
         myGameObject.transform.parent          = GameObjectContainer.transform;
         ControllerfarmMatrix[cords.x, cords.y] = myGameObject;
         InstalledFarmObject farnObject = myGameObject.AddComponent <InstalledFarmObject>();
         myGameObject.GetComponent <InstalledFarmObject>().setFarmObject(farm, cords);
     }
 }
Esempio n. 2
0
    public bool refreshTile(Vector2Int cords)
    {
        GameObject gameObjectprefab;
        Tile       tile     = farm.farmMatrix[cords.x, cords.y];
        string     typename = tile.getTypeString();

        if (!prefabDictionary.ContainsKey(typename))
        {
            Debug.LogError("can't refresh tile (" + cords.x + ", " + cords.y + ") , missing a prefab with name " + typename);
            return(false);
        }
        Destroy(ControllerfarmMatrix[cords.x, cords.y]);
        prefabDictionary.TryGetValue(typename, out gameObjectprefab);
        GameObject myGameObject = Instantiate(gameObjectprefab, new Vector3(cords.x + offset.x + inGamelocation.x, cords.y + offset.y + inGamelocation.y), Quaternion.identity);

        myGameObject.transform.parent          = GameObjectContainer.transform;
        ControllerfarmMatrix[cords.x, cords.y] = myGameObject;
        InstalledFarmObject farnObject = myGameObject.AddComponent <InstalledFarmObject>();

        myGameObject.GetComponent <InstalledFarmObject>().setFarmObject(farm, cords);
        return(true);
    }