Ejemplo n.º 1
0
    // Child override to set decoration
    protected override void _SetDecoration(string decoID, bool isPlacedFromDecoMode)
    {
        currDecoId = decoID;
        // Build the prefab from the id of the decoration
        string     strResource = DataLoaderItems.GetDecoItemPrefabName(decoID);
        GameObject goPrefab    = Resources.Load(strResource) as GameObject;

        if (decoGameObject != null)
        {
            Destroy(decoGameObject.gameObject);
            InventoryManager.Instance.AddItemToInventory(oldDecoId);
            DataManager.Instance.GameData.Decorations.PlacedDecorations.Remove(oldDecoId);
        }
        if (goPrefab)
        {
            decoGameObject = Instantiate(goPrefab) as GameObject;
            decoGameObject.transform.parent = placementNode;                // Put it in the hierachy of decorations in this room
            GameObjectUtils.ResetLocalPosition(decoGameObject);             // Reset all transforms
            DataManager.Instance.GameData.Decorations.PlacedDecorations.Remove(currDecoId);
            InventoryManager.Instance.UseDecoItem(currDecoId);
            oldDecoId = currDecoId;
            // If the object is a farm deco, init some variables
            FarmGenerator farmScript = decoGameObject.GetComponent <FarmGenerator>();
            if (farmScript != null)
            {
                farmScript.Initialize(decoID, isPlacedFromDecoMode);
            }
        }
        else
        {
            Debug.LogError("No such prefab for " + strResource);
        }
    }
Ejemplo n.º 2
0
    public static Building CreateBuilding(GenerationRandom genRan, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        Vec2i zero      = new Vec2i(0, 0);
        int   maxWidth  = (plan.DesiredSize == null || plan.DesiredSize == zero) ?Mathf.Min(plan.BuildingPlan.MaxSize, plan.MaxWidth): plan.DesiredSize.x;
        int   maxHeight = (plan.DesiredSize == null || plan.DesiredSize == zero)? Mathf.Min(plan.BuildingPlan.MaxSize, plan.MaxHeight) : plan.DesiredSize.z;
        int   width     = genRan.RandomInt(plan.BuildingPlan.MinSize, maxWidth);
        int   height    = genRan.RandomInt(plan.BuildingPlan.MinSize, maxHeight);

        if (plan.BuildingPlan == Building.BLACKSMITH)
        {
            Blacksmith smith = BlacksmithGenerator.GenerateBlacksmith(genRan, new Blacksmith(width, height), out vox, plan);
            return(smith);
        }
        if (plan.BuildingPlan == Building.BARACKS)
        {
            Barracks barr = BarracksGenerator.GenerateBarracks(genRan, new Barracks(width, height), out vox, plan);
            return(barr);
        }
        if (plan.BuildingPlan == Building.TAVERN)
        {
            return(TavernGenerator.GenerateTavern(genRan, new Tavern(width, height), out vox, plan));
        }
        if (plan.BuildingPlan == Building.VEGFARM)
        {
            Farm farm = FarmGenerator.GenerateVegFarm(genRan, new Farm(width, height), out vox, plan);
            return(farm);
        }
        if (plan.BuildingPlan == Building.WHEATFARM)
        {
            Farm farm = FarmGenerator.GenerateWheatFarm(genRan, new Farm(width, height), out vox, plan);
            return(farm);
        }

        House house = HouseGenerator.GenerateHouse(genRan, new House(width, height), out vox, plan);

        return(house);
        //return GenerateHouse(out vox, width, height);
    }