/// <summary> /// 处理数据 /// </summary> /// <param name="str"></param> /// <returns></returns> SongTime[] Parse(string str) { string[] arr = str.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); List <SongTime> list = new List <SongTime>(); for (int i = 0; i < arr.Length; i++) { string[] per = arr[i].Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); string[] direction = per[1].Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < direction.Length; j++) { SongTime time = null; switch (direction[j].Length) { case 1: time = new SongTime(); time.direction = (DIRECTION)(int.Parse(direction[j])); break; case 2: time = new LongSongTime(); time.direction = (DIRECTION)(int.Parse(direction[j].Substring(0, 1))); string mode = direction[j].Substring(1, 1); (time as LongSongTime).type = (LONG_PRESS_TYPE)(int.Parse(mode)); break; case 3: Debug.Log("这里估计有问题~~"); Debug.Break(); break; } list.Add(time); time.showTime = float.Parse(per[0]); } } List <SongTime> deleteList = new List <SongTime>(); for (int i = 0, c = list.Count; i < c; i++) { LongSongTime lst = list[i] as LongSongTime; if (lst != null && lst.type == LONG_PRESS_TYPE.START) { bool found = false; for (int j = i + 1; j < c; j++) { LongSongTime elst = list[j] as LongSongTime; if (elst != null && elst.type == LONG_PRESS_TYPE.END && deleteList.IndexOf(elst) == -1 && elst.direction == lst.direction) { float timeDiff = elst.showTime - lst.showTime; lst.PressTime = timeDiff; deleteList.Add(elst); found = true; break; } } if (!found) { Debug.LogWarning("没有结束箭头。请检查数据~~"); } } } for (int i = 0, c = deleteList.Count; i < c; i++) { list.Remove(deleteList[i]); } deleteList.Clear(); deleteList = null; SongTime[] result = list.ToArray(); return(result); }
public void reset() { // reset start time start = DateTime.Now; songtime = new SongTime(); }
public PPTime() { // get start time start = DateTime.Now; songtime = new SongTime(); }
internal void SetSongTime(SongTime songTime) { this.songTime = songTime; }
public override double poll() { // checks int msFromStart = (DateTime.Now - start).Milliseconds; SongTime now = new SongTime(); switch (mode) { case (int)LFOModes.Hz: { position = (msFromStart / (speed * 1000)); break; } case (int)LFOModes.Tick: { position = (now.CurrentTick / speed); break; } case (int)LFOModes.Tick256: { position = (now.CurrentTick / 256.0) / speed; break; } case (int)LFOModes.SubTick: { position = ((now.CurrentTick * now.CurrentSubTick) + now.CurrentSubTick) / speed; break; } case (int)LFOModes.Millisecond: { position = msFromStart / speed; break; } case (int)LFOModes.Second: { position = (msFromStart / 1000) / speed; break; } default: position = 0; break; } switch (shape) { case (int)LFOShapes.Sine: { return ((Math.Sin(position * 2 * Math.PI) * depth) / 2) + centre; } case (int)LFOShapes.SawDown: { return ((1 - (position - Math.Truncate(position))) * depth / 2) + centre; } case (int)LFOShapes.SawUp: { return ((position - ((int)position)) * depth / 2) + centre; } case (int)LFOShapes.Square: { if ((position - ((int)position)) > 0.5) return 1.0; else return 0; } } // else (throw an exception for problems?) return 0; }
// Update is called once per frame void FixedUpdate() { var d = hpBar.dimensions; d.Set(d.x + (dimensionsX - d.x) * .3f, hpBar.dimensions.y); hpBar.dimensions = d; Vector3 p = hpEff.transform.position; p.x = hpBar.transform.position.x + d.x / 100; hpEff.transform.position = p; if (BeatGame.instance.playState != BeatGame.PLAY_STATE.PLAYING || !alive) { return; } //runTime+= Time.fixedDeltaTime; runTime = BeatGame.instance.audioSource.time; #region 添加箭头 for (int i = beatIndex, c = curBeats.Length; i < c; i++) { SongTime songTime = curBeats[i]; if (runTime >= (songTime.showTime - moveToTopTime)) { if (i >= beatIndex) { beatIndex = i + 1; } Arrow arrow; if (songTime is LongSongTime) { arrow = PrefabPool.instance(longArrowPrefab).GetComponent <LongPressArrow>(); (arrow as LongPressArrow).subState = Arrow.STATE.READY; } else { arrow = PrefabPool.instance(arrowPrefab).GetComponent <Arrow>(); } arrow.SetState(Arrow.STATE.READY); arrow.gameObject.SetActive(true); arrow.gameObject.transform.parent = arrowContainer.transform; if (beatIndex == curBeats.Length) { arrow.isLastOne = true; } GameObject targetArrow = null; switch (songTime.direction) { case SongInfo.DIRECTION.DOWN: targetArrow = downArrow; break; case SongInfo.DIRECTION.LEFT: targetArrow = leftArrow; break; case SongInfo.DIRECTION.RIGHT: targetArrow = rightArrow; break; case SongInfo.DIRECTION.UP: targetArrow = upArrow; break; } if (songTime is LongSongTime) { arrow.GetComponent <LongPressArrow>().SetType(songTime.direction, (songTime as LongSongTime).PressTime * unitSpeedPerFrame * Application.targetFrameRate * 100); } else { arrow.GetComponent <Arrow>().SetType(songTime.direction); } arrow.transform.localPosition = new Vector3(targetArrow.transform.localPosition.x, bornPosY, 0); arrow.SetSongTime(songTime); arrows.Add(arrow); arrow.Init(runTime - PRESS_DELAY_TIME, unitSpeedPerSec); } else { break; } } #endregion #region 移动、删除箭头 for (int i = 0, c = arrows.Count; i < c; i++) { if (!alive) { return; } Arrow a = arrows[i]; a.Move(runTime); bool isLongPress = a is LongPressArrow; //超出底线,干掉 if ((!isLongPress && a.transform.localPosition.y >= (Global.SCREEN_HEIGHT + 1f)) || (isLongPress && a.transform.localPosition.y >= (Global.SCREEN_HEIGHT + 1f + (a as LongPressArrow).height / 100)) ) { KillArrow(arrows[i]); } else if ((a.transform.position.y > (END_POSITION_Y + HIT_DISTANCE))) //超过顶部图标,判定MISS { if (a.state != Arrow.STATE.FAILED) { a.SetState(Arrow.STATE.FAILED); SetArrowResult(Global.TIMING_JUAGE_TYPE.MISS, a); } else if (isLongPress && (a as LongPressArrow).subState != Arrow.STATE.FAILED) { Vector3 pos = (a as LongPressArrow).GetSecondArrowPos(); if (pos.y > (END_POSITION_Y + HIT_DISTANCE)) { (a as LongPressArrow).subState = Arrow.STATE.FAILED; SetArrowResult(Global.TIMING_JUAGE_TYPE.MISS, a); } } } else if (DataUtils.isAutoMode && DataUtils.mode == Global.MODE.MODE_1P) //自动模式 { if (a is LongPressArrow) { LongPressArrow l = a as LongPressArrow; switch (l.state) { case Arrow.STATE.READY: if ((a as LongPressArrow).IsPerfectTime(true)) { PressKey(a.songTime.direction, JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN); //Debug.Log("长按:" + a.songTime.direction + "时间:" + runTime); } break; case Arrow.STATE.PRESSING: if (GetJuade(Mathf.Abs(l.GetSecondArrowPos().y - END_POSITION_Y)) == Global.TIMING_JUAGE_TYPE.PREFECT) //if ((a as LongPressArrow).IsPerfectTime(false)) { PressKey(a.songTime.direction, JoystickManager.JOYSTICK_KEY_STATE.KEY_UP); //Debug.Log("长按结束:" + a.songTime.direction + "时间:" + runTime); } break; } } else { if (a.IsPerfectTime()) { PressKey(a.songTime.direction, JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN); } } if (a is LongPressArrow) { LongPressArrow l = a as LongPressArrow; if (a.state == Arrow.STATE.PRESSING) { if (l.pressingTime != 0 && (runTime - l.pressingTime) > 0.25f) { SetArrowResult(Global.TIMING_JUAGE_TYPE.PREFECT, a, false); l.pressingTime = runTime; } } } } } if (deleteArrows.Count > 0) { for (int i = 0, c = deleteArrows.Count; i < c; i++) { arrows.Remove(deleteArrows[i]); } deleteArrows.Clear(); } #endregion }