A lot of stuff (Read desc)

Beat action is now used to define one-off objects that is used by the beat but I don't wanna bother making a different script for. Example case: the "hit 3" sprite in Karate Man.

Animation helpers for functions I don't wanna rewrite 100,000 times.

General improvements for Karate Man, like prepare animation and some updates to game events.
This commit is contained in:
Braedon
2022-01-21 02:09:32 -05:00
parent 59aae67174
commit fa519d25d7
27 changed files with 2076 additions and 233 deletions

View File

@ -51,7 +51,7 @@ namespace RhythmHeavenMania.Editor
var entity = GameManager.instance.Beatmap.entities[i];
var e = GameManager.instance.Beatmap.entities[i];
AddEventObject(e.datamodel, false, new Vector3(e.beat, Mathp.Round2Nearest(Random.Range(0, -LayersRect.rect.height), LayerHeight())), i);
AddEventObject(e.datamodel, false, new Vector3(e.beat, -e.track * LayerHeight()), i);
}
TimelineSlider.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
@ -322,7 +322,7 @@ namespace RhythmHeavenMania.Editor
else
{
eventObj.resizable = true;
if (gameAction.defaultLength != GameManager.instance.Beatmap.entities[entityId].length)
if (gameAction.defaultLength != GameManager.instance.Beatmap.entities[entityId].length && dragNDrop == false)
{
g.GetComponent<RectTransform>().sizeDelta = new Vector2(GameManager.instance.Beatmap.entities[entityId].length, LayerHeight());
}

View File

@ -64,7 +64,7 @@ namespace RhythmHeavenMania.Editor
{
for (int i = 0; i < this.transform.childCount; i++)
{
this.transform.GetChild(i).gameObject.SetActive(visible);
// this.transform.GetChild(i).gameObject.SetActive(visible);
}
}
@ -155,6 +155,8 @@ namespace RhythmHeavenMania.Editor
startPosY = mousePos.y - this.transform.position.y;
moving = true;
OnComplete();
}
public void OnUp()
@ -210,13 +212,14 @@ namespace RhythmHeavenMania.Editor
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);
OnComplete();
}
public void OnLeftUp()
{
SetPivot(new Vector2(0, rectTransform.pivot.y));
resizing = false;
OnComplete();
}
public void OnRightDown()
@ -238,13 +241,13 @@ namespace RhythmHeavenMania.Editor
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);
OnComplete();
}
public void OnRightUp()
{
resizing = false;
OnComplete();
}
private void SetPivot(Vector2 pivot)
@ -272,6 +275,8 @@ namespace RhythmHeavenMania.Editor
{
eligibleToMove = true;
}
OnComplete();
}
private void OnComplete()

View File

@ -0,0 +1,124 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace RhythmHeavenMania.Editor
{
public class WaveformVisual : MonoBehaviour
{
public new AudioSource audio;
public RawImage image;
public int width;
public Color col;
int resolution = 60;
float[] waveForm;
float[] samples;
Texture2D texture;
private void Start()
{
audio = Conductor.instance.musicSource;
GetComponent<RectTransform>().sizeDelta = new Vector2(Conductor.instance.SongLengthInBeats(), GetComponent<RectTransform>().sizeDelta.y);
texture = new Texture2D(width, 100, TextureFormat.RGBA32, false);
CreateWaveForm();
}
// This two are from unity answer (I mixed up)
public void CreateWaveForm()
{
resolution = audio.clip.frequency / resolution;
samples = new float[audio.clip.samples * audio.clip.channels];
audio.clip.GetData(samples, 0);
int s = 0;
while (s < samples.Length)
{
samples[s] = samples[s] * 0.5F;
++s;
}
audio.clip.SetData(samples, 0);
waveForm = new float[(samples.Length / resolution)];
for (int i = 0; i < waveForm.Length; i++)
{
waveForm[i] = 0;
for (int ii = 0; ii < resolution; ii++)
{
waveForm[i] += Mathf.Abs(samples[(i * resolution) + ii]);
}
waveForm[i] /= resolution;
}
MakeTexture(width, 100, waveForm, col);
}
public void MakeTexture(int width, int height, float[] waveform, Color col)
{
texture = new Texture2D(width, height, TextureFormat.RGBA32, false);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
texture.SetPixel(x, y, Color.black);
}
}
for (int x = 0; x < waveform.Length; x++)
{
for (int y = 0; y <= waveform[x] * ((float)height * .75f); y++)
{
texture.SetPixel(x, (height / 2) + y, col);
texture.SetPixel(x, (height / 2) - y, col);
}
}
texture.Apply();
image.texture = texture;
}
void Update()
{
//script from unity doc.
float[] spectrum = new float[1024];
AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);
/*for (int i = 1; i < spectrum.Length - 1; i++)
{
Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);
Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i, Mathf.Log(spectrum[i]) + 10, 2), Color.cyan);
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), spectrum[i - 1] - 10, 1), new Vector3(Mathf.Log(i), spectrum[i] - 10, 1), Color.green);
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(spectrum[i - 1]), 3), new Vector3(Mathf.Log(i), Mathf.Log(spectrum[i]), 3), Color.blue);
}
//script from unity answer
for (int i = 0; i < waveForm.Length - 1; i++)
{
Vector3 sv = new Vector3(i * .01f, waveForm[i] * 10, 0);
Vector3 ev = new Vector3(i * .01f, -waveForm[i] * 10, 0);
Debug.DrawLine(sv, ev, Color.yellow);
}*/
int current = audio.timeSamples / resolution;
current *= 2;
Vector3 c = new Vector3(current * .01f, 0, 0);
Debug.DrawLine(c, c + Vector3.up * 10, Color.white);
}
}
}

View File

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