/// <summary> /// Change player visibility /// </summary> public void OnFieldChange(MusicField curField) { if (curField.isNotSpawning && curField.isSelectable) { curField.UpdatePlayingSurfaces(); } }
// ENVIRONMENT /// <summary> /// Create a complete field set, with parented gameObjects, line renderers and outer surfaces. Initialize with data (ID, positions, isCorner, isEdgeMid, lineRend) and return the field set. /// </summary> public static MusicField[] CreateFieldSet() { int fieldsCount = TunnelData.FieldsCount; MusicField[] fields = new MusicField[fieldsCount]; // 1. Create gameObjects, lineRenderers and initialize with data (no positions) for (int i = 0; i < fieldsCount; i++) { // Get data int ID = i; bool isCorner = MusicField.IsCorner(ID); bool isEdgeMid = MusicField.IsEdgeMid(ID); GameObject newObj = CreateContainer("Field" + ID, MeshRef.inst.musicFields_parent); LineRenderer lineRend = newObj.AddLineRenderer(0, MeshRef.inst.musicFields_mat, VisualController.inst.fieldThickness, false); // TO DO: init mit zwei empty lineRend positions? // Assign fields[ID] = new MusicField(ID, lineRend, isCorner, isEdgeMid); } // 2. Assign positions fields = MeshUpdate.UpdateFieldsVertices(fields); // 3. Surfaces CreateFieldsSurfaces(fields); return(fields); }
public void OnFieldChange(MusicField field) { if (Player.actionState == Player.ActionState.Play) { StopField(); PlayField(); } }
private void OnStopField_byRecord(MusicField field) { bool isPlayingLive = Player.inst.actionState == Player.ActionState.Play; if (!(isPlayingLive && Player.inst.curField.ID == field.ID)) { field.SetFieldVisibility(0, 1); } }
/// <summary> /// Set a given fields.positions, dependant on the tunnel vertices. Set fieldLength in TunnelData. /// </summary> public static MusicField[] UpdateFieldsVertices(MusicField[] fields) { if (TunnelData.vertices[0] == Vector3.zero) { Debug.LogError("Tried to get tunnel vertices too early, no collider yet."); } // Set field length float fieldLength = (TunnelData.vertices[1] - TunnelData.vertices[0]).magnitude / VisualController.inst.fieldsPerEdge; TunnelData.fieldLength = fieldLength; // 1. Iterate over edges for (int edgeInd = 0; edgeInd < TunnelData.vertices.Length; edgeInd++) { Vector3 edgeVec = TunnelData.vertices[(edgeInd + 1) % TunnelData.vertices.Length] - TunnelData.vertices[edgeInd]; Vector3 fieldVec = edgeVec.normalized * fieldLength; // 2. Interate over fields per edge for (int fieldInd = 0; fieldInd < VisualController.inst.fieldsPerEdge - 1; fieldInd++) { int ID = edgeInd * (VisualController.inst.fieldsPerEdge - 1) + fieldInd; Vector3 start, end, mid; Vector3[] positions; // Regular field bool isCorner = MusicField.IsCorner(ID); if (!isCorner) { start = TunnelData.vertices[edgeInd] + fieldVec * fieldInd; end = TunnelData.vertices[edgeInd] + fieldVec * (fieldInd + 1); mid = (start + end) / 2f; positions = new Vector3[] { start, end }; } // Corner else { int oppositeIndex = ExtensionMethods.Modulo(edgeInd - 1, TunnelData.vertices.Length); Vector3 oppositeEdgeVec = TunnelData.vertices[oppositeIndex] - TunnelData.vertices[edgeInd]; Vector3 oppositeFieldFec = oppositeEdgeVec.normalized * fieldLength; start = TunnelData.vertices[edgeInd] + oppositeFieldFec; mid = TunnelData.vertices[edgeInd]; end = TunnelData.vertices[edgeInd] + fieldVec; positions = new Vector3[] { start, mid, end }; } // Assign fields[ID].SetVertices(start, mid, end, positions); } } return(fields); }
// ----------------------------- Events ---------------------------- /// <summary> /// Highlight field when played by a loopObject. /// </summary> /// <param name="field"></param> private void OnPlayField_byRecord(MusicField field) { bool isPlayingLive = Player.inst.actionState == Player.ActionState.Play; if (!(isPlayingLive && Player.inst.curField.ID == field.ID)) { var opacity = recordFieldOpacity; var intensifier = recordFieldIntensifier; field.SetFieldVisibility(opacity, intensifier); } }
/// <summary> /// Move lineRenderer from back to front. Fold out fieldSurface when done. Set musicField-variables (e.g. isSpawning = false). /// </summary> private IEnumerator MoveFieldFromBackToFront(MusicField field, float spawnDistanceInBeats, float durationInBeats) { // 0. Start field.lineRend.enabled = true; float duration = spawnDistanceInBeats * LoopData.timePerQuarter; float timer = 0; float zPos = playerZpos + distancePerQuarter * spawnDistanceInBeats; // 1. Move lineRend to front while (timer < duration) { zPos -= moveSpeed * DeltaTime; field.SetLineRendZPos(zPos); timer += Time.deltaTime; yield return(null); } // 2. "Fold" out fieldSurface field.fieldSurface.enabled = true; timer = 0; duration = VisualController.inst.fieldFoldOutTime; while (timer < duration) { // scale up fieldSurface & move lineRend to front float remappedTimer = timer / duration; // remapped to 0-1 float curveValue = VisualController.inst.fieldFoldOutCurve.Evaluate(remappedTimer); // between 0-1 float curScale = curveValue.Remap(0, 1f, 0, field.height); // remapped to final field.fieldSurface.transform.localScale = new Vector3(1, 1, curScale); field.SetLineRendZPos(Player.inst.transform.position.z - curScale); timer += Time.deltaTime; yield return(null); } field.fieldSurface.transform.localScale = new Vector3(1, 1, field.height); field.SetLineRendZPos(Player.inst.transform.position.z - field.height); field.isNotSpawning = true; // aktiviere variablen }
/// <summary> /// Single rotation routine: Rotate in the given direction to the adjacent field, if possible. Get and set data (curID, fieldPos, ...), fire event. /// </summary> /// <param name="direction">[1 or -1]</param> private IEnumerable RotateToNextField(int direction) { // 1. Get next ID int nextID = MusicField.NextFieldID(curField.ID, direction); // 2. Selectable? if (curFieldSet[nextID].isSelectable) // TO DO: sollte hier nicht rein (?) { // 4. Set data (ID, ...) var data = PlayerData.SetDataByID(nextID); // FIRE EVENT GameEvents.inst.onChangeField?.Invoke(data); // TO DO: gehört hier nicht rein!!! // 3. Get target rotation var targetPos = data.mid; // 5. ROTATE TO ID float maxTime = 1.2f; float timer = 0; while (timer < maxTime) { RotateToTarget(targetPos); if (actionState == ActionState.Play) { StickToEdge(curPlaySide); } timer += Time.deltaTime; yield return(null); } } else { // TO DO: Perform NotDoable-Animation; } }
/// <summary> /// Create color for each field. Sorted like IDs. Corners are similar. Rest is a bit distant and similar, too. Constraints are in VisalController. /// </summary> /// <returns>RGB colors (Length == FieldsCount). Used for BaseColor and EmissiveColor of lineRend, fieldSurface and highlightSurface.</returns> public static Color[] ColorsInRange() { var vars = VisualController.inst; // 1. Corner colors float randHue = UnityEngine.Random.Range(0, 1f); ColorHSV curColor = new ColorHSV(randHue, vars.fieldsSaturation, vars.fieldsValue); ColorHSV[] cornerColors = new ColorHSV[vars.tunnelVertices]; for (int i = 0; i < cornerColors.Length; i++) { cornerColors[i] = new ColorHSV(curColor.hue, curColor.saturation, curColor.value); if (i == cornerColors.Length - 1) { break; } curColor.hue = (curColor.hue + vars.fieldsHue_CornerStep) % 1; } // 2. Distance curColor.hue = (curColor.hue + vars.fieldsHue_Corner2NoCornerDistance) % 1; // 3. NoCorner colors List <ColorHSV> noCornerColors = new List <ColorHSV>(); for (int i = 0; i < TunnelData.FieldsCount - vars.tunnelVertices; i++) { noCornerColors.Add( new ColorHSV(curColor.hue, curColor.saturation, curColor.value) ); curColor.hue = (curColor.hue + vars.fieldsHue_NoCornerStep) % 1; if ((i + 1) % vars.colorCount == 0) { float startHue = curColor.hue - vars.colorCount * vars.fieldsHue_NoCornerStep; curColor.hue = ExtensionMethods.Modulo(startHue, 1); } } // 4. Assign Color[] colors = new Color[TunnelData.FieldsCount]; int cornerCounter = 0; for (int i = 0; i < colors.Length; i++) { if (MusicField.IsCorner(i)) { ColorHSV color = cornerColors[cornerCounter]; colors[i] = Color.HSVToRGB(color.hue, color.saturation, color.value); cornerCounter++; } else { int randNoCornerIndex = UnityEngine.Random.Range(0, noCornerColors.Count); ColorHSV color = noCornerColors[randNoCornerIndex]; colors[i] = Color.HSVToRGB(color.hue, color.saturation, color.value); noCornerColors.Remove(color); } } return(colors); }
private void Start() { mf = gameObject.GetComponentInChildren <MusicField>(); pm = gameObject.GetComponentInChildren <PlayMusic>(); settings = GameObject.FindGameObjectWithTag("Settings").GetComponent <Settings>(); }