mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:37:37 +02:00
Tempo change? (Don't update very buggy)
This commit is contained in:
56
Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs
Normal file
56
Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
namespace RhythmHeavenMania.Editor.Track
|
||||
{
|
||||
public class TempoTimeline : MonoBehaviour
|
||||
{
|
||||
[Header("Components")]
|
||||
private RectTransform rectTransform;
|
||||
[SerializeField] private RectTransform RefTempoChange;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rectTransform = this.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main))
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
AddTempoChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddTempoChange()
|
||||
{
|
||||
GameObject tempoChange = Instantiate(RefTempoChange.gameObject, this.transform);
|
||||
|
||||
tempoChange.transform.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.TempoLayerCol.Hex2RGB();
|
||||
tempoChange.transform.GetChild(1).GetComponent<Image>().color = EditorTheme.theme.properties.TempoLayerCol.Hex2RGB();
|
||||
tempoChange.transform.GetChild(2).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.TempoLayerCol.Hex2RGB();
|
||||
|
||||
tempoChange.SetActive(true);
|
||||
tempoChange.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, tempoChange.transform.position.y);
|
||||
tempoChange.transform.localPosition = new Vector3(Starpelly.Mathp.Round2Nearest(tempoChange.transform.localPosition.x, 0.25f), tempoChange.transform.localPosition.y);
|
||||
|
||||
TempoTimelineObj tempoTimelineObj = tempoChange.AddComponent<TempoTimelineObj>();
|
||||
|
||||
Beatmap.TempoChange tempoC = new Beatmap.TempoChange();
|
||||
tempoC.beat = tempoChange.transform.localPosition.x;
|
||||
tempoC.tempo = GameManager.instance.Beatmap.bpm;
|
||||
|
||||
tempoTimelineObj.tempoChange = tempoC;
|
||||
GameManager.instance.Beatmap.tempoChanges.Add(tempoC);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10dd19278a802c24fbeb39d1ccb23219
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/LevelEditor/Timeline/TempoTimelineObj.cs
Normal file
45
Assets/Scripts/LevelEditor/Timeline/TempoTimelineObj.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using TMPro;
|
||||
|
||||
namespace RhythmHeavenMania.Editor.Track
|
||||
{
|
||||
public class TempoTimelineObj : MonoBehaviour
|
||||
{
|
||||
[Header("Components")]
|
||||
[SerializeField] private RectTransform rectTransform;
|
||||
[SerializeField] private TMP_Text tempoTXT;
|
||||
|
||||
public Beatmap.TempoChange tempoChange;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
tempoTXT = transform.GetChild(2).GetComponent<TMP_Text>();
|
||||
UpdateTempo();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main))
|
||||
{
|
||||
float newTempo = Input.mouseScrollDelta.y;
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
newTempo *= 5f;
|
||||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
newTempo /= 100f;
|
||||
|
||||
tempoChange.tempo += newTempo;
|
||||
}
|
||||
UpdateTempo();
|
||||
}
|
||||
|
||||
private void UpdateTempo()
|
||||
{
|
||||
tempoTXT.text = $"{tempoChange.tempo} BPM";
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/LevelEditor/Timeline/TempoTimelineObj.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/Timeline/TempoTimelineObj.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfe88f36dac55f44dac7fe958fe3c228
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
479
Assets/Scripts/LevelEditor/Timeline/Timeline.cs
Normal file
479
Assets/Scripts/LevelEditor/Timeline/Timeline.cs
Normal file
@ -0,0 +1,479 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
namespace RhythmHeavenMania.Editor.Track
|
||||
{
|
||||
public class Timeline : MonoBehaviour
|
||||
{
|
||||
[Header("Song Positions")]
|
||||
[SerializeField] private TMP_Text SongBeat;
|
||||
[SerializeField] private TMP_Text SongPos;
|
||||
[SerializeField] private TMP_Text CurrentTempo;
|
||||
[SerializeField] private RectTransform StartingBPM;
|
||||
|
||||
[Header("Timeline Properties")]
|
||||
private float lastBeatPos = 0;
|
||||
private Vector2 lastMousePos;
|
||||
public List<TimelineEventObj> eventObjs = new List<TimelineEventObj>();
|
||||
private bool lastFrameDrag;
|
||||
public int LayerCount = 4;
|
||||
public bool metronomeEnabled;
|
||||
public bool resizable;
|
||||
|
||||
[Header("Timeline Components")]
|
||||
[SerializeField] private RectTransform TimelineSlider;
|
||||
[SerializeField] private TMP_Text TimelinePlaybackBeat;
|
||||
[SerializeField] private RectTransform TimelineContent;
|
||||
[SerializeField] private RectTransform TimelineSongPosLineRef;
|
||||
[SerializeField] private RectTransform TimelineEventObjRef;
|
||||
[SerializeField] private RectTransform LayersRect;
|
||||
private RectTransform TimelineSongPosLine;
|
||||
|
||||
[Header("Timeline Playbar")]
|
||||
public Button PlayBTN;
|
||||
public Button PauseBTN;
|
||||
public Button StopBTN;
|
||||
public Button MetronomeBTN;
|
||||
public Button AutoplayBTN;
|
||||
public Button SelectionsBTN;
|
||||
public Button TempoChangeBTN;
|
||||
public Button MusicVolumeBTN;
|
||||
|
||||
public static Timeline instance { get; private set; }
|
||||
|
||||
#region Initializers
|
||||
|
||||
public void UpdateLevelInfo()
|
||||
{
|
||||
StartingBPM.GetChild(0).GetComponent<TMP_Text>().text = GameManager.instance.Beatmap.bpm.ToString();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
||||
{
|
||||
var entity = GameManager.instance.Beatmap.entities[i];
|
||||
var e = GameManager.instance.Beatmap.entities[i];
|
||||
|
||||
AddEventObject(e.datamodel, false, new Vector3(e.beat, -e.track * LayerHeight()), e, false, RandomID());
|
||||
}
|
||||
|
||||
TimelineSlider.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
||||
TimelineSlider.GetChild(1).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
||||
TimelineSlider.GetChild(2).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
||||
TimelineSlider.GetChild(3).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
||||
TimelineSongPosLineRef.GetComponent<Image>().color = EditorTheme.theme.properties.CurrentTimeMarkerCol.Hex2RGB();
|
||||
|
||||
PlayBTN.onClick.AddListener(delegate
|
||||
{
|
||||
if (Conductor.instance.isPaused)
|
||||
PlayCheck(false);
|
||||
else
|
||||
PlayCheck(true);
|
||||
});
|
||||
PauseBTN.onClick.AddListener(delegate
|
||||
{
|
||||
if (Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
||||
PlayCheck(false);
|
||||
});
|
||||
StopBTN.onClick.AddListener(delegate
|
||||
{
|
||||
if (Conductor.instance.isPlaying || Conductor.instance.isPaused)
|
||||
PlayCheck(true);
|
||||
});
|
||||
|
||||
MetronomeBTN.onClick.AddListener(delegate
|
||||
{
|
||||
if (!Conductor.instance.metronome)
|
||||
{
|
||||
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = "009FC6".Hex2RGB();
|
||||
Conductor.instance.metronome = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
||||
Conductor.instance.metronome = false;
|
||||
}
|
||||
});
|
||||
AutoplayBTN.onClick.AddListener(delegate
|
||||
{
|
||||
if (!GameManager.instance.autoplay)
|
||||
{
|
||||
AutoplayBTN.GetComponent<Animator>().Play("Idle", 0, 0);
|
||||
GameManager.instance.autoplay = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AutoplayBTN.GetComponent<Animator>().Play("Disabled", 0, 0);
|
||||
GameManager.instance.autoplay = false;
|
||||
}
|
||||
});
|
||||
|
||||
Tooltip.AddTooltip(SongBeat.gameObject, "Current Beat");
|
||||
Tooltip.AddTooltip(SongPos.gameObject, "Current Time");
|
||||
Tooltip.AddTooltip(CurrentTempo.gameObject, "Current Tempo (BPM)");
|
||||
|
||||
Tooltip.AddTooltip(PlayBTN.gameObject, "Play <color=#adadad>[Space]</color>");
|
||||
Tooltip.AddTooltip(PauseBTN.gameObject, "Pause <color=#adadad>[Shift + Space]</color>");
|
||||
Tooltip.AddTooltip(StopBTN.gameObject, "Stop <color=#adadad>[Space]</color>");
|
||||
|
||||
Tooltip.AddTooltip(MetronomeBTN.gameObject, "Metronome");
|
||||
Tooltip.AddTooltip(AutoplayBTN.gameObject, "Autoplay");
|
||||
|
||||
Tooltip.AddTooltip(SelectionsBTN.gameObject, "Tool: Selection <color=#adadad>[1]</color>");
|
||||
Tooltip.AddTooltip(TempoChangeBTN.gameObject, "Tool: Tempo Change <color=#adadad>[2]</color>");
|
||||
Tooltip.AddTooltip(MusicVolumeBTN.gameObject, "Tool: Music Volume <color=#adadad>[3]</color>");
|
||||
|
||||
SetTimeButtonColors(true, false, false);
|
||||
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
||||
|
||||
UpdateLevelInfo();
|
||||
}
|
||||
|
||||
public static string RandomID()
|
||||
{
|
||||
return Starpelly.Random.Strings.RandomString(Starpelly.Enums.Strings.StringType.Alphanumeric, 128);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
||||
{
|
||||
SongBeat.text = $"Beat {string.Format("{0:0.000}", TimelineSlider.localPosition.x)}";
|
||||
SongPos.text = FormatTime(Conductor.instance.GetSongPosFromBeat(TimelineSlider.localPosition.x));
|
||||
}
|
||||
else
|
||||
{
|
||||
SongBeat.text = $"Beat {string.Format("{0:0.000}", Conductor.instance.songPositionInBeats)}";
|
||||
SongPos.text = FormatTime(Conductor.instance.songPosition);
|
||||
}
|
||||
|
||||
SliderControl();
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
PlayCheck(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayCheck(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetMouseButton(1) && !Conductor.instance.isPlaying && CheckIfMouseInTimeline())
|
||||
{
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(TimelineContent, Input.mousePosition, Editor.instance.EditorCamera, out lastMousePos);
|
||||
TimelineSlider.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(lastMousePos.x + 0.12f, 0.25f), 0, Mathf.Infinity), TimelineSlider.transform.localPosition.y);
|
||||
|
||||
if (TimelineSlider.localPosition.x != lastBeatPos)
|
||||
Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x);
|
||||
|
||||
lastBeatPos = TimelineSlider.localPosition.x;
|
||||
}
|
||||
|
||||
float moveSpeed = 750;
|
||||
if (Input.GetKey(KeyCode.LeftShift)) moveSpeed *= 2;
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftArrow))
|
||||
{
|
||||
TimelineContent.transform.localPosition += new Vector3(moveSpeed * Time.deltaTime, 0);
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.RightArrow))
|
||||
{
|
||||
TimelineContent.transform.localPosition += new Vector3(-moveSpeed * Time.deltaTime, 0);
|
||||
}
|
||||
|
||||
if (Conductor.instance.isPlaying)
|
||||
TimelineContent.transform.localPosition = new Vector3((-Conductor.instance.songPositionInBeats * 100) + 200, TimelineContent.transform.localPosition.y);
|
||||
|
||||
TimelineContent.transform.localPosition = new Vector3(Mathf.Clamp(TimelineContent.transform.localPosition.x, Mathf.NegativeInfinity, 0), TimelineContent.transform.localPosition.y);
|
||||
|
||||
CurrentTempo.text = $" = {Conductor.instance.songBpm}";
|
||||
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPM, Input.mousePosition, Camera.main))
|
||||
{
|
||||
float increase = Input.mouseScrollDelta.y;
|
||||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
increase /= 100f;
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
increase *= 5f;
|
||||
|
||||
GameManager.instance.Beatmap.bpm += increase;
|
||||
UpdateLevelInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private void SliderControl()
|
||||
{
|
||||
TimelinePlaybackBeat.text = $"Beat {string.Format("{0:0.000}", TimelineSlider.localPosition.x)}";
|
||||
|
||||
if (TimelineSongPosLine != null)
|
||||
{
|
||||
TimelineSongPosLine.transform.localPosition = new Vector3(Conductor.instance.songPositionInBeats, TimelineSongPosLine.transform.localPosition.y);
|
||||
TimelineSongPosLine.transform.localScale = new Vector3(1f / TimelineContent.transform.localScale.x, TimelineSongPosLine.transform.localScale.y, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#region PlayChecks
|
||||
public void PlayCheck(bool fromStart)
|
||||
{
|
||||
if (fromStart)
|
||||
{
|
||||
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
||||
{
|
||||
Play(false, TimelineSlider.transform.localPosition.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stop(TimelineSlider.transform.localPosition.x);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Conductor.instance.isPlaying)
|
||||
{
|
||||
if (TimelineSongPosLine == null)
|
||||
{
|
||||
Play(false, TimelineSlider.transform.localPosition.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
Play(false, TimelineSongPosLine.transform.localPosition.x);
|
||||
}
|
||||
}
|
||||
else if (!Conductor.instance.isPaused)
|
||||
{
|
||||
Pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(bool fromStart, float time)
|
||||
{
|
||||
// if (fromStart) Stop();
|
||||
|
||||
if (!Conductor.instance.isPaused)
|
||||
{
|
||||
TimelineSongPosLine = Instantiate(TimelineSongPosLineRef, TimelineSongPosLineRef.parent).GetComponent<RectTransform>();
|
||||
TimelineSongPosLine.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
GameManager.instance.Play(time);
|
||||
|
||||
SetTimeButtonColors(false, true, true);
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
// isPaused = true;
|
||||
GameManager.instance.Pause();
|
||||
|
||||
SetTimeButtonColors(true, false, true);
|
||||
}
|
||||
|
||||
public void Stop(float time)
|
||||
{
|
||||
// isPaused = true;
|
||||
// timelineSlider.value = 0;
|
||||
|
||||
if (TimelineSongPosLine != null)
|
||||
Destroy(TimelineSongPosLine.gameObject);
|
||||
|
||||
GameManager.instance.Stop(time);
|
||||
|
||||
SetTimeButtonColors(true, false, false);
|
||||
}
|
||||
|
||||
public void SetTimeButtonColors(bool playEnabled, bool pauseEnabled, bool stopEnabled)
|
||||
{
|
||||
if (playEnabled)
|
||||
{
|
||||
PlayBTN.transform.GetChild(0).GetComponent<Image>().color = Color.green;
|
||||
PlayBTN.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
||||
PlayBTN.enabled = false;
|
||||
}
|
||||
|
||||
if (pauseEnabled)
|
||||
{
|
||||
PauseBTN.enabled = true;
|
||||
PauseBTN.transform.GetChild(0).GetComponent<Image>().color = Color.blue;
|
||||
}
|
||||
else
|
||||
{ PauseBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
||||
PauseBTN.enabled = false;
|
||||
}
|
||||
|
||||
if (stopEnabled)
|
||||
{
|
||||
StopBTN.enabled = true;
|
||||
StopBTN.transform.GetChild(0).GetComponent<Image>().color = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
StopBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
||||
StopBTN.enabled = false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Extras
|
||||
private string FormatTime(float time)
|
||||
{
|
||||
int minutes = (int)time / 60;
|
||||
int seconds = (int)time - 60 * minutes;
|
||||
int milliseconds = (int)(1000 * (time - minutes * 60 - seconds));
|
||||
return string.Format("{0:00}:{1:00}:{2:000}", minutes, seconds, milliseconds);
|
||||
}
|
||||
|
||||
public bool CheckIfMouseInTimeline()
|
||||
{
|
||||
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineContent.transform.parent.gameObject.GetComponent<RectTransform>(), Input.mousePosition, Camera.main));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public TimelineEventObj AddEventObject(string eventName, bool dragNDrop = false, Vector3 pos = new Vector3(), Beatmap.Entity entity = null, bool addEvent = false, string eventId = "")
|
||||
{
|
||||
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
|
||||
g.transform.localPosition = pos;
|
||||
g.transform.GetChild(3).GetComponent<TMP_Text>().text = eventName.Split('/')[1];
|
||||
|
||||
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
|
||||
|
||||
if (eventName.Split(1) == "switchGame")
|
||||
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(2));
|
||||
else
|
||||
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0));
|
||||
|
||||
Minigames.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
||||
|
||||
if (gameAction != null)
|
||||
{
|
||||
if (gameAction.resizable == false)
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
||||
float length = gameAction.defaultLength;
|
||||
eventObj.length = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
eventObj.resizable = true;
|
||||
if (entity != null && gameAction.defaultLength != entity.length && dragNDrop == false)
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(entity.length, LayerHeight());
|
||||
}
|
||||
else
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.SetActive(true);
|
||||
|
||||
if (dragNDrop)
|
||||
{
|
||||
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
g.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
|
||||
|
||||
Selections.instance.ClickSelect(eventObj);
|
||||
eventObj.moving = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.eventObj = g.GetComponent<TimelineEventObj>();
|
||||
entity.track = (int)(g.transform.localPosition.y / LayerHeight() * -1);
|
||||
}
|
||||
|
||||
if (addEvent)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
Beatmap.Entity en = new Beatmap.Entity();
|
||||
en.datamodel = eventName;
|
||||
en.eventObj = eventObj;
|
||||
|
||||
GameManager.instance.Beatmap.entities.Add(en);
|
||||
GameManager.instance.SortEventsList();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameManager.instance.Beatmap.entities.Add(entity);
|
||||
GameManager.instance.SortEventsList();
|
||||
}
|
||||
}
|
||||
|
||||
Editor.EventObjs.Add(eventObj);
|
||||
eventObjs.Add(eventObj);
|
||||
|
||||
eventObj.eventObjID = eventId;
|
||||
|
||||
return eventObj;
|
||||
}
|
||||
|
||||
public void DestroyEventObject(Beatmap.Entity entity)
|
||||
{
|
||||
Editor.EventObjs.Remove(entity.eventObj);
|
||||
GameManager.instance.Beatmap.entities.Remove(entity);
|
||||
Timeline.instance.eventObjs.Remove(entity.eventObj);
|
||||
|
||||
Destroy(entity.eventObj.gameObject);
|
||||
GameManager.instance.SortEventsList();
|
||||
}
|
||||
|
||||
public bool IsMouseAboveEvents()
|
||||
{
|
||||
return Timeline.instance.eventObjs.FindAll(c => c.mouseHovering == true).Count > 0;
|
||||
}
|
||||
|
||||
public bool InteractingWithEvents()
|
||||
{
|
||||
return eventObjs.FindAll(c => c.moving == true).Count > 0 || eventObjs.FindAll(c => c.resizing == true).Count > 0;
|
||||
}
|
||||
|
||||
public float SnapToLayer(float y)
|
||||
{
|
||||
float size = LayerHeight();
|
||||
return Mathf.Clamp(Mathp.Round2Nearest(y, size), -size * 3, 0);
|
||||
}
|
||||
|
||||
public float LayerHeight()
|
||||
{
|
||||
return LayersRect.rect.height / 4;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
|
||||
public void Move()
|
||||
{
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
11
Assets/Scripts/LevelEditor/Timeline/Timeline.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/Timeline/Timeline.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bec7fb5d989cb2d4792951c751f8fc23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
408
Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs
Normal file
408
Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs
Normal file
@ -0,0 +1,408 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using Starpelly;
|
||||
using DG.Tweening;
|
||||
|
||||
namespace RhythmHeavenMania.Editor.Track
|
||||
{
|
||||
public class TimelineEventObj : MonoBehaviour
|
||||
{
|
||||
private float startPosX;
|
||||
private float startPosY;
|
||||
|
||||
private Vector3 lastPos;
|
||||
public Vector2 lastPos_;
|
||||
private RectTransform rectTransform;
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField] private RectTransform PosPreview;
|
||||
[SerializeField] private RectTransform PosPreviewRef;
|
||||
[SerializeField] public Image Icon;
|
||||
[SerializeField] private Image selectedImage;
|
||||
[SerializeField] private RectTransform outline;
|
||||
[SerializeField] private RectTransform resizeGraphic;
|
||||
[SerializeField] private RectTransform leftDrag;
|
||||
[SerializeField] private RectTransform rightDrag;
|
||||
|
||||
[Header("Properties")]
|
||||
public Beatmap.Entity entity;
|
||||
public float length;
|
||||
public bool eligibleToMove = false;
|
||||
private bool lastVisible;
|
||||
public bool selected;
|
||||
public bool mouseHovering;
|
||||
public bool resizable;
|
||||
public bool resizing;
|
||||
public bool moving;
|
||||
private bool resizingLeft;
|
||||
private bool resizingRight;
|
||||
private bool inResizeRegion;
|
||||
public Vector2 lastMovePos;
|
||||
public bool isCreating;
|
||||
public string eventObjID;
|
||||
|
||||
[Header("Colors")]
|
||||
public Color NormalCol;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
lastPos_ = transform.localPosition;
|
||||
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
|
||||
if (!resizable)
|
||||
{
|
||||
Destroy(resizeGraphic.gameObject);
|
||||
}
|
||||
|
||||
lastMovePos = transform.localPosition;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
selected = Selections.instance.eventsSelected.Contains(this);
|
||||
entity = GameManager.instance.Beatmap.entities.Find(a => a.eventObj == this);
|
||||
|
||||
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main);
|
||||
|
||||
#region Optimizations
|
||||
|
||||
// problem with long objects but im lazy right now
|
||||
bool visible = rectTransform.IsVisibleFrom(Camera.main);
|
||||
|
||||
if (visible != lastVisible)
|
||||
{
|
||||
for (int i = 0; i < this.transform.childCount; i++)
|
||||
{
|
||||
// this.transform.GetChild(i).gameObject.SetActive(visible);
|
||||
}
|
||||
}
|
||||
|
||||
lastVisible = visible;
|
||||
|
||||
#endregion
|
||||
|
||||
SetColor(GetTrack());
|
||||
|
||||
if (Conductor.instance.NotStopped())
|
||||
{
|
||||
Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selected)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Delete))
|
||||
{
|
||||
/*Selections.instance.Deselect(this);
|
||||
Timeline.instance.DestroyEventObject(entity);*/
|
||||
}
|
||||
|
||||
selectedImage.gameObject.SetActive(true);
|
||||
for (int i = 0; i < outline.childCount; i++)
|
||||
{
|
||||
outline.GetChild(i).GetComponent<Image>().color = Color.cyan;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedImage.gameObject.SetActive(false);
|
||||
|
||||
for (int i = 0; i < outline.childCount; i++)
|
||||
outline.GetChild(i).GetComponent<Image>().color = new Color32(0, 0, 0, 51);
|
||||
}
|
||||
|
||||
if (!resizing)
|
||||
{
|
||||
if (Input.GetMouseButtonUp(0) && Timeline.instance.CheckIfMouseInTimeline())
|
||||
{
|
||||
if (Timeline.instance.eventObjs.FindAll(c => c.mouseHovering).Count == 0 && Timeline.instance.eventObjs.FindAll(c => c.moving).Count == 0 && !BoxSelection.instance.selecting && Timeline.instance.eventObjs.FindAll(c => c.resizing).Count == 0)
|
||||
{
|
||||
if (!Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
Selections.instance.Deselect(this);
|
||||
}
|
||||
}
|
||||
|
||||
// OnUp();
|
||||
}
|
||||
|
||||
if (Timeline.instance.eventObjs.FindAll(c => c.moving).Count > 0 && selected)
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
// lastPos_ = transform.localPosition;
|
||||
|
||||
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
|
||||
this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
|
||||
|
||||
if (lastPos != transform.localPosition)
|
||||
{
|
||||
OnMove();
|
||||
}
|
||||
|
||||
lastPos = this.transform.localPosition;
|
||||
}
|
||||
}
|
||||
else if (resizingLeft)
|
||||
{
|
||||
SetPivot(new Vector2(1, rectTransform.pivot.y));
|
||||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
Vector2 mousePos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2(-mousePos.x + 0.15f, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, rectTransform.localPosition.x), sizeDelta.y);
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, 0.25f), sizeDelta.y);
|
||||
SetPivot(new Vector2(0, rectTransform.pivot.y));
|
||||
OnComplete(false);
|
||||
}
|
||||
else if (resizingRight)
|
||||
{
|
||||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
Vector2 mousePos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2(mousePos.x + 0.15f, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, Mathf.Infinity), sizeDelta.y);
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, 0.25f), sizeDelta.y);
|
||||
SetPivot(new Vector2(0, rectTransform.pivot.y));
|
||||
OnComplete(false);
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
OnLeftUp();
|
||||
OnRightUp();
|
||||
}
|
||||
|
||||
if (resizing && selected || inResizeRegion && selected)
|
||||
{
|
||||
if (resizable)
|
||||
Cursor.SetCursor(Resources.Load<Texture2D>("Cursors/horizontal_resize"), new Vector2(8, 8), CursorMode.Auto);
|
||||
}
|
||||
else if (Timeline.instance.eventObjs.FindAll(c => c.inResizeRegion).Count == 0 && Timeline.instance.eventObjs.FindAll(c => c.resizing).Count == 0)
|
||||
{
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
#region ClickEvents
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
Selections.instance.ShiftClickSelect(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!selected)
|
||||
{
|
||||
Selections.instance.ClickSelect(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDown()
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
lastPos_ = transform.localPosition;
|
||||
|
||||
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
|
||||
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
|
||||
}
|
||||
|
||||
moving = true;
|
||||
// lastMovePos = transform.localPosition;
|
||||
// OnComplete();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUp()
|
||||
{
|
||||
// lastPos_ = this.lastPos_;
|
||||
// previousPos = this.transform.localPosition;
|
||||
|
||||
if (selected)
|
||||
{
|
||||
if (eligibleToMove)
|
||||
{
|
||||
OnComplete(true);
|
||||
}
|
||||
|
||||
moving = false;
|
||||
|
||||
Cancel();
|
||||
if (isCreating == true)
|
||||
{
|
||||
isCreating = false;
|
||||
CommandManager.instance.Execute(new Commands.Place(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
eligibleToMove = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ResizeEvents
|
||||
|
||||
public void DragEnter()
|
||||
{
|
||||
inResizeRegion = true;
|
||||
}
|
||||
|
||||
public void DragExit()
|
||||
{
|
||||
inResizeRegion = false;
|
||||
}
|
||||
|
||||
public void OnLeftDown()
|
||||
{
|
||||
if (resizable && selected)
|
||||
{
|
||||
ResetResize();
|
||||
resizing = true;
|
||||
resizingLeft = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLeftUp()
|
||||
{
|
||||
if (resizable && selected)
|
||||
{
|
||||
ResetResize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnRightDown()
|
||||
{
|
||||
if (resizable && selected)
|
||||
{
|
||||
ResetResize();
|
||||
resizing = true;
|
||||
resizingRight = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRightUp()
|
||||
{
|
||||
if (resizable && selected)
|
||||
{
|
||||
ResetResize();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetResize()
|
||||
{
|
||||
resizingLeft = false;
|
||||
resizingRight = false;
|
||||
resizing = false;
|
||||
}
|
||||
|
||||
private void SetPivot(Vector2 pivot)
|
||||
{
|
||||
if (rectTransform == null) return;
|
||||
|
||||
Vector2 size = rectTransform.rect.size;
|
||||
Vector2 deltaPivot = rectTransform.pivot - pivot;
|
||||
Vector3 deltaPosition = new Vector3(deltaPivot.x * size.x, deltaPivot.y * size.y);
|
||||
rectTransform.pivot = pivot;
|
||||
rectTransform.localPosition -= deltaPosition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnEvents
|
||||
|
||||
private void OnMove()
|
||||
{
|
||||
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == this.transform.localPosition.x && c.track == GetTrack()).Count > 0)
|
||||
{
|
||||
eligibleToMove = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
eligibleToMove = true;
|
||||
}
|
||||
|
||||
OnComplete(true);
|
||||
}
|
||||
|
||||
private void OnComplete(bool move)
|
||||
{
|
||||
entity.length = rectTransform.sizeDelta.x;
|
||||
entity.beat = this.transform.localPosition.x;
|
||||
GameManager.instance.SortEventsList();
|
||||
entity.track = GetTrack();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Selection
|
||||
|
||||
#endregion
|
||||
|
||||
#region Extra
|
||||
|
||||
public void SetColor(int type)
|
||||
{
|
||||
Color c = Color.white;
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
c = EditorTheme.theme.properties.Layer1Col.Hex2RGB();
|
||||
break;
|
||||
case 1:
|
||||
c = EditorTheme.theme.properties.Layer2Col.Hex2RGB();
|
||||
break;
|
||||
case 2:
|
||||
c = EditorTheme.theme.properties.Layer3Col.Hex2RGB();
|
||||
break;
|
||||
case 3:
|
||||
c = EditorTheme.theme.properties.Layer4Col.Hex2RGB();
|
||||
break;
|
||||
}
|
||||
|
||||
// c = new Color(c.r, c.g, c.b, 0.85f);
|
||||
transform.GetChild(0).GetComponent<Image>().color = c;
|
||||
|
||||
if (resizable)
|
||||
{
|
||||
c = new Color(0, 0, 0, 0.35f);
|
||||
transform.GetChild(1).GetChild(0).GetComponent<Image>().color = c;
|
||||
transform.GetChild(1).GetChild(1).GetComponent<Image>().color = c;
|
||||
transform.GetChild(1).GetChild(2).GetComponent<Image>().color = c;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetTrack()
|
||||
{
|
||||
return (int)(this.transform.localPosition.y / Timeline.instance.LayerHeight()) * -1;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// better safety net than canada's healthcare system
|
||||
// GameManager.instance.Beatmap.entities.Remove(GameManager.instance.Beatmap.entities.Find(c => c.eventObj = this));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
11
Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/Timeline/TimelineEventObj.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb5481d804b2aec42a04ea8f659fdc5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user