Timeline improvements

This commit is contained in:
Braedon
2022-01-09 18:35:55 -05:00
parent 9bcb315344
commit 00e3791e6d
22 changed files with 1035 additions and 215 deletions

View File

@ -18,6 +18,7 @@ namespace RhythmHeavenMania
public float valA;
public int type;
public string datamodel;
[Newtonsoft.Json.JsonIgnore] public Editor.TimelineEventObj eventObj;
public object Clone()
{

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 403408f55becf5f4f9195d5766738526
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Common
{
public class FollowMouse : MonoBehaviour
{
private void Update()
{
var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(pos.x, pos.y, 0);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ef18fa546ce78c4b9ebf77aefdec762
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -56,10 +56,13 @@ namespace RhythmHeavenMania
{
float secFromBeat = GetSongPosFromBeat(beat);
if (secFromBeat < musicSource.clip.length)
musicSource.time = secFromBeat;
else
musicSource.time = 0;
if (musicSource.clip != null)
{
if (secFromBeat < musicSource.clip.length)
musicSource.time = secFromBeat;
else
musicSource.time = 0;
}
GameManager.instance.SetCurrentEventToClosest(beat);
}
@ -142,7 +145,10 @@ namespace RhythmHeavenMania
public bool SongPosLessThanClipLength(float t)
{
return t < musicSource.clip.length;
if (musicSource.clip != null)
return t < musicSource.clip.length;
else
return false;
}
}
}

View File

@ -51,16 +51,14 @@ namespace RhythmHeavenMania
public string actionName;
public EventCallback function;
public bool playerAction = false;
public float[] eventBeats = new float[] { 0 };
public float defaultLength;
public bool resizable;
public GameAction(string actionName, EventCallback function, float[] eventBeats = null, float defaultLength = 1, bool playerAction = false, bool resizable = false)
public GameAction(string actionName, EventCallback function, float defaultLength = 1, bool playerAction = false, bool resizable = false)
{
this.actionName = actionName;
this.function = function;
this.playerAction = playerAction;
this.eventBeats = eventBeats;
this.defaultLength = defaultLength;
this.resizable = resizable;
}
@ -88,37 +86,37 @@ namespace RhythmHeavenMania
}),
new MiniGame("forkLifter", "FFFFFF", new List<GameAction>()
{
new GameAction("pea", delegate { ForkLifter.instance.Flick(currentBeat, 0); }, new float[] { 0, 2 }, 3, true),
new GameAction("topbun", delegate { ForkLifter.instance.Flick(currentBeat, 1); }, new float[] { 0, 2 }, 3, true),
new GameAction("burger", delegate { ForkLifter.instance.Flick(currentBeat, 2); }, new float[] { 0, 2 }, 3, true),
new GameAction("bottombun", delegate { ForkLifter.instance.Flick(currentBeat, 3); }, new float[] { 0, 2 }, 3, true),
new GameAction("prepare", delegate { ForkLifter.instance.ForkLifterHand.Prepare(); }, new float[] { 0 }, 0.5f, true),
new GameAction("pea", delegate { ForkLifter.instance.Flick(currentBeat, 0); }, 3, true),
new GameAction("topbun", delegate { ForkLifter.instance.Flick(currentBeat, 1); }, 3, true),
new GameAction("burger", delegate { ForkLifter.instance.Flick(currentBeat, 2); }, 3, true),
new GameAction("bottombun", delegate { ForkLifter.instance.Flick(currentBeat, 3); }, 3, true),
new GameAction("prepare", delegate { ForkLifter.instance.ForkLifterHand.Prepare(); }, 0.5f, true),
new GameAction("gulp", delegate { ForkLifterPlayer.instance.Eat(); }),
new GameAction("sigh", delegate { Jukebox.PlayOneShot("sigh"); })
}),
new MiniGame("clappyTrio", "29E7FF", new List<GameAction>()
{
new GameAction("clap", delegate { ClappyTrio.instance.Clap(currentBeat, currentLength); }, new float[] { 0 }, 3, true),
new GameAction("clap", delegate { ClappyTrio.instance.Clap(currentBeat, currentLength); }, 3, true),
new GameAction("bop", delegate { ClappyTrio.instance.Bop(currentBeat); } ),
new GameAction("prepare", delegate { ClappyTrio.instance.Prepare(0); } ),
new GameAction("prepare_alt", delegate { ClappyTrio.instance.Prepare(3); } ),
}),
new MiniGame("spaceball", "00A518", new List<GameAction>()
{
new GameAction("shoot", delegate { Spaceball.instance.Shoot(currentBeat, false, currentType); }, new float[] { 0, 1 }, 2, true),
new GameAction("shootHigh", delegate { Spaceball.instance.Shoot(currentBeat, true, currentType); }, new float[] { 0, 2 }, 3, true),
new GameAction("shoot", delegate { Spaceball.instance.Shoot(currentBeat, false, currentType); }, 2, true),
new GameAction("shootHigh", delegate { Spaceball.instance.Shoot(currentBeat, true, currentType); }, 3, true),
new GameAction("costume", delegate { Spaceball.instance.Costume(currentType); } ),
new GameAction("alien", delegate { Spaceball.instance.alien.Show(currentBeat); } ),
new GameAction("cameraZoom", delegate { } ),
}),
new MiniGame("karateman", "70A8D8", new List<GameAction>()
{
new GameAction("bop", delegate { KarateMan.instance.Bop(currentBeat, currentLength); }, new float[] { 0 }, 0.5f, true, true),
new GameAction("pot", delegate { KarateMan.instance.Shoot(currentBeat, 0); }, new float[] { 0, 1 }, 2, true),
new GameAction("bulb", delegate { KarateMan.instance.Shoot(currentBeat, 1); }, new float[] { 0, 1 }, 2, true),
new GameAction("rock", delegate { KarateMan.instance.Shoot(currentBeat, 2); }, new float[] { 0, 1 }, 2, true),
new GameAction("ball", delegate { KarateMan.instance.Shoot(currentBeat, 3); }, new float[] { 0, 1 }, 2, true),
new GameAction("kick", delegate { KarateMan.instance.Shoot(currentBeat, 4); }, new float[] { 0, 1, 2 }, 4.5f, true),
new GameAction("bop", delegate { KarateMan.instance.Bop(currentBeat, currentLength); }, 0.5f, true, true),
new GameAction("pot", delegate { KarateMan.instance.Shoot(currentBeat, 0); }, 2, true),
new GameAction("bulb", delegate { KarateMan.instance.Shoot(currentBeat, 1); }, 2, true),
new GameAction("rock", delegate { KarateMan.instance.Shoot(currentBeat, 2); }, 2, true),
new GameAction("ball", delegate { KarateMan.instance.Shoot(currentBeat, 3); }, 2, true),
new GameAction("kick", delegate { KarateMan.instance.Shoot(currentBeat, 4); }, 4.5f, true),
new GameAction("bgfxon", delegate { KarateMan.instance.BGFXOn(); } ),
new GameAction("bgfxoff", delegate { KarateMan.instance.BGFXOff(); }),
})

