示例#1
0
        private void GenerateRandomBarrierLinePattern(BarrierLinePatternGenerateEvent generateEvent)
        {
            float maxArea     = generateEvent.size;
            float targetArea  = maxArea * generateEvent.density;
            float currentArea = 0.0f;

            while (currentArea < targetArea)
            {
                Vector3 position = new Vector3(0, 0, Random.Range(-generateEvent.size / 2, generateEvent.size / 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.z;
            }
        }
示例#2
0
 private void GenerateBarrierLinePattern(BarrierLinePatternGenerateEvent generateEvent)
 {
     if (generateEvent.fillType == BarrierPatternFillType.Random)
     {
         GenerateRandomBarrierLinePattern(generateEvent);
     }
     else
     {
         GeneratePeriodicBarrierLinePattern(generateEvent);
     }
 }
示例#3
0
        private void GeneratePeriodicBarrierLinePattern(BarrierLinePatternGenerateEvent generateEvent)
        {
            var collider = generateEvent.barrierPrefab.GetComponent <Collider>();

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

            float barrierLength    = collider.bounds.size.z;
            int   numberOfBarriers = (int)((generateEvent.size / barrierLength) * generateEvent.density);

            for (int i = 0; i < numberOfBarriers; ++i)
            {
                Vector3 position = new Vector3(0, 0, (i + 1) * (generateEvent.size / (numberOfBarriers + 1)) - generateEvent.size / 2);

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

                go.transform.localPosition = position;
            }
        }