public void SetStarType(ref PosVel pv, float distPercent, float ellipseProgression) { if (starGroupTotals == 0) { foreach (var item in StarGroups) { starGroupTotals += item.Percentage * 0.01f; // This multiplied allows artists to use whole numbers in the UI. } } float starType = Random.Range(0, starGroupTotals); float total = 0; for (int i = 0; i < StarGroups.Count; i++) { var sg = StarGroups[i]; total += sg.Percentage * 0.01f; // This multiplied allows artists to use whole numbers in the UI. if (starType < total) { pv.uv = sg.UVOffset; pv.color = sg.UseColorRange ? sg.ColorRange.Evaluate(Random.value) : centerToRimGradient.Evaluate(distPercent); float sgSize = Random.Range(sg.SizeMultiplierRange.x, sg.SizeMultiplierRange.y); pv.size = sg.SizeIsAbsolute ? sgSize : centerToRimStarSize.Evaluate(ellipseProgression) * sgSize; pv.ellipseDistance += sg.RandomEllipseScaleOffset * ((Random.value * 2) - 1); break; } } }
public PosVel[] GenerateEllipse(float offset, float ellipseProgression) { List <PosVel> result = new List <PosVel>(StarsPerEllipse); float ellipseScale = Mathf.Lerp(MinEllipseScale, MaxEllipseScale, ellipseProgression); for (int i = 0; i < StarsPerEllipse; i++) { float x = 0; float y = 0; float z = 0; float t = Random.Range(0, Mathf.PI * 2f); var maxRadii = Mathf.Max(XRadii, ZRadii); float maxDist = MaxEllipseScale * maxRadii; x = Mathf.Cos(t) * XRadii; z = Mathf.Sin(t) * ZRadii; var zp = (z * Mathf.Cos(offset * Mathf.Deg2Rad)) - (x * Mathf.Sin(offset * Mathf.Deg2Rad)); var xp = (z * Mathf.Sin(offset * Mathf.Deg2Rad)) + (x * Mathf.Cos(offset * Mathf.Deg2Rad)); x = xp; z = zp; Vector3 flatPos = new Vector3(x, y, z); float distance = flatPos.magnitude; float distPercent = Mathf.InverseLerp(0, maxDist, distance) * ellipseProgression; float verticalOffset = centerToRimVerticalOffset.Evaluate(distPercent) * YRange; y = Random.Range(-verticalOffset, verticalOffset); var pv = new PosVel(); pv.curveOffset = t; pv.ellipseOffset = offset * Mathf.Deg2Rad; pv.ellipseDistance = ellipseProgression; pv.position = new Vector3(x * ellipseScale, y, z * ellipseScale); SetStarType(ref pv, distPercent, ellipseProgression); if (pv.size > 0) { result.Add(pv); } } return(result.ToArray()); }