Exemplo n.º 1
0
        private void GeneratePeriodicBarrierRectPattern(BarrierRectPatternGenerateEvent generateEvent)
        {
            var collider = generateEvent.barrierPrefab.GetComponent <Collider>();

            Assert.IsNotNull(collider, "Barrier collider not found");

            int row    = (int)((generateEvent.size.z / collider.bounds.size.z) * generateEvent.density);
            int column = (int)((generateEvent.size.x / collider.bounds.size.x) * generateEvent.density);

            for (int iRow = 0; iRow < row; ++iRow)
            {
                float zPosition = (iRow + 1) * (generateEvent.size.z / (row + 1)) - generateEvent.size.z / 2;
                for (int iColumn = 0; iColumn < column; ++iColumn)
                {
                    Vector3 position = new Vector3((iColumn + 1) * (generateEvent.size.x / (column + 1)) - generateEvent.size.x / 2, 0, zPosition);

                    var go = GameObject.Instantiate(generateEvent.barrierPrefab,
                                                    generateEvent.parent);

                    go.name = generateEvent.barrierPrefab.name;

                    go.transform.localPosition = position;
                }
            }
        }
Exemplo n.º 2
0
        private void GenerateRandomBarrierRectPattern(BarrierRectPatternGenerateEvent generateEvent)
        {
            float maxArea     = generateEvent.size.x * generateEvent.size.z;
            float targetArea  = maxArea * generateEvent.density;
            float currentArea = 0.0f;

            while (currentArea < targetArea)
            {
                Vector3 position = new Vector3(Random.Range(-generateEvent.size.x / 2, generateEvent.size.x / 2), 0, Random.Range(-generateEvent.size.z / 2, generateEvent.size.z / 2));
                Vector3 scale    = Vector3.one * Random.Range(0.5f, 2.0f);

                var go = GameObject.Instantiate(generateEvent.barrierPrefab,
                                                generateEvent.parent);

                go.name = generateEvent.barrierPrefab.name;

                go.transform.localPosition = position;
                go.transform.localScale    = new Vector3(go.transform.localScale.x * scale.x,
                                                         go.transform.localScale.y * scale.y,
                                                         go.transform.localScale.z * scale.z);

                var collider = go.GetComponentInChildren <Collider>();
                Assert.IsNotNull(collider, "Barrier collider not found");

                currentArea += collider.bounds.size.x * collider.bounds.size.z;
            }
        }
Exemplo n.º 3
0
 private void GenerateBarrierRectPattern(BarrierRectPatternGenerateEvent generateEvent)
 {
     if (generateEvent.fillType == BarrierPatternFillType.Random)
     {
         GenerateRandomBarrierRectPattern(generateEvent);
     }
     else
     {
         GeneratePeriodicBarrierRectPattern(generateEvent);
     }
 }