public void Init(StarfieldBaseSettings settings) { m_maxStars = settings.maxStars; m_starSize = settings.starSize; m_starSizeRange = settings.starSizeRange; m_fieldHeight = settings.fieldHeight; m_fieldWidth = settings.fieldWidth; m_parallaxFactor = settings.parallaxFactor; m_stars = new ParticleSystem.Particle[m_maxStars]; m_particles = GetComponent <ParticleSystem>(); Assert.IsNotNull(m_particles, "Particle system missing from object!"); m_xOffset = m_fieldWidth * 0.5f; // Offset the coordinates to distribute the spread m_yOffset = m_fieldHeight * 0.5f; // around the object's center for (int i = 0; i < m_maxStars; i++) { float randSize = Random.Range(m_starSizeRange, m_starSizeRange + 1f); // Randomize star size within parameters float scaledColor = (true == Colorize) ? randSize - m_starSizeRange : 1f; // If coloration is desired, color based on size m_stars[i].position = GetRandomInRectangle(m_fieldWidth, m_fieldHeight) + transform.position; m_stars[i].startSize = m_starSize * randSize; m_stars[i].startColor = new Color(1f, scaledColor, scaledColor, 1f); } m_particles.SetParticles(m_stars, m_stars.Length); // Write data to the particle system }
// Start is called before the first frame update public void Init() { StarfieldBaseSettings settings = new StarfieldBaseSettings(); for (int i = 0; i < m_starfields.Count; ++i) { m_starfields[i].Init(settings); settings.maxStars += m_maxStarIncrease; settings.starSize -= m_starSizeDecrease; settings.starSizeRange -= m_starSizeRangeDecrease; settings.parallaxFactor += m_parallaxFactorIncrease; } }