View File

@ -109,7 +109,7 @@ namespace RhythmHeavenMania
if (currentEvent < Beatmap.entities.Count && currentEvent >= 0)
{
if (Conductor.instance.songPositionInBeats >= entities[currentEvent] && Conductor.instance.GetSongPosFromBeat(Conductor.instance.songPositionInBeats) < Conductor.instance.musicSource.clip.length)
if (Conductor.instance.songPositionInBeats >= entities[currentEvent] && SongPosLessThanClipLength(Conductor.instance.songPositionInBeats))
{
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
var entitesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && c.datamodel.Split('/')[0] != "gameManager");
@ -143,6 +143,7 @@ namespace RhythmHeavenMania
public void SetCurrentEventToClosest(float beat)
{
SortEventsList();
if (Beatmap.entities.Count > 0)
{
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
@ -258,5 +259,13 @@ namespace RhythmHeavenMania
currentGame = game;
CircleCursor.InnerCircle.GetComponent<SpriteRenderer>().color = Colors.Hex2RGB(GetGame(currentGame).color);
}
private bool SongPosLessThanClipLength(float t)
{
if (Conductor.instance.musicSource.clip != null)
return Conductor.instance.GetSongPosFromBeat(t) < Conductor.instance.musicSource.clip.length;
else
return true;
}
}
}

View File

@ -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}");
}
}
}

View 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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0baf64619d1dc0749bfc3f9a4b8f7b47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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);
}
}

View 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();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb5481d804b2aec42a04ea8f659fdc5a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: