mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:37:37 +02:00
Timeline improvements
This commit is contained in:
@ -16,6 +16,7 @@ namespace RhythmHeavenMania.Editor
|
||||
[Header("Rect")]
|
||||
[SerializeField] private RenderTexture ScreenRenderTexture;
|
||||
[SerializeField] private RawImage Screen;
|
||||
[SerializeField] private RectTransform GridGameSelector;
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField] private Timeline Timeline;
|
||||
@ -36,6 +37,19 @@ namespace RhythmHeavenMania.Editor
|
||||
|
||||
GameManager.instance.Init();
|
||||
Timeline.Init();
|
||||
|
||||
for (int i = 0; i < EventCaller.instance.minigames.Count; i++)
|
||||
{
|
||||
GameObject GameIcon_ = Instantiate(GridGameSelector.GetChild(0).gameObject, GridGameSelector);
|
||||
GameIcon_.GetComponent<Image>().sprite = GameIcon(EventCaller.instance.minigames[i].name);
|
||||
GameIcon_.gameObject.SetActive(true);
|
||||
GameIcon_.name = "GameIcon";
|
||||
}
|
||||
}
|
||||
|
||||
public static Sprite GameIcon(string name)
|
||||
{
|
||||
return Resources.Load<Sprite>($"Sprites/Editor/GameIcons/{name}");
|
||||
}
|
||||
}
|
||||
}
|
20
Assets/Scripts/LevelEditor/GridGameSelector.cs
Normal file
20
Assets/Scripts/LevelEditor/GridGameSelector.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
public class GridGameSelector : MonoBehaviour
|
||||
{
|
||||
public GameObject GameTitlePreview;
|
||||
|
||||
public void OnEnter()
|
||||
{
|
||||
GameTitlePreview.GetComponent<Image>().enabled = true;
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
{
|
||||
GameTitlePreview.GetComponent<Image>().enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/LevelEditor/GridGameSelector.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/GridGameSelector.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0baf64619d1dc0749bfc3f9a4b8f7b47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -23,9 +23,9 @@ namespace RhythmHeavenMania.Editor
|
||||
[SerializeField] private TMP_Text TimelinePlaybackBeat;
|
||||
[SerializeField] private RectTransform TimelineContent;
|
||||
[SerializeField] private RectTransform TimelineSongPosLineRef;
|
||||
[SerializeField] private RectTransform TimelineEventObjRef;
|
||||
private RectTransform TimelineSongPosLine;
|
||||
|
||||
public RectTransform TestEVENTGO;
|
||||
|
||||
#region Initializers
|
||||
|
||||
@ -34,52 +34,27 @@ namespace RhythmHeavenMania.Editor
|
||||
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
||||
{
|
||||
var entity = GameManager.instance.Beatmap.entities[i];
|
||||
|
||||
GameObject g = Instantiate(TestEVENTGO.gameObject, TestEVENTGO.parent);
|
||||
var e = GameManager.instance.Beatmap.entities[i];
|
||||
|
||||
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(e.datamodel.Split(0)), e.datamodel.Split(1));
|
||||
|
||||
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
|
||||
g.transform.localPosition = new Vector3(e.beat, Mathp.Round2Nearest(Random.Range(0, -205.36f), 51.34f));
|
||||
g.transform.GetChild(1).GetComponent<TMP_Text>().text = e.datamodel.Split('/')[1];
|
||||
|
||||
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(e.datamodel.Split(0)), e.datamodel.Split(1));
|
||||
GameObject blocksHolder = g.transform.GetChild(0).gameObject;
|
||||
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
|
||||
eventObj.Icon.sprite = Editor.GameIcon(e.datamodel.Split(0));
|
||||
|
||||
if (gameAction != null)
|
||||
{
|
||||
blocksHolder.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, blocksHolder.GetComponent<RectTransform>().sizeDelta.y);
|
||||
if (gameAction.eventBeats != null)
|
||||
{
|
||||
if (gameAction.eventBeats.Length > 0)
|
||||
{
|
||||
for (int k = 0; k < gameAction.eventBeats.Length; k++)
|
||||
{
|
||||
var ind = gameAction.eventBeats[k];
|
||||
if (gameAction.defaultLength > 0)
|
||||
{
|
||||
float length;
|
||||
|
||||
if (k + 1 >= gameAction.eventBeats.Length)
|
||||
length = gameAction.defaultLength - ind;
|
||||
else
|
||||
length = gameAction.eventBeats[k + 1];
|
||||
|
||||
if (gameAction.resizable)
|
||||
{
|
||||
length = entity.length;
|
||||
}
|
||||
|
||||
GameObject block = Instantiate(blocksHolder.transform.GetChild(0).gameObject, blocksHolder.transform);
|
||||
block.GetComponent<RectTransform>().sizeDelta = new Vector2(length, block.GetComponent<RectTransform>().sizeDelta.y);
|
||||
block.transform.localPosition = new Vector3(ind, block.transform.localPosition.y);
|
||||
block.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, g.GetComponent<RectTransform>().sizeDelta.y);
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, g.GetComponent<RectTransform>().sizeDelta.y);
|
||||
float length = gameAction.defaultLength;
|
||||
eventObj.length = length;
|
||||
}
|
||||
|
||||
g.SetActive(true);
|
||||
entity.eventObj = g.GetComponent<TimelineEventObj>();
|
||||
entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
112
Assets/Scripts/LevelEditor/TimelineEventObj.cs
Normal file
112
Assets/Scripts/LevelEditor/TimelineEventObj.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using Starpelly;
|
||||
using DG.Tweening;
|
||||
|
||||
namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
public class TimelineEventObj : MonoBehaviour
|
||||
{
|
||||
private float startPosX;
|
||||
private float startPosY;
|
||||
private bool isDragging;
|
||||
|
||||
private Vector3 lastPos;
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField] private RectTransform PosPreview;
|
||||
[SerializeField] private RectTransform PosPreviewRef;
|
||||
[SerializeField] public Image Icon;
|
||||
|
||||
[Header("Properties")]
|
||||
private int enemyIndex;
|
||||
public float length;
|
||||
private bool eligibleToMove = false;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Conductor.instance.isPlaying == true || Conductor.instance.isPaused)
|
||||
{
|
||||
Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
enemyIndex = GameManager.instance.Beatmap.entities.FindIndex(a => a.eventObj == this);
|
||||
|
||||
if (isDragging == true)
|
||||
{
|
||||
Vector3 mousePos;
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
|
||||
PosPreview.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
|
||||
PosPreview.transform.localPosition = new Vector3(Mathp.Round2Nearest(PosPreview.transform.localPosition.x, 0.25f), Mathp.Round2Nearest(PosPreview.transform.localPosition.y, 51.34f));
|
||||
|
||||
if (lastPos != transform.localPosition)
|
||||
OnMove();
|
||||
|
||||
lastPos = PosPreview.transform.localPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMove()
|
||||
{
|
||||
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == PosPreview.transform.localPosition.x && c.track == (int)(PosPreview.transform.localPosition.y / 51.34f * -1)).Count > 0)
|
||||
{
|
||||
PosPreview.GetComponent<Image>().color = Color.red;
|
||||
eligibleToMove = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PosPreview.GetComponent<Image>().color = Color.yellow;
|
||||
eligibleToMove = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnComplete()
|
||||
{
|
||||
var entity = GameManager.instance.Beatmap.entities[enemyIndex];
|
||||
entity.beat = PosPreview.transform.localPosition.x;
|
||||
GameManager.instance.SortEventsList();
|
||||
entity.track = (int)(PosPreview.transform.localPosition.y / 51.34f) * -1;
|
||||
|
||||
this.transform.localPosition = PosPreview.transform.localPosition;
|
||||
// transform.DOLocalMove(PosPreview.transform.localPosition, 0.15f).SetEase(Ease.OutExpo);
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
if (PosPreview) Destroy(PosPreview.gameObject);
|
||||
eligibleToMove = false;
|
||||
}
|
||||
|
||||
public void OnDown()
|
||||
{
|
||||
Vector3 mousePos;
|
||||
|
||||
PosPreview = Instantiate(PosPreviewRef, PosPreviewRef.transform.parent);
|
||||
PosPreview.sizeDelta = new Vector2(100 * transform.GetComponent<RectTransform>().sizeDelta.x, transform.GetComponent<RectTransform>().sizeDelta.y);
|
||||
PosPreview.transform.localPosition = this.transform.localPosition;
|
||||
PosPreview.GetComponent<Image>().enabled = true;
|
||||
PosPreview.GetComponent<Image>().color = Color.yellow;
|
||||
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
startPosX = mousePos.x - PosPreview.transform.position.x;
|
||||
startPosY = mousePos.y - PosPreview.transform.position.y;
|
||||
isDragging = true;
|
||||
|
||||
}
|
||||
|
||||
public void OnUp()
|
||||
{
|
||||
isDragging = false;
|
||||
|
||||
if (eligibleToMove) OnComplete();
|
||||
Cancel();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/LevelEditor/TimelineEventObj.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/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