public virtual Shape SpawnShape() { int factoryIndex = Random.Range(0, spawnConfig.factories.Length); Shape shape = spawnConfig.factories[factoryIndex].GetRandom(); Transform trans = shape.transform; trans.localPosition = SpawnPoint; trans.localRotation = Random.rotation; trans.localScale = Vector3.one * spawnConfig.scale.RandomValueInRange; if (spawnConfig.uniformColor) { shape.SetColor(spawnConfig.color.RandomInRange); } else { for (int i = 0; i < shape.ColorCount; ++i) { Color color = spawnConfig.color.RandomInRange; shape.SetColor(color, i); } } float angularSpeed = spawnConfig.angularSpeed.RandomValueInRange; if (angularSpeed != 0f) { RotationShapeBehavior rotation = shape.AddBehavior <RotationShapeBehavior>(); rotation.AngularVelocity = Random.onUnitSphere * angularSpeed; } float speed = spawnConfig.speed.RandomValueInRange; if (speed != 0f) { MovementShapeBehavior movement = shape.AddBehavior <MovementShapeBehavior>(); movement.Velocity = GetDirectionVector(spawnConfig.movementDirection, trans) * speed; } SetupOscillation(shape); return(shape); }
public virtual void SpawnShape() { int factoryIndex = Random.Range(0, spawnConfig.factories.Length); Shape shape = spawnConfig.factories[factoryIndex].GetRandom(); shape.gameObject.layer = gameObject.layer; Transform trans = shape.transform; trans.localPosition = SpawnPoint; trans.localRotation = Random.rotation; trans.localScale = Vector3.one * spawnConfig.scale.RandomValueInRange; SetupColor(shape); float angularSpeed = spawnConfig.angularSpeed.RandomValueInRange; if (angularSpeed != 0f) { RotationShapeBehavior rotation = shape.AddBehavior <RotationShapeBehavior>(); rotation.AngularVelocity = Random.onUnitSphere * angularSpeed; } float speed = spawnConfig.speed.RandomValueInRange; if (speed != 0f) { MovementShapeBehavior movement = shape.AddBehavior <MovementShapeBehavior>(); movement.Velocity = GetDirectionVector(spawnConfig.movementDirection, trans) * speed; } SetupOscillation(shape); Vector3 lifecycleDurations = spawnConfig.lifecycle.RandomDurations; int satelliteCount = spawnConfig.satellite.amount.RandomValueInRange; for (int i = 0; i != satelliteCount; ++i) { CreateSatelliteFor(shape, spawnConfig.satellite.uniformLifecycles ? lifecycleDurations : spawnConfig.lifecycle.RandomDurations); } SetupLifecycle(shape, lifecycleDurations); }