using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AK.Wwise; using DG.Tweening; using Dreamteck.Splines; using Ichni.UI; using SLSUtilities.WwiseAssistance; using TMPro; using Event = AK.Wwise.Event; namespace Ichni.Menu { public partial class OffsetEditor : MonoBehaviour { public int offset = 0; // 当前偏移量 public Event PlayMusicEvent; private uint _playingId; public float songTimeSegment = 0; public List noteTimeList; public List noteJudgedList; public bool canReset; public int iteration = 0; public float trackTime = 4; public GameObject offsetEditingContainer; public SplinePositioner trackPoint; public List noteList; public ValueModifier offsetModifier; public TMP_Text descriptionText; public TMP_Text largeOffsetHintText; public Button backButton; private void Awake() { for (var index = 0; index < noteList.Count; index++) { float notePercent = Mathf.Clamp01(noteTimeList[index] / trackTime); noteList[index].SetPercent(notePercent); } offsetModifier.SetUp(0, 1); offsetModifier.SetMinMax(-250, 250); offsetModifier.SetPrefixAndSuffix("", " ms", true); offsetModifier.updateValueAction = () => { offset = SettingsManager.instance.gameSettings.beatmapOffset = offsetModifier.GetValue(); largeOffsetHintText.gameObject.SetActive(Mathf.Abs(offset) > 50); }; backButton.onClick.AddListener(() => { Stop(); offsetEditingContainer.SetActive(false); gameObject.SetActive(false); MenuManager.instance.settingsUIPage.settingsWindowController.gameObject.SetActive(true); MenuManager.instance.settingsUIPage.settingsWindowController.gameplayButton.onClick.Invoke(); MenuManager.instance.settingsUIPage.settingsWindowController.buttonsContainer.gameObject.SetActive(true); }); } public void Play() { iteration = 0; _playingId = PlayMusicEvent.Post(gameObject, (uint)AkCallbackType.AK_EnableGetMusicPlayPosition | (uint)AkCallbackType.AK_MusicSyncEntry, OnMusicEvent, null); offsetModifier.SetValue(SettingsManager.instance.gameSettings.beatmapOffset); } void Update() { songTimeSegment = ((iteration - 1) * trackTime) + PlaySegment() / 1000f - (offset / 1000f); songTimeSegment %= trackTime; if (canReset && songTimeSegment >= -(offset / 1000f) && songTimeSegment < 0.5f) { canReset = false; for (int i = 0; i < noteList.Count; i++) { noteList[i].transform.GetChild(0).transform.localScale = Vector3.zero; noteList[i].transform.GetChild(0).GetComponent().color = new Color(1, 1, 1, 1); noteJudgedList[i] = false; } } trackPoint.SetPercent(Mathf.Clamp01(songTimeSegment / trackTime)); for (int i = 0; i < noteList.Count; i++) { //float notePercent = Mathf.Clamp01((noteTimeList[i] - offset) / trackTime); //noteList[i].SetPercent(notePercent); if (!noteJudgedList[i] && songTimeSegment >= noteTimeList[i]) { noteJudgedList[i] = true; AudioManager.Post(AK.EVENTS.DEFAULTTAP); noteList[i].transform.GetChild(0).transform.DOScale(0.5f, 0.2f).Play(); noteList[i].transform.GetChild(0).GetComponent().DOFade(0, 0.2f).Play(); } } } private void OnMusicEvent(object in_cookie, AkCallbackType in_type, AkCallbackInfo in_info) { if (in_type is AkCallbackType.AK_MusicSyncEntry) { canReset = true; iteration++; } } int PlaySegment() { AkSegmentInfo segmentInfo = new AkSegmentInfo(); AkSoundEngine.GetPlayingSegmentInfo(_playingId, segmentInfo, true); return segmentInfo.iCurrentPosition; } public void Stop() { if (_playingId != AkSoundEngine.AK_INVALID_PLAYING_ID) { AkSoundEngine.StopPlayingID(_playingId); } SettingsManager.instance.SaveGameSettings(); } private void OnApplicationQuit() { if (_playingId != AkSoundEngine.AK_INVALID_PLAYING_ID) { AkSoundEngine.StopPlayingID(_playingId); } } } }