示例#1
0
        protected override void Execute()
        {
            if (Number <= 0)
            {
                return;
            }
            BuildingParameters param = (BuildingParameters)parameters;

            if (pattern == null || pattern.Length == 0)           // generate a pattern if needed
            {
                pattern = new int[Number];
                for (int i = 0; i < Number; i++)
                {
                    if (param != null && param.Rand != null)
                    {
                        pattern[i] = param.Rand.Next(0, prefabs.Length);
                    }
                    else
                    {
                        pattern[i] = (int)(Random.value * prefabs.Length);
                    }
                }
            }

            for (int i = 0; i < Number; i++)                            // spawn the prefabs
            {
                int index = pattern[i % pattern.Length] % prefabs.Length;

                //if (i == 0 || i==Number-1)
                //{
                //    continue;
                //}
                if (i == Number / 2 && doorPrefabs != null)
                {
                    int randomN = param.Rand.Next(0, doorPrefabs.Length);
                    SpawnPrefab(doorPrefabs[randomN],
                                direction * (i - (Number - 1) / 2f),
                                Quaternion.identity,
                                transform
                                );
                }
                else
                {
                    SpawnPrefab(prefabs[index],
                                direction * (i - (Number - 1) / 2f),
                                Quaternion.identity,
                                transform
                                );
                }
            }
        }
示例#2
0
    public void generateBuilding(int index, int x, int y)
    {
        Color c = inputMap.GetPixel(x, y);

        if (c.grayscale != 0)
        {
            GameObject house = Instantiate(houseBase, new Vector3(x * houseWidth + 1, 0, y * houseHeight + 1), Quaternion.identity);

            stockComponent  = house.GetComponent <Demo.Stock>();
            parameComponent = house.GetComponent <Demo.BuildingParameters>();


            stockComponent.Width = houseWidth - 1;
            stockComponent.Depth = houseHeight - 1;

            parameComponent.maxHeight = (int)(c.grayscale * 256f) / 20;

            stockComponent.Generate();
        }
    }
示例#3
0
        void CreateFlatRoofPart()
        {
            BuildingParameters param = (BuildingParameters)parameters;

            int side = param.Rand.Next(2);
            Row flatRoof;

            switch (side)
            {
            // Add two roof strips in depth direction
            case 0:
                for (int i = 0; i < 2; i++)
                {
                    flatRoof = CreateSymbol <Row>("roofStrip",
                                                  new Vector3((Width - 1) * (i - 0.5f), 0, 0),
                                                  Quaternion.identity,
                                                  transform
                                                  );
                    flatRoof.Initialize(Depth, param.roofStyle);
                    flatRoof.Generate();
                }
                newWidth -= 2;
                break;

            // Add two roof strips in width direction
            case 1:
                for (int i = 0; i < 2; i++)
                {
                    flatRoof = CreateSymbol <Row>("roofStrip",
                                                  new Vector3(0, 0, (Depth - 1) * (i - 0.5f)),
                                                  Quaternion.Euler(0, 0, 0),
                                                  transform
                                                  );
                    flatRoof.Initialize(Width, param.roofStyle, null, new Vector3(1, 0, 0));
                    flatRoof.Generate();
                }
                newDepth -= 2;
                break;
            }
        }
示例#4
0
        public virtual void Initialize(int Width, int Depth, int HeightRemaining)
        {

            if (parameters == null)
            {
                parameters = GetComponent<BuildingParameters>();
            }
            param = (BuildingParameters)parameters;
            
            this.Width = Width;
            this.Depth = Depth;

            if (this.HeightRemaining == -1)
            {
                this.HeightRemaining = param.maxHeight;
            }
            else
            {
                this.HeightRemaining = HeightRemaining;
            }

        }
