mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-24 02:25:18 +00:00
89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
using TMPro;
|
|
using Starpelly;
|
|
|
|
namespace HeavenStudio.Editor.Track
|
|
{
|
|
public class VolumeTimeline : MonoBehaviour
|
|
{
|
|
[Header("Components")]
|
|
private RectTransform rectTransform;
|
|
public TMP_InputField StartingVolume;
|
|
private RectTransform StartingVolumeRect;
|
|
|
|
public List<VolumeTimelineObj> volumeTimelineObjs = new List<VolumeTimelineObj>();
|
|
|
|
private bool firstUpdate;
|
|
|
|
void Start()
|
|
{
|
|
rectTransform = this.GetComponent<RectTransform>();
|
|
StartingVolumeRect = StartingVolume.GetComponent<RectTransform>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!firstUpdate)
|
|
{
|
|
UpdateStartingVolumeText();
|
|
firstUpdate = true;
|
|
}
|
|
|
|
if (Timeline.instance.userIsEditingInputField)
|
|
return;
|
|
|
|
if (Timeline.instance.timelineState.musicVolume && !Conductor.instance.NotStopped())
|
|
{
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(StartingVolumeRect, Input.mousePosition, Editor.instance.EditorCamera))
|
|
{
|
|
int increase = Mathf.RoundToInt(Input.mouseScrollDelta.y);
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
increase *= 5;
|
|
|
|
if (increase != 0)
|
|
{
|
|
GameManager.instance.Beatmap.musicVolume += increase;
|
|
UpdateStartingVolumeText();
|
|
UpdateStartingVolumeFromText(); // In case the scrolled-to value is invalid.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateStartingVolumeText()
|
|
{
|
|
StartingVolume.text = GameManager.instance.Beatmap.musicVolume.ToString();
|
|
}
|
|
|
|
public void UpdateStartingVolumeFromText()
|
|
{
|
|
// Failsafe against empty string.
|
|
if (String.IsNullOrEmpty(StartingVolume.text))
|
|
StartingVolume.text = "100";
|
|
|
|
var newVol = Convert.ToInt32(StartingVolume.text);
|
|
|
|
// Failsafe against invalid volume.
|
|
if (newVol > 100)
|
|
{
|
|
StartingVolume.text = "100";
|
|
newVol = 100;
|
|
}
|
|
else if (newVol < 0)
|
|
{
|
|
StartingVolume.text = "0";
|
|
newVol = 0;
|
|
}
|
|
|
|
GameManager.instance.Beatmap.musicVolume = newVol;
|
|
|
|
// In case the newVol ended up differing from the inputted string.
|
|
UpdateStartingVolumeText();
|
|
}
|
|
}
|
|
}
|