private void placeObject(HitObjectData hitObj) { GameObject instance; if (hitObj.type == HitObjectData.HitType.Circle) { instance = Instantiate(circlePrefab, hitObj.position, Quaternion.identity); } else { instance = Instantiate(sliderPrefab, hitObj.positions[0], Quaternion.identity); Slider sliderScript = instance.GetComponent <Slider>(); sliderScript.setup(hitObj); } instance.transform.SetParent(hitObjects); }
private void generateMap() { // timestamp (progression) is made such that the smallest approach circle aligns with the beat // in this way, the timestamp is independent of the approach rate // todo - replace this with a neural network that takes song as input and outputs/fills up mapSpawns float songLength = beatMapSong.length; float progression = beatOffset; while (progression < songLength) { HitObjectData hitObject; // switch between singlecircles and sliders if (Random.Range(0, 2) == 0) // SLIDER { // between 2 and 5 positions int positionCount = Random.Range(2, 6); // max 2 coordinates away in x- and y-dir float maxSpace = 3; // duration between 2 and 5 beats? int duration = Random.Range(2, 6); // 1 repeat (for now) int repeats = 1; Vector3[] positions = new Vector3[positionCount]; for (int i = 0; i < positionCount; i++) { float randomX, randomY; if (i > 0) // limit position to be within 'maxspace' of previous point { Vector3 prevPoint = positions[i - 1]; randomX = Random.Range(prevPoint.x - maxSpace, prevPoint.x + maxSpace); randomY = Random.Range(prevPoint.y - maxSpace, prevPoint.y + maxSpace); // clamp to screen min/max randomX = Math.Max(randomX, xMin); randomX = Math.Min(randomX, xMax); randomY = Math.Max(randomY, yMin); randomY = Math.Min(randomY, yMax); } else { randomX = Random.Range(xMin, xMax); randomY = Random.Range(yMin, yMax); } positions[i] = new Vector3(randomX, randomY, depth); } hitObject = new HitObjectData(positions, progression, duration, repeats); progression += beatTime * (duration + 1); } else { // make circle float randomX = Random.Range(xMin, xMax); float randomY = Random.Range(yMin, yMax); hitObject = new HitObjectData(new Vector3(randomX, randomY, depth), progression); progression += beatTime; } mapSpawns.Add(hitObject); depth += 0.01f; // increase depth slightly to make older circles be on top } }
// called from the generation script public void setup(HitObjectData hitObj) { this.positions = hitObj.positions; this.duration = hitObj.duration; this.durationInBeats = hitObj.durationInBeats; }