示例#5
0
        protected override void Execute()
        {
            if (Number <= 0)
            {
                return;
            }
            BuildingParameters param = (BuildingParameters)parameters;

            if (pattern == null || pattern.Length == 0)           // generate a pattern if needed
            {
                pattern = new int[Number];
                for (int i = 0; i < Number; i++)
                {
                    if (param != null && param.Rand != null)
                    {
                        pattern[i] = param.Rand.Next(0, prefabs.Length);
                    }
                    else
                    {
                        pattern[i] = (int)(Random.value * prefabs.Length);
                    }
                }
            }
            for (int i = 0; i < Number; i++)                            // spawn the prefabs
            {
                int     index    = pattern[i % pattern.Length] % prefabs.Length;
                Vector3 position = direction * (i - (Number - 1) / 2f);

                // push the wall to the center
                position.x = 0.5f;

                SpawnPrefab(prefabs[index],
                            position,
                            Quaternion.identity,
                            transform
                            );
            }
        }
示例#6
0
        void CreateNextPart()
        {
            if (newWidth <= 0 || newDepth <= 0)
            {
                return;
            }
            BuildingParameters param = (BuildingParameters)parameters;

            double randomValue = param.Rand.NextDouble();

            if (randomValue < param.RoofContinueChance || HeightRemaining <= 0)             // continue with the roof
            {
                Roof nextRoof = CreateSymbol <Roof>("roof");
                nextRoof.Initialize(newWidth, newDepth, HeightRemaining);
                nextRoof.Generate(param.buildDelay);
            }
            else                 // continue with a stock
            {
                Stock nextStock = CreateSymbol <Stock>("stock");
                nextStock.Initialize(newWidth, newDepth, HeightRemaining);
                nextStock.Generate(param.buildDelay);
            }
        }
示例#7
0
 void Start()
 {
     Root       = GetComponent <Shape>();
     parameters = GetComponent <BuildingParameters>();
 }
示例#8
0
        protected override void Execute()
        {
            // This is necessary for the start symbol of the grammar:
            if (parameters == null)
            {
                parameters = GetComponent <BuildingParameters>();
            }

            BuildingParameters param = (BuildingParameters)parameters;

            GameObject[] walls = new GameObject[4];



            for (int i = 0; i < 4; i++)
            {
                Vector3 localPosition = new Vector3();
                switch (i)
                {
                case 0:
                    localPosition = new Vector3(-(Width - 1) * 0.5f, 0, 0);     // left
                    break;

                case 1:
                    localPosition = new Vector3(0, 0, (Depth - 1) * 0.5f);     // back
                    break;

                case 2:
                    localPosition = new Vector3((Width - 1) * 0.5f, 0, 0);     // right
                    break;

                case 3:
                    localPosition = new Vector3(0, 0, -(Depth - 1) * 0.5f);     // front
                    break;
                }
                Row newRow = CreateSymbol <Row>("wall", localPosition, Quaternion.Euler(0, i * 90, 0), transform);

                if (isFloor == true && i == DoorOrientation)
                {
                    newRow.Initialize(
                        i % 2 == 1 ? Width : Depth,
                        param.wallStyle, param.doorStyle,
                        param.wallPattern
                        );
                    // Debug.Log("initializing doors");
                }
                else
                {
                    newRow.Initialize(
                        i % 2 == 1 ? Width : Depth,
                        param.wallStyle,
                        param.wallPattern
                        );

                    //Debug.Log("initializing normal wall");
                }



                newRow.Generate();
            }

            double randomValue = param.Rand.NextDouble();

            if (param.maxHeight - currentFloor > 0)
            {
                ShotgunHouse nextStock = CreateSymbol <ShotgunHouse>("ShotgunStock", new Vector3(0, 1, 0), Quaternion.identity, transform);
                nextStock.Initialize(Width, Depth, currentFloor + 1, param.maxHeight, RoofPrefab, false);
                nextStock.Generate(param.buildDelay);
            }
            else
            {
                //instantiate the roof
                GameObject tr = Instantiate(RoofPrefab, transform);


                //set a roof position offset
                Vector3 offset = new Vector3(-Width / 2f, 1, -Depth / 2f);

                //set a roof scale offset       average them for height
                Vector3 scale = new Vector3(Width, (Width + Depth) / 2f, Depth);

                tr.transform.localScale    = scale;
                tr.transform.localPosition = offset;
            }
        }