public virtual void RecycleNote(NoteHandler note) { if (note != null) { noteHandlers.Enqueue(note); } SpawnHoldedNotes(); }
protected virtual NoteHandler GetFreeNoteHandler() { NoteHandler result = null; while (noteHandlers.Count > 0 && (result == null || !result.IsIdle)) { result = noteHandlers.Dequeue(); } if (result == null) { var cloned = Instantiate(notePrefab); cloned.transform.SetParent(transform, false); result = cloned.GetComponent <NoteHandler>(); spawnedNoteHandlers.Add(result); } result.transform.SetAsFirstSibling(); return(result); }
private void HandleSpawn(BMSEvent bmsEvent) { bool isLongNote = bmsManager.LongNoteType > 0 && _handledChannels.Contains(bmsEvent.data1) && (bmsEvent.type == BMSEventType.LongNoteStart || bmsEvent.type == BMSEventType.LongNoteEnd); if (!_handledChannels.Contains(bmsEvent.data1)) { return; } int index = Array.IndexOf(channels, bmsEvent.data1); if (index < 0) { return; } float delta = (float)index / (channels.Length - 1); bool createNew = true; NoteHandler noteHandler = null; if (isLongNote) { int idx = Array.IndexOf(channels, bmsEvent.data1); noteHandler = longNoteHandlers[idx]; createNew = noteHandler == null; if (createNew) { longNoteHandlers[idx] = noteHandler = GetFreeNoteHandler(); } else { longNoteHandlers[idx] = null; } } else { noteHandler = GetFreeNoteHandler(); } if (createNew) { noteHandler.Register(this, bmsManager, bmsEvent.time, bmsEvent.data1, (int)bmsEvent.data2, delta, isLongNote); } else { noteHandler.RegisterLongNoteEnd(bmsEvent.time, (int)bmsEvent.data2); } if (isLongNote ? createNew : true) { switch (coloringMode) { case ColoringMode.Timing: noteHandler.SetColor(defaultColor); if (hasColors) { if (currentMatchingTime != bmsEvent.time) { matchingTimeNoteHandlers.Clear(); } currentMatchingTime = bmsEvent.time; matchingTimeNoteHandlers.Add(noteHandler); if (matchingTimeNoteHandlers.Count > 1) { if (matchingTimeNoteHandlers.Count == 2) { currentColor++; foreach (var nh in matchingTimeNoteHandlers) { nh.SetMatchColor(); } } noteHandler.SetMatchColor(); } } break; case ColoringMode.Channel: if (hasColors) { int colorId = Array.IndexOf(handledChannels, bmsEvent.data1); noteHandler.SetColor(matchColors[colorId > 0 ? colorId % matchColors.Length : 0]); } break; case ColoringMode.Beat: double currentBeat = ((bmsEvent.time - bpmBasePoint).ToAccurateMinute() * bpm + bpmBasePointBeatFlow) % timeSign; noteHandler.SetColor(HelperFunctions.ColorFromHSL(Mathf.Log(HelperFunctions.FindDivision(currentBeat), 2) / 9, 1, 0.55F)); break; default: noteHandler.SetColor(defaultColor); break; } } #if UNITY_EDITOR || DEBUG noteHandler.gameObject.name = string.Format("NOTE #{0:0000}:{1:0000} @{2}", bmsEvent.data1, bmsEvent.data2, bmsEvent.time); #endif }