This commit is contained in:
FloatGaming
2026-07-26 03:44:27 +08:00
parent 86351dbd2a
commit add675e45d
223 changed files with 1960 additions and 10735 deletions
+271 -259
View File
@@ -2,18 +2,19 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class controllerSettings : MonoBehaviour
{
[Header("Inspector")]
public Button[] keyButtons; // assign 5 buttons in Inspector
public Text errorText; // UI text to show error/success messages
public Button[] keyButtons;
public Button secondary_track3Button;
public Text errorText;
[Header("Message Colors")]
public Color messageErrorColor = Color.red;
public Color messageSuccessColor = Color.green;
private Coroutine messageCoroutine = null;
[Header("Inspector")]
public Slider noteSpeedMultipler_slider;
@@ -22,236 +23,228 @@ public class controllerSettings : MonoBehaviour
public Button noteSpeed_IncreaseButton;
public Button noteSpeed_ResetButton;
// internal colors/order must match KeyBindingManager usage
private readonly string[] colors = new string[] { "red", "green", "yellow", "purple", "blue" };
private bool isRebinding = false;
private int rebindingIndex = -1;
private Coroutine blinkCoroutine = null;
// store previous key so we can restore if user cancels
private KeyCode previousKey = KeyCode.None;
private bool previousKeyValid = false;
// slider range
private const float NoteSpeedMin = 1f;
// Player-facing range is 1-3. NoteSpawner multiplies it by 2, so the real range is 2-6.
private const float NoteSpeedMax = 3f;
private const string NoteSpeedPrefKey = "noteSpeedMultiplier";
private const string NoteSpeedDefaultVersionKey = "noteSpeedMultiplierDefaultVersion";
private const int NoteSpeedDefaultVersion = 2;
private const float NoteSpeedDefault = 2.0f;
// continuous change
private Coroutine continuousChangeCoroutine = null;
private const float ContinuousInitialDelay = 0.5f; // increased to avoid accidental long-press
private const float ContinuousRepeatRate = 0.05f;
private const float StepAmount = 0.01f;
[Header("call dt prefab")]
public GameObject delayTapper_prefab;
public GameObject dt_to_put;
public Button launch_delayTapper;
public Text currentDelayText;
void Start()
{
// initialize button labels from KeyBindingManager
RefreshButtonLabels();
private readonly string[] colors = { "red", "green", "yellow", "purple", "blue" };
private readonly string[] bindingDisplayNames = { "轨道1键位", "轨道2键位", "轨道3键位", "轨道4键位", "轨道5键位", "轨道3键位2" };
// initialize errorText
if (errorText != null)
private const int SecondaryTrack3Slot = 5;
private const float NoteSpeedMin = 1f;
private const float NoteSpeedMax = 3f;
private const string NoteSpeedPrefKey = "noteSpeedMultiplier";
private const string NoteSpeedDefaultVersionKey = "noteSpeedMultiplierDefaultVersion";
private const int NoteSpeedDefaultVersion = 2;
private const float NoteSpeedDefault = 2.0f;
private const float ContinuousInitialDelay = 0.5f;
private const float ContinuousRepeatRate = 0.05f;
private const float StepAmount = 0.01f;
private bool isRebinding;
private int rebindingIndex = -1;
private KeyCode previousKey = KeyCode.None;
private bool previousKeyValid;
private Coroutine blinkCoroutine;
private Coroutine messageCoroutine;
private Coroutine continuousChangeCoroutine;
private void Start()
{
RefreshButtonLabels();
ClearMessage();
SetupKeyButtonListeners();
SetupNoteSpeedControls();
SetupDelayTapper();
RefreshDelayText();
}
private void OnDestroy()
{
if (keyButtons != null)
{
errorText.text = string.Empty;
foreach (Button button in keyButtons)
{
if (button != null) button.onClick.RemoveAllListeners();
}
}
// hook up listeners for key buttons
if (secondary_track3Button != null) secondary_track3Button.onClick.RemoveAllListeners();
if (noteSpeedMultipler_slider != null) noteSpeedMultipler_slider.onValueChanged.RemoveListener(OnNoteSpeedSliderChanged);
if (noteSpeed_DecreaseButton != null) noteSpeed_DecreaseButton.onClick.RemoveAllListeners();
if (noteSpeed_IncreaseButton != null) noteSpeed_IncreaseButton.onClick.RemoveAllListeners();
if (noteSpeed_ResetButton != null) noteSpeed_ResetButton.onClick.RemoveAllListeners();
if (launch_delayTapper != null) launch_delayTapper.onClick.RemoveAllListeners();
}
private void Update()
{
if (isRebinding && Input.GetMouseButtonDown(0) && !IsPointerOverAnyKeyButton())
{
CancelRebind();
return;
}
if (!isRebinding) return;
foreach (KeyCode kc in Enum.GetValues(typeof(KeyCode)))
{
if (kc >= KeyCode.Mouse0 && kc <= KeyCode.Mouse6) continue;
if (kc >= KeyCode.JoystickButton0 && kc <= KeyCode.Joystick8Button19) continue;
if (!Input.GetKeyDown(kc)) continue;
HandleRebindKey(kc);
break;
}
}
public void RefreshDelayText()
{
if (currentDelayText == null) return;
const string delayPrefsKey = "UserGlobalDelaySeconds";
if (PlayerPrefs.HasKey(delayPrefsKey))
{
float savedDelaySeconds = PlayerPrefs.GetFloat(delayPrefsKey, 0f);
int ms = Mathf.RoundToInt(savedDelaySeconds * 1000f);
currentDelayText.text = $"当前偏移:{(ms >= 0 ? "+" : "")}{ms}ms";
}
else
{
currentDelayText.text = "未设定偏移数值";
}
}
public void OnLaunchDelayTapperClicked()
{
if (delayTapper_prefab == null || dt_to_put == null)
{
Debug.LogWarning("[controllerSettings] Prefab or target container is missing!");
return;
}
GameObject instantiated = Instantiate(delayTapper_prefab, dt_to_put.transform);
Debug.Log($"[controllerSettings] Instantiated delay tapper prefab under {dt_to_put.name}");
delayTapperPrefab dtp = instantiated.GetComponent<delayTapperPrefab>();
if (dtp != null)
{
dtp.mainSettings = this;
}
}
private void SetupKeyButtonListeners()
{
if (keyButtons != null)
{
for (int i = 0; i < keyButtons.Length && i < colors.Length; i++)
{
int idx = i;
if (keyButtons[i] == null) continue;
keyButtons[i].onClick.RemoveAllListeners();
keyButtons[i].onClick.AddListener(() => OnKeyButtonClicked(idx));
}
}
// initialize slider
if (secondary_track3Button != null)
{
secondary_track3Button.onClick.RemoveAllListeners();
secondary_track3Button.onClick.AddListener(() => OnKeyButtonClicked(SecondaryTrack3Slot));
}
}
private void SetupNoteSpeedControls()
{
if (noteSpeedMultipler_slider != null)
{
noteSpeedMultipler_slider.minValue = NoteSpeedMin;
noteSpeedMultipler_slider.maxValue = NoteSpeedMax;
EnsureDefaultNoteSpeedPreference();
float saved = PlayerPrefs.GetFloat(NoteSpeedPrefKey, NoteSpeedDefault);
saved = Mathf.Clamp(saved, NoteSpeedMin, NoteSpeedMax);
float saved = Mathf.Clamp(PlayerPrefs.GetFloat(NoteSpeedPrefKey, NoteSpeedDefault), NoteSpeedMin, NoteSpeedMax);
noteSpeedMultipler_slider.value = saved;
UpdateNoteSpeedText(saved);
noteSpeedMultipler_slider.onValueChanged.RemoveAllListeners();
noteSpeedMultipler_slider.onValueChanged.AddListener(OnNoteSpeedSliderChanged);
// Add PointerUp event to save value when sliding ends (kept for compatibility)
EventTrigger trigger = noteSpeedMultipler_slider.gameObject.GetComponent<EventTrigger>();
if (trigger == null) trigger = noteSpeedMultipler_slider.gameObject.AddComponent<EventTrigger>();
trigger.triggers.RemoveAll(e => e.eventID == EventTriggerType.PointerUp);
var entry = new EventTrigger.Entry { eventID = EventTriggerType.PointerUp };
entry.callback.AddListener((data) => { OnNoteSpeedSliderPointerUp(); });
EventTrigger.Entry entry = new EventTrigger.Entry { eventID = EventTriggerType.PointerUp };
entry.callback.AddListener(_ => OnNoteSpeedSliderPointerUp());
trigger.triggers.Add(entry);
}
// setup buttons
if (noteSpeed_DecreaseButton != null)
{
noteSpeed_DecreaseButton.onClick.RemoveAllListeners();
noteSpeed_DecreaseButton.onClick.AddListener(() => ChangeNoteSpeedBy(-StepAmount));
AddButtonContinuousEvents(noteSpeed_DecreaseButton, -StepAmount);
}
if (noteSpeed_IncreaseButton != null)
{
noteSpeed_IncreaseButton.onClick.RemoveAllListeners();
noteSpeed_IncreaseButton.onClick.AddListener(() => ChangeNoteSpeedBy(StepAmount));
AddButtonContinuousEvents(noteSpeed_IncreaseButton, StepAmount);
}
if (noteSpeed_ResetButton != null)
{
noteSpeed_ResetButton.onClick.RemoveAllListeners();
noteSpeed_ResetButton.onClick.AddListener(() => ResetNoteSpeed());
}
// Initialize delay tapper button and display
if (launch_delayTapper != null)
{
launch_delayTapper.onClick.RemoveAllListeners();
launch_delayTapper.onClick.AddListener(OnLaunchDelayTapperClicked);
}
RefreshDelayText();
}
public void RefreshDelayText()
{
if (currentDelayText != null)
{
const string DELAY_PREFS_KEY = "UserGlobalDelaySeconds";
if (PlayerPrefs.HasKey(DELAY_PREFS_KEY))
{
float savedDelaySeconds = PlayerPrefs.GetFloat(DELAY_PREFS_KEY, 0f);
int ms = Mathf.RoundToInt(savedDelaySeconds * 1000f);
currentDelayText.text = $"当前偏移:{(ms >= 0 ? "+" : "")}{ms}ms";
}
else
{
currentDelayText.text = "未设定偏移数值";
}
noteSpeed_ResetButton.onClick.AddListener(ResetNoteSpeed);
}
}
public void OnLaunchDelayTapperClicked()
private void SetupDelayTapper()
{
if (delayTapper_prefab != null && dt_to_put != null)
{
GameObject instantiated = Instantiate(delayTapper_prefab, dt_to_put.transform);
Debug.Log($"[controllerSettings] Instantiated delay tapper prefab under {dt_to_put.name}");
// 获取 dtp 脚本并传递当前 settings 引用,以便保存时刷新 UI
delayTapperPrefab dtp = instantiated.GetComponent<delayTapperPrefab>();
if (dtp != null)
{
dtp.mainSettings = this;
}
}
else
{
Debug.LogWarning("[controllerSettings] Prefab or target container is missing!");
}
}
void OnDestroy()
{
if (keyButtons != null)
{
foreach (var b in keyButtons)
if (b != null) b.onClick.RemoveAllListeners();
}
if (noteSpeedMultipler_slider != null)
{
noteSpeedMultipler_slider.onValueChanged.RemoveListener(OnNoteSpeedSliderChanged);
// Do not remove EventTrigger to avoid affecting other listeners, but it's okay on destroy
}
if (noteSpeed_DecreaseButton != null) noteSpeed_DecreaseButton.onClick.RemoveAllListeners();
if (noteSpeed_IncreaseButton != null) noteSpeed_IncreaseButton.onClick.RemoveAllListeners();
if (noteSpeed_ResetButton != null) noteSpeed_ResetButton.onClick.RemoveAllListeners();
}
void Update()
{
// If waiting for a new key, also cancel if user clicks outside UI/buttons
if (isRebinding)
{
if (Input.GetMouseButtonDown(0))
{
if (!IsPointerOverAnyKeyButton())
{
// clicked outside the key buttons while rebinding -> cancel and restore
CancelRebind();
return;
}
}
}
if (!isRebinding) return;
// detect any keydown by iterating KeyCode values
foreach (KeyCode kc in Enum.GetValues(typeof(KeyCode)))
{
// ignore mouse buttons and joystick buttons
if (kc >= KeyCode.Mouse0 && kc <= KeyCode.Mouse6) continue;
if (kc >= KeyCode.JoystickButton0 && kc <= KeyCode.Joystick8Button19) continue;
if (Input.GetKeyDown(kc))
{
HandleRebindKey(kc);
break;
}
}
if (launch_delayTapper == null) return;
launch_delayTapper.onClick.RemoveAllListeners();
launch_delayTapper.onClick.AddListener(OnLaunchDelayTapperClicked);
}
private bool IsPointerOverAnyKeyButton()
{
if (EventSystem.current == null) return false;
var pointerData = new PointerEventData(EventSystem.current) { position = Input.mousePosition };
var results = new List<RaycastResult>();
PointerEventData pointerData = new PointerEventData(EventSystem.current) { position = Input.mousePosition };
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
if (results.Count == 0) return false;
foreach (var res in results)
foreach (RaycastResult result in results)
{
var go = res.gameObject;
// check if this gameobject is one of the keyButtons or a child of one
for (int i = 0; i < keyButtons.Length; i++)
GameObject go = result.gameObject;
if (IsPointerOverButton(go, secondary_track3Button)) return true;
if (keyButtons == null) continue;
foreach (Button button in keyButtons)
{
var btn = keyButtons[i];
if (btn == null) continue;
if (go == btn.gameObject || go.transform.IsChildOf(btn.transform))
return true;
if (IsPointerOverButton(go, button)) return true;
}
}
return false;
}
private static bool IsPointerOverButton(GameObject go, Button button)
{
return go != null && button != null && (go == button.gameObject || go.transform.IsChildOf(button.transform));
}
private void OnKeyButtonClicked(int index)
{
if (isRebinding) return; // ignore while another rebind in progress
if (index < 0 || index >= colors.Length) return;
if (isRebinding || !IsValidBindingSlot(index)) return;
isRebinding = true;
rebindingIndex = index;
// remember previous key so we can restore if user cancels
previousKey = KeyBindingManager.GetKeyForColor(colors[index]);
previousKey = GetKeyForSlot(index);
previousKeyValid = true;
// start blinking underscore on the clicked button
blinkCoroutine = StartCoroutine(BlinkUnderscore(index));
// show persistent prompt
ShowPersistentMessage("按下新按键", messageErrorColor);
}
@@ -259,6 +252,7 @@ public class controllerSettings : MonoBehaviour
{
Text txt = GetButtonText(index);
if (txt == null) yield break;
while (isRebinding && rebindingIndex == index)
{
txt.text = "_";
@@ -266,50 +260,89 @@ public class controllerSettings : MonoBehaviour
txt.text = "";
yield return new WaitForSeconds(0.25f);
}
// restore label when finished
RefreshButtonLabel(index);
}
private void HandleRebindKey(KeyCode key)
{
// ignore ESC
if (key == KeyCode.Escape)
{
CancelRebind();
return;
}
// check if key already assigned to another color
for (int i = 0; i < colors.Length; i++)
if (!IsValidBindingSlot(rebindingIndex)) return;
int conflictSlot = FindSlotByKey(key, rebindingIndex);
KeyCode oldKey = GetKeyForSlot(rebindingIndex);
if (conflictSlot >= 0)
{
if (i == rebindingIndex) continue;
KeyCode existing = KeyBindingManager.GetKeyForColor(colors[i]);
if (existing == key)
{
// conflict: reject and keep waiting
string msg = $"按键冲突:{KeyBindingManager.GetDisplayName(key)}已被分配给按键{i+1}。";
ShowMessage(msg, messageErrorColor, 2f);
StartCoroutine(FlashButtonInvalid(rebindingIndex));
return;
}
SetKeyForSlot(rebindingIndex, key);
SetKeyForSlot(conflictSlot, oldKey);
string msg = $"按键冲突:{KeyBindingManager.GetDisplayName(key)}已与{GetSlotDisplayName(conflictSlot)}互换。";
ShowMessage(msg, messageErrorColor, 2f);
StartCoroutine(FlashButtonInvalid(rebindingIndex));
}
else
{
SetKeyForSlot(rebindingIndex, key);
ClearMessage();
ShowMessage("按键设置已保存", messageSuccessColor, 2f);
}
// accept binding
KeyBindingManager.ChangeKeyBinding(colors[rebindingIndex], key);
// update UI labels
RefreshButtonLabel(rebindingIndex);
InputManager.Instance?.RefreshKeyLabels();
// clear persistent prompt and show success message
ClearMessage();
ShowMessage("按键设置已保存", messageSuccessColor, 2f);
// finish
previousKeyValid = false;
previousKey = KeyCode.None;
RefreshButtonLabels();
InputManager.Instance?.RefreshKeyLabels();
StopRebind();
}
private int FindSlotByKey(KeyCode key, int ignoredSlot)
{
for (int i = 0; i <= SecondaryTrack3Slot; i++)
{
if (i == ignoredSlot || !IsValidBindingSlot(i)) continue;
if (GetKeyForSlot(i) == key) return i;
}
return -1;
}
private bool IsValidBindingSlot(int index)
{
return (index >= 0 && index < colors.Length) || index == SecondaryTrack3Slot;
}
private KeyCode GetKeyForSlot(int index)
{
if (index == SecondaryTrack3Slot) return KeyBindingManager.GetSecondaryKeyForTrack3();
if (index >= 0 && index < colors.Length) return KeyBindingManager.GetKeyForColor(colors[index]);
return KeyCode.None;
}
private void SetKeyForSlot(int index, KeyCode key)
{
if (index == SecondaryTrack3Slot)
{
KeyBindingManager.ChangeSecondaryTrack3KeyBinding(key);
return;
}
if (index >= 0 && index < colors.Length)
{
KeyBindingManager.ChangeKeyBinding(colors[index], key);
}
}
private string GetSlotDisplayName(int index)
{
if (index >= 0 && index < bindingDisplayNames.Length) return bindingDisplayNames[index];
return $"键位{index + 1}";
}
private void ShowMessage(string message, Color color, float duration = 2f)
{
if (errorText == null) return;
@@ -327,25 +360,24 @@ public class controllerSettings : MonoBehaviour
t += Time.deltaTime;
yield return null;
}
errorText.text = string.Empty;
messageCoroutine = null;
}
// Show a persistent message (until explicitly cleared)
private void ShowPersistentMessage(string message, Color color)
{
if (errorText == null) return;
// stop any timed message
if (messageCoroutine != null)
{
StopCoroutine(messageCoroutine);
messageCoroutine = null;
}
errorText.text = message;
errorText.color = color;
}
// Clear any displayed message immediately
private void ClearMessage()
{
if (messageCoroutine != null)
@@ -353,29 +385,31 @@ public class controllerSettings : MonoBehaviour
StopCoroutine(messageCoroutine);
messageCoroutine = null;
}
if (errorText != null) errorText.text = string.Empty;
}
private IEnumerator FlashButtonInvalid(int index)
{
Button b = GetButton(index);
if (b == null) yield break;
Color original = b.image.color;
b.image.color = Color.red;
Button button = GetButton(index);
if (button == null || button.image == null) yield break;
Color original = button.image.color;
button.image.color = Color.red;
yield return new WaitForSeconds(0.35f);
b.image.color = original;
button.image.color = original;
}
private void CancelRebind()
{
// restore previous key if we have one
if (previousKeyValid && rebindingIndex >= 0 && rebindingIndex < colors.Length)
if (previousKeyValid && IsValidBindingSlot(rebindingIndex))
{
KeyBindingManager.ChangeKeyBinding(colors[rebindingIndex], previousKey);
SetKeyForSlot(rebindingIndex, previousKey);
InputManager.Instance?.RefreshKeyLabels();
ClearMessage();
ShowMessage("按键设置已保存", messageSuccessColor, 2f);
}
previousKeyValid = false;
previousKey = KeyCode.None;
StopRebind();
@@ -390,6 +424,7 @@ public class controllerSettings : MonoBehaviour
StopCoroutine(blinkCoroutine);
blinkCoroutine = null;
}
RefreshButtonLabels();
}
@@ -399,57 +434,49 @@ public class controllerSettings : MonoBehaviour
{
RefreshButtonLabel(i);
}
RefreshButtonLabel(SecondaryTrack3Slot);
}
// update RefreshButtonLabel to use display name
private void RefreshButtonLabel(int index)
{
Text txt = GetButtonText(index);
if (txt == null) return;
KeyCode k = KeyBindingManager.GetKeyForColor(colors[index]);
txt.text = KeyBindingManager.GetDisplayName(k);
txt.text = KeyBindingManager.GetDisplayName(GetKeyForSlot(index));
}
private Button GetButton(int index)
{
if (keyButtons == null) return null;
if (index < 0 || index >= keyButtons.Length) return null;
if (index == SecondaryTrack3Slot) return secondary_track3Button;
if (keyButtons == null || index < 0 || index >= keyButtons.Length) return null;
return keyButtons[index];
}
private Text GetButtonText(int index)
{
Button b = GetButton(index);
if (b == null) return null;
Text t = b.GetComponentInChildren<Text>();
return t;
Button button = GetButton(index);
return button != null ? button.GetComponentInChildren<Text>() : null;
}
private void OnNoteSpeedSliderChanged(float value)
{
UpdateNoteSpeedText(value);
// save on every change
SaveNoteSpeedValue(value);
}
private void OnNoteSpeedSliderPointerUp()
{
if (noteSpeedMultipler_slider != null)
{
float value = noteSpeedMultipler_slider.value;
PlayerPrefs.SetFloat(NoteSpeedPrefKey, value);
PlayerPrefs.Save();
}
if (noteSpeedMultipler_slider == null) return;
PlayerPrefs.SetFloat(NoteSpeedPrefKey, noteSpeedMultipler_slider.value);
PlayerPrefs.Save();
}
private void UpdateNoteSpeedText(float value)
{
if (noteSpeedMultipler_valueText != null)
{
// 将 0.5-2.0 映射为 50%-200% 的百分比显示
int percentage = Mathf.RoundToInt(value * 100f);
noteSpeedMultipler_valueText.text = $"{percentage}%";
}
if (noteSpeedMultipler_valueText == null) return;
int percentage = Mathf.RoundToInt(value * 100f);
noteSpeedMultipler_valueText.text = $"{percentage}%";
}
private void SaveNoteSpeedValue(float value)
@@ -462,44 +489,35 @@ public class controllerSettings : MonoBehaviour
private void ChangeNoteSpeedBy(float delta)
{
if (noteSpeedMultipler_slider == null) return;
float cur = noteSpeedMultipler_slider.value;
float step = StepAmount;
float newVal = cur;
float current = noteSpeedMultipler_slider.value;
float newValue = current;
const float eps = 1e-5f;
if (delta > 0f)
{
float ceilStep = Mathf.Ceil(cur / step) * step;
if (Mathf.Abs(cur - ceilStep) < eps)
{
newVal = Mathf.Min(cur + step, NoteSpeedMax);
}
else
{
newVal = Mathf.Min(ceilStep, NoteSpeedMax);
}
float ceilStep = Mathf.Ceil(current / StepAmount) * StepAmount;
newValue = Mathf.Abs(current - ceilStep) < eps
? Mathf.Min(current + StepAmount, NoteSpeedMax)
: Mathf.Min(ceilStep, NoteSpeedMax);
}
else if (delta < 0f)
{
float floorStep = Mathf.Floor(cur / step) * step;
if (Mathf.Abs(cur - floorStep) < eps)
{
newVal = Mathf.Max(cur - step, NoteSpeedMin);
}
else
{
newVal = Mathf.Max(floorStep, NoteSpeedMin);
}
float floorStep = Mathf.Floor(current / StepAmount) * StepAmount;
newValue = Mathf.Abs(current - floorStep) < eps
? Mathf.Max(current - StepAmount, NoteSpeedMin)
: Mathf.Max(floorStep, NoteSpeedMin);
}
newVal = Mathf.Clamp(newVal, NoteSpeedMin, NoteSpeedMax);
// round to 3 decimals for display and consistency
newVal = (float)System.Math.Round(newVal, 3);
noteSpeedMultipler_slider.value = newVal; // will trigger OnNoteSpeedSliderChanged and save
newValue = Mathf.Clamp(newValue, NoteSpeedMin, NoteSpeedMax);
newValue = (float)Math.Round(newValue, 3);
noteSpeedMultipler_slider.value = newValue;
}
private void ResetNoteSpeed()
{
if (noteSpeedMultipler_slider == null) return;
noteSpeedMultipler_slider.value = NoteSpeedDefault; // triggers change and save
noteSpeedMultipler_slider.value = NoteSpeedDefault;
SaveNoteSpeedValue(NoteSpeedDefault);
UpdateNoteSpeedText(NoteSpeedDefault);
}
@@ -527,30 +545,26 @@ public class controllerSettings : MonoBehaviour
PlayerPrefs.Save();
}
private void AddButtonContinuousEvents(Button btn, float delta)
private void AddButtonContinuousEvents(Button button, float delta)
{
EventTrigger trigger = btn.gameObject.GetComponent<EventTrigger>();
if (trigger == null) trigger = btn.gameObject.AddComponent<EventTrigger>();
EventTrigger trigger = button.gameObject.GetComponent<EventTrigger>();
if (trigger == null) trigger = button.gameObject.AddComponent<EventTrigger>();
// PointerDown -> start continuous change
var downEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerDown };
downEntry.callback.AddListener((data) => { StartContinuousChange(delta); });
EventTrigger.Entry downEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerDown };
downEntry.callback.AddListener(_ => StartContinuousChange(delta));
trigger.triggers.Add(downEntry);
// PointerUp -> stop continuous change
var upEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerUp };
upEntry.callback.AddListener((data) => { StopContinuousChange(); });
EventTrigger.Entry upEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerUp };
upEntry.callback.AddListener(_ => StopContinuousChange());
trigger.triggers.Add(upEntry);
// Also stop on PointerExit in case cursor leaves button while pressed
var exitEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerExit };
exitEntry.callback.AddListener((data) => { StopContinuousChange(); });
EventTrigger.Entry exitEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerExit };
exitEntry.callback.AddListener(_ => StopContinuousChange());
trigger.triggers.Add(exitEntry);
}
private void StartContinuousChange(float delta)
{
// perform immediate single step
ChangeNoteSpeedBy(delta);
if (continuousChangeCoroutine != null) StopCoroutine(continuousChangeCoroutine);
continuousChangeCoroutine = StartCoroutine(ContinuousChangeRoutine(delta));
@@ -558,11 +572,9 @@ public class controllerSettings : MonoBehaviour
private void StopContinuousChange()
{
if (continuousChangeCoroutine != null)
{
StopCoroutine(continuousChangeCoroutine);
continuousChangeCoroutine = null;
}
if (continuousChangeCoroutine == null) return;
StopCoroutine(continuousChangeCoroutine);
continuousChangeCoroutine = null;
}
private IEnumerator ContinuousChangeRoutine(float delta)