public void CreateEntities(IChartParser parser) { var taps = parser.Taps; var arctaps = parser.Arctaps; taps.Sort((item1, item2) => { return(item1.timing.CompareTo(item2.timing)); }); arctaps.Sort((item1, item2) => { return(item1.timing.CompareTo(item2.timing)); }); int tapCount = taps.Count; int arcTapCount = arctaps.Count; int tapIndex = 0; int arcTapIndex = 0; while (tapIndex < tapCount && arcTapIndex < arcTapCount) { TapRaw tap = taps[tapIndex]; ArctapRaw arctap = arctaps[arcTapIndex]; if (tap.timing == arctap.timing) { Entity tapEntity = CreateTapEntity(tap); Entity arctapEntity = CreateArcTapEntity(arctap); CreateConnection(tap, arctap, tapEntity, arctapEntity); tapIndex++; arcTapIndex++; } else if (tap.timing < arctap.timing) { CreateTapEntity(tap); tapIndex++; } else { CreateArcTapEntity(arctap); arcTapIndex++; } } while (tapIndex < tapCount) { CreateTapEntity(taps[tapIndex++]); } while (arcTapIndex < arcTapCount) { CreateArcTapEntity(arctaps[arcTapIndex++]); } }
public Entity CreateArcTapEntity(ArctapRaw arctap) { Entity tapEntity = em.Instantiate(arcTapNoteEntityPrefab); float x = Conversion.GetWorldX(arctap.position.x); float y = Conversion.GetWorldY(arctap.position.y); const float z = 0; float floorpos = PlayManager.Conductor.GetFloorPositionFromTiming(arctap.timing, arctap.timingGroup); int t1 = PlayManager.Conductor.GetFirstTimingFromFloorPosition(floorpos - Constants.RenderFloorPositionRange, arctap.timingGroup); int t2 = PlayManager.Conductor.GetFirstTimingFromFloorPosition(floorpos + Constants.RenderFloorPositionRange, arctap.timingGroup); int appearTime = (t1 < t2) ? t1 : t2; em.SetComponentData(tapEntity, new Translation() { Value = new float3(x, y, z) }); em.SetComponentData(tapEntity, new FloorPosition(floorpos)); em.SetComponentData(tapEntity, new TimingGroup(arctap.timingGroup)); em.SetComponentData(tapEntity, new AppearTime(appearTime)); em.SetComponentData(tapEntity, new ChartTime(arctap.timing)); em.SetComponentData(tapEntity, new ChartPosition(Conversion.GetWorldPos(arctap.position))); Entity shadowEntity = em.Instantiate(shadowEntityPrefab); em.SetComponentData(tapEntity, new ArcTapShadowReference(shadowEntity)); em.SetComponentData(shadowEntity, new TimingGroup(arctap.timingGroup)); em.SetComponentData(shadowEntity, new Translation() { Value = new float3(x, 0, z) }); em.SetComponentData(shadowEntity, new FloorPosition(floorpos)); PlayManager.ScoreHandler.tracker.noteCount++; return(tapEntity); }
public void CreateConnection(TapRaw tap, ArctapRaw arctap, Entity tapEntity, Entity arcTapEntity) { Entity lineEntity = em.Instantiate(connectionLineEntityPrefab); float floorpos = PlayManager.Conductor.GetFloorPositionFromTiming(arctap.timing, arctap.timingGroup); float x = Conversion.GetWorldX(arctap.position.x); float y = Conversion.GetWorldY(arctap.position.y) - 0.5f; const float z = 0; float dx = Conversion.TrackToX(tap.track) - x; float dy = -y; float3 direction = new float3(dx, dy, 0); float length = math.sqrt(dx * dx + dy * dy); int appearTime = em.GetComponentData <AppearTime>(tapEntity).value; em.SetComponentData(lineEntity, new Translation() { Value = new float3(x, y, z) }); em.AddComponentData(lineEntity, new NonUniformScale() { Value = new float3(1f, 1f, length) }); em.SetComponentData(lineEntity, new Rotation() { Value = quaternion.LookRotationSafe(direction, new Vector3(0, 0, 1)) }); em.AddComponentData(lineEntity, new FloorPosition(floorpos)); em.SetComponentData(lineEntity, new TimingGroup(arctap.timingGroup)); em.SetComponentData(lineEntity, new AppearTime(appearTime)); em.SetComponentData(tapEntity, new ConnectionReference(lineEntity)); em.SetComponentData(arcTapEntity, new ConnectionReference(lineEntity)); }