'Count amount of lines in unity GUI (break count after each comma)
I'm creating a rhythm game on Unity and I'm using an external program which in turn gives me 0000,1000,0100,0001 as outputs, and I'm using them to create the song levels. I've come across a problem where sometimes it prints four lines before a comma (a whole beat), and sometimes eight lines before a comma (half beats), and so on. Is there any way I can make Unity detect the amount of lines before a comma hits? Code & images below; if you need any other parts tell me, thanks !
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(NoteData))]
public class NoteDataEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
NoteData data = target as NoteData;
if (GUILayout.Button("Parse"))
{
float x = 60f / data.BPM;
float currentTime = 0;
List<NoteData.NoteInfo> notes = new List<NoteData.NoteInfo>();
string[] allNotes = data.noteSequence.Split('\n');
foreach (string note in allNotes)
{
if (note.Trim() == ",") continue;
currentTime += x;
if (note.Trim() == "0000") continue;
NoteData.NoteColor colorToAdd = NoteData.NoteColor.Red;
if (note.Trim() == "1000")
{
colorToAdd = NoteData.NoteColor.Green;
}
else if (note.Trim() == "0100")
{
colorToAdd = NoteData.NoteColor.Blue;
}
else if (note.Trim() == "0010")
{
colorToAdd = NoteData.NoteColor.Red;
//colorToAdd = (NoteData.NoteColor) Random.Range(0, 3);
}
notes.Add(new NoteData.NoteInfo(){
color = colorToAdd,
timeStamp = currentTime
});
}
data.notes = notes.ToArray();
}
}
}
Solution 1:[1]
I managed to find a solution by adding a line counter which puts the counter to 0 whenever a comma is seen, and adds +1 to the counter everytime there isn't a comma until one pops up.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pietru |
