public ChordObject DouplicateChordObject(ChordObject chordObj, List <ChordObject> chordObjects) { // 0. Refs var fields = Player.inst.curFieldSet; var ID = chordObj.fieldID; var parent = MeshRef.inst.recordObj_parent; var material = MeshRef.inst.recordObjs_mat[chordObj.trackLayer]; var pos = Recorder.inst.NextLoopPosition(chordObj.sequencer, chordObj.start); var layer = 8; var visible = true; var collider = true; var tag = MeshRef.inst.chordObjTag; // 1. Instantiate & scale! var newObj = MeshCreation.CreateLaneSurface(fields, ID, "ChordObject", parent, material, visible, collider, tag, 1f, layer).gameObject; newObj.transform.localScale = chordObj.obj.transform.localScale; var douplicateObj = ChordObject.Create(newObj, null, pos, ID, chordObj.notes, chordObj.sequencer, chordObj.trackLayer, chordObj.start, chordObj.end, chordObj.loopStart, chordObj.loopEnd_extended); // 2. Set data chordObj.douplicate = douplicateObj; chordObj.hasRespawned = true; // 3. Add to list chordObjects.Add(douplicateObj); return(douplicateObj); }
/// <summary> /// Remove a single chord. Maybe also LoopObject. Reset every necessary UI stuff. /// </summary> /// <param name="chordObj"></param> private void RemoveRecord(ChordObject chordObj) { // 1. clear notes foreach (int note in chordObj.notes) { chordObj.sequencer.RemoveNotesInRange(note, chordObj.start, chordObj.end); chordObj.sequencer.NoteOff(note); } // 2. gameObject & list RecordVisuals.inst.DestroyChordObject(chordObj); // 3. UI if (chordObj.sequencer.GetAllNotes().Count == 0) { UIOps.inst.EnableRecordedTrackImage(chordObj.trackLayer, false); } // 4. field.activeChords if (chordObj.isPlaying) Player.inst.curFieldSet[chordObj.fieldID].ActiveRecords--; // 5. LoopObject if (!Has1stRecord) { DestroyLoopObjects(); } }
// ------------------------------ Public functions ------------------------------ /// <summary> /// Instantiate 2 lane surfaces (current chord, looped chord) from recording-data and keep scaling it by a coroutine upwards from zero until stopped. Writes into recording (!). /// </summary> /// <param name="recording">Recording data.</param> /// <param name="chordObjects">List to add the new chord objects.</param> public void CreateChordObjectTwice(Recording recording, List <ChordObject>[] chordObjects, int trackLayer) { // 0. Refs var fields = Player.inst.curFieldSet; var ID = recording.fieldID; var parent = MeshRef.inst.recordObj_parent; var material = MeshRef.inst.recordObjs_mat[trackLayer]; var pos1 = Player.inst.transform.position; var pos2 = Recorder.inst.NextLoopPosition(recording.sequencer, recording.start); var layer1 = LayerMask.NameToLayer(MeshRef.inst.highlightSurfaces_layer); var renderQueue1 = MeshRef.inst.highlightSurfaces_renderQueue + 1; var layer2 = LayerMask.NameToLayer(MeshRef.inst.recordLayer); //var layer = 8; var collider = true; var visible = true; var tag = MeshRef.inst.chordObjTag; // 1. Instantiate var obj1 = MeshCreation.CreateLaneSurface(fields, ID, "ChordObject", parent, material, visible, collider, tag, 1f, layer1, renderQueue1).gameObject; var obj2 = MeshCreation.CreateLaneSurface(fields, ID, "ChordObject", parent, material, visible, collider, tag, 1f, layer2).gameObject; var recordObject2 = ChordObject.Create(obj2, null, pos2, ID, recording.notes, recording.sequencer, trackLayer, recording.start, recording.end, recording.loopStart, recording.loopEnd_extended); var recordObject1 = ChordObject.Create(obj1, recordObject2, pos1, ID, recording.notes, recording.sequencer, trackLayer, recording.start, recording.end, recording.loopStart, recording.loopEnd_extended); recordObject1.hasRespawned = true; // 2. Add to list chordObjects[trackLayer].Add(recordObject1); chordObjects[trackLayer].Add(recordObject2); // 3. Edit recording / Start scaling recording.obj = recordObject1; // Nur für scaling-coroutine recording.loopObj = recordObject2; // Nur für scaling-coroutine recording.scaleRoutine = StartCoroutine(ScaleChordObject(recordObject1, recordObject2)); }
/// <summary> /// Delete over time. Make transparent and delete after that. /// </summary> /// <param name="chordObj"></param> /// <returns></returns> public IEnumerator DeleteRoutine(ChordObject chordObj) { chordObj.isBeingDeleted = true; float timer = 0; float maxTime = UIManager.inst.deleteRecordTime; bool hasExactlyOneChord = HasExactlyOneChord; // 1. Fade out chordObject (& loopObject) while (timer < maxTime) { var curveValue = MeshRef.inst.deleteChordCurve.Evaluate(timer / maxTime); var chordColorLerp = Color.Lerp(Color.black * 0, MeshRef.inst.recordColor, curveValue); // chordObject chordObj.meshRenderer.material.color = chordColorLerp; // loopObject if (hasExactlyOneChord) { foreach(LoopObject loopObject in loopObjects) { loopObject.meshRenderer.material.color = chordColorLerp; } } timer += Time.deltaTime; yield return null; } // 2. Destroy RemoveRecord(chordObj); }
/// <summary> /// Destroy a single chordObject (and its douplicate). /// </summary> /// <param name="obj"></param> public void DestroyChordObject(ChordObject obj) { Destroy(obj.obj); Recorder.inst.chordObjects[obj.trackLayer].Remove(obj); if (obj.douplicate != null) { Destroy(obj.douplicate.obj); Recorder.inst.chordObjects[obj.trackLayer].Remove(obj.douplicate); } }
// ------------------------------ Private functions ------------------------------ /// <summary> /// Increase the scale of the currently recorded object and its already instantiated loop object. /// </summary> /// <param name="obj1">Currently played chord-object.</param> /// <param name="obj2">Loop-chord-object.</param> /// <returns></returns> private IEnumerator ScaleChordObject(ChordObject obj1, ChordObject obj2) { var playerPos = Player.inst.transform.position.z; while (true) { var scale = playerPos - obj1.obj.transform.position.z; obj1.obj.transform.localScale = new Vector3(1, 1, scale); obj2.obj.transform.localScale = new Vector3(1, 1, scale); yield return(null); } }
// ------------------------------ Public functions ------------------------------ /// <summary> /// Add a ChordObject-component to the first parameter. Set remaining variables. /// </summary> public static ChordObject Create(GameObject obj, ChordObject douplicate, Vector3 position, int fieldID, int[] notes, Sequencer sequencer, int trackLayer, float start, float end, float loopStart, float loopEnd_extended) { // 1. ChordObject-Script var thisObj = obj.AddComponent <ChordObject>(); // 2. Variables thisObj.obj = obj; thisObj.douplicate = douplicate; thisObj.obj.transform.position = position; thisObj.fieldID = fieldID; thisObj.notes = notes; thisObj.sequencer = sequencer; thisObj.trackLayer = trackLayer; thisObj.start = start; thisObj.end = end; thisObj.loopStart = loopStart; thisObj.loopEnd_extended = loopEnd_extended; // 3. Mesh & colors thisObj.meshRenderer = obj.GetComponent <MeshRenderer>(); if (thisObj.meshRenderer == null) { Debug.LogError("mesh rend sollte nich null sein"); } var color = VisualController.inst.tracksColorPalette[trackLayer]; thisObj.meshRenderer.material.SetColor("_BaseColor", color); //thisObj.meshRenderer.material.color = color; thisObj.startColor = color; // 4. Move thisObj.obj.AddComponent <Move>(); // 5. Outline //var outline = thisObj.obj.AddComponent<Outline>(); //outline.OutlineMode = Outline.Mode.OutlineAll; //outline.OutlineWidth = 5f; //outline.OutlineColor = Color.red; return(thisObj); }
public void setChord(string name) { //public UIToggle[] guitarStringsToPlay; //public UISlider[] strings; stopPlay(); ChordObject cObj = new ChordObject(); cObj = chordDictionary [name]; int[] chordStrings = cObj.getStrings(); bool[] stringSettings = cObj.getStringSettings(); for (int i = 0; i < strings.Length; i++) //for each string { //set string to the value designated by this chord strings[i].value = fretPerc * chordStrings[i]; //set Toggle to the value designated by this chord guitarStringsToPlay[i].value = stringSettings[i]; } playChord(); }
public string addNewChord(string chordName) //adds a new chord with name 'chordName' and chord value equal to the current state of the strings to the dictionary { ChordObject tempChordObj = new ChordObject(); tempChordObj.setChord((int)(strings[0].value * (1 / fretPerc)), guitarStringsToPlay[0].value, (int)(strings[1].value * (1 / fretPerc)), guitarStringsToPlay[1].value, (int)(strings[2].value * (1 / fretPerc)), guitarStringsToPlay[2].value, (int)(strings[3].value * (1 / fretPerc)), guitarStringsToPlay[3].value, (int)(strings[4].value * (1 / fretPerc)), guitarStringsToPlay[4].value, (int)(strings[5].value * (1 / fretPerc)), guitarStringsToPlay[5].value); int i = 1; string newChordName = chordName; while (chordDictionary.ContainsKey(newChordName)) { newChordName = chordName + 'v' + i; i++; } chordDictionary.Add(newChordName, tempChordObj); return(newChordName); }
void setupDictionary() { ChordObject tempChordObj; string tempChord = "A"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 2, true, 2, true, 2, true, 0, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "A7"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 2, true, 0, true, 2, true, 0, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Am"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 1, true, 2, true, 2, true, 0, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "B"; tempChordObj = new ChordObject(); tempChordObj.setChord(2, true, 4, true, 4, true, 4, true, 2, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "B7"; tempChordObj = new ChordObject(); tempChordObj.setChord(2, true, 0, true, 2, true, 1, true, 2, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Bm"; tempChordObj = new ChordObject(); tempChordObj.setChord(2, true, 3, true, 4, true, 4, true, 2, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "C"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 1, true, 0, true, 2, true, 3, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "C7"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 1, true, 3, true, 2, true, 3, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Cm"; tempChordObj = new ChordObject(); tempChordObj.setChord(3, true, 4, true, 5, true, 5, true, 0, false, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "D"; tempChordObj = new ChordObject(); tempChordObj.setChord(2, true, 3, true, 2, true, 0, true, 0, false, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "D7"; tempChordObj = new ChordObject(); tempChordObj.setChord(2, true, 1, true, 2, true, 0, true, 0, false, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Dm"; tempChordObj = new ChordObject(); tempChordObj.setChord(1, true, 3, true, 2, true, 0, true, 0, false, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "E"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 0, true, 1, true, 2, true, 2, true, 0, true); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "E7"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 0, true, 1, true, 0, true, 2, true, 0, true); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Em"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, true, 0, true, 0, true, 2, true, 2, true, 0, true); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "F"; tempChordObj = new ChordObject(); tempChordObj.setChord(1, true, 1, true, 2, true, 3, true, 0, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "F7"; tempChordObj = new ChordObject(); tempChordObj.setChord(1, true, 4, true, 2, true, 3, true, 0, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Fm"; tempChordObj = new ChordObject(); tempChordObj.setChord(1, true, 1, true, 3, true, 0, true, 0, true, 0, false); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "G"; tempChordObj = new ChordObject(); tempChordObj.setChord(3, true, 0, true, 0, true, 0, true, 2, true, 3, true); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "G7"; tempChordObj = new ChordObject(); tempChordObj.setChord(1, true, 0, true, 0, true, 0, true, 2, true, 3, true); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "Gm"; tempChordObj = new ChordObject(); tempChordObj.setChord(3, true, 3, true, 0, true, 0, true, 1, true, 3, true); chordDictionary.Add(tempChord, tempChordObj); originalChords.Add(tempChord); tempChord = "reset"; tempChordObj = new ChordObject(); tempChordObj.setChord(0, false, 0, false, 0, false, 0, false, 0, false, 0, false); chordDictionary.Add(tempChord, tempChordObj); }