Пример #1
0
    public void InitializeBuildingInfo(Tile.Property property)
    {
        int costWood = 0, costStone = 0, costWork = 0, workAmount = 0;

        if (property == Tile.Property.House)
        {
            // Use a dictionary or smth other external and central for this?
            costWood   = 4;
            costStone  = 0;
            costWork   = 2;
            workAmount = 4;
        }

        this.WorkAmount = workAmount;
        this.costWork   = costWork;
        this.costWood   = costWood;
        this.costStone  = costStone;
        Debug.Log("Initialized Building Info: " + property);
    }
Пример #2
0
 public static void SetBuildingSize(List <Tile> buildingSizeTiles, Tile.Property buildingProperty)
 {// For cleanup of tiles within a buildings tiles (spanning over several tiles)
     foreach (var _t in buildingSizeTiles)
     {
         ClearTile(_t.transform, false);
         MeshRenderer t_meshRen    = _t.GetComponent <MeshRenderer>();
         var          dirtMaterial = (Material)Resources.Load("Materials/DirtMat");
         t_meshRen.material = (dirtMaterial) ? dirtMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
         SelectionStatusHandler vH = _t.GetComponent <SelectionStatusHandler>();
         vH.originalMat = t_meshRen.material;
         _t.property    = buildingProperty;
         _t.Passable    = false;
         _t.tag         = TagHandler.buildingBonfireString;
         if (_t.GetComponent <Resource>())
         {
             Destroy(_t.GetComponent <Resource>());
         }
     }
 }
Пример #3
0
    public void SelectBuildingToBuild(Tile.Property buildingProp, GameObject buildingPrefab)
    {
        this.buildingProp = buildingProp;
        var buildingInfo = new Building();

        buildingInfo.InitializeBuildingInfo(buildingProp);
        if (PlayerResources.current.wood >= buildingInfo.CostWood && PlayerResources.current.stone >= buildingInfo.CostStone)
        {
            this.buildingPrefab = Instantiate(buildingPrefab);
            _selection.DeselectAll();
            EventHandler.current.SelectBuildingToBuild();
            Debug.Log("Selceted " + buildingProp + " to build.");
        }
        else
        {
            Debug.Log("Not enough resources.");
            Talker.TypeThis("Not enough resources.");
        }
    }
Пример #4
0
    public void SetTilePropTo(Transform tileTransform, Tile.Property newProperty)
    {
        Tile         tile    = tileTransform.GetComponent <Tile>();
        MeshRenderer meshRen = tileTransform.GetComponent <MeshRenderer>();

        tile.property = newProperty;

        if (newProperty == Tile.Property.Tree)
        {
            meshRen.material = (grassMaterial) ? grassMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.resourceWoodString;
            var randomOffset = Random.Range(0.05f, 0.15f);
            var randomDir    = Random.insideUnitCircle.normalized;
            for (int i = 0; i < 2; i++)
            {
                GameObject tree = Instantiate(Resources.Load("Nature/" + treePrefab.name), tileTransform.position, Quaternion.Euler(new Vector3(Random.Range(-7f, 7f), Random.Range(0, 360), Random.Range(-7f, 7f))), tileTransform) as GameObject;
                tree.name = treePrefab.name;
                var randomScale = Random.Range(0.75f, 1.3f);
                if (i == 0)
                {
                    tree.transform.position += Vector3.forward * randomOffset + new Vector3(randomDir.x, 0, randomDir.y);
                }
                else
                {
                    tree.transform.position -= Vector3.forward * randomOffset + new Vector3(randomDir.x, 0, randomDir.y);
                }
                tree.transform.localScale += new Vector3(randomScale, randomScale, randomScale);
            }
            tile.Passable = false;
        }
        if (newProperty == Tile.Property.Grass)
        {
            meshRen.material = (grassMaterial) ? grassMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.Passable       = true;
            tile.tag            = TagHandler.walkGroundString;
        }
        if (newProperty == Tile.Property.Water)
        {
            meshRen.material = (waterMaterial) ? waterMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.Passable       = false;
        }
        if (newProperty == Tile.Property.Stone)
        {
            meshRen.material = (rockMaterial) ? rockMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.resourceStoneString;
            GameObject rock = Instantiate(Resources.Load("Nature/" + rockPrefab.name), tileTransform.position, Quaternion.identity, tileTransform) as GameObject;
            rock.name = rockPrefab.name;
            rock.transform.localScale += new Vector3(1f, 1f, 1f);
            tile.Passable              = false;
        }
        if (newProperty == Tile.Property.OldTree)
        {
            meshRen.material = (grassMaterial) ? grassMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.magicTreeString;
            GameObject oldTree = Instantiate(Resources.Load("Nature/" + oldTreePrefab.name), tileTransform.position, Quaternion.identity, tileTransform) as GameObject;
            oldTree.name  = oldTreePrefab.name;
            tile.Passable = false;
        }
        if (newProperty == Tile.Property.Bagpack)
        {
            meshRen.material = (grassMaterial) ? grassMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.buildingBagpackString;
            GameObject bagPack = Instantiate(Resources.Load("Buildings/" + bagpackPrefab.name), tileTransform.position, Quaternion.identity, tileTransform) as GameObject;
            bagPack.name  = bagpackPrefab.name;
            tile.Passable = false;
        }

        if (newProperty == Tile.Property.WoodStorage)
        {
            meshRen.material = (dirtMaterial) ? dirtMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.buildingWoodStorageString;
            GameObject woodStorage = Instantiate(Resources.Load("Buildings/" + woodStoragePrefab.name), tileTransform.position, Quaternion.Euler(0, 120, 0), tileTransform) as GameObject;
            woodStorage.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
            woodStorage.name = woodStoragePrefab.name;
            tile.Passable    = false;
        }
        if (newProperty == Tile.Property.StoneStorage)
        {
            meshRen.material = (rockMaterial) ? rockMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.buildingStoneStorageString;
            GameObject woodStorage = Instantiate(Resources.Load("Buildings/" + stoneStoragePrefab.name), tileTransform.position, Quaternion.Euler(0, 120, 0), tileTransform) as GameObject;
            woodStorage.name = stoneStoragePrefab.name;
            tile.Passable    = false;
        }
        if (newProperty == Tile.Property.Cauldron)
        {
            meshRen.material = (dirtMaterial) ? dirtMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.buildingCauldronString;
            GameObject cauldron = Instantiate(Resources.Load("Buildings/" + cauldronPrefab.name), tileTransform.position, Quaternion.identity, tileTransform) as GameObject;
            tile.Passable = false;
            cauldron.name = woodStoragePrefab.name;
        }
        if (newProperty == Tile.Property.House)
        {
            meshRen.material = (dirtMaterial) ? dirtMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.tag            = TagHandler.buildingHouseString;
            GameObject house = Instantiate(Resources.Load("Buildings/" + housePrefab.name), tileTransform.position, Quaternion.identity, tileTransform) as GameObject;
            house.name    = housePrefab.name;
            tile.Passable = false;
        }
        if (newProperty == Tile.Property.Construction)
        {
            meshRen.material = (dirtMaterial) ? dirtMaterial : UnityEditor.AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            SelectionStatusHandler tileMat = tileTransform.GetComponent <SelectionStatusHandler>();
            tileMat.originalMat = meshRen.material;
            tile.Passable       = false;
            tile.tag            = TagHandler.buildingConstructionString;
        }

        if (newProperty == Tile.Property.Default)
        {
            ClearTile(tileTransform, true);
            tile.tag = null;
        }
        Debug.Log("Set " + tile.gameObject.name + " to " + tile.property);
    }