This commit is contained in:
2024-07-01 21:24:10 +05:30
parent 7bf2a45583
commit 70303078c7
73 changed files with 15059 additions and 1124 deletions

View File

@@ -8,9 +8,36 @@ public class AudioSync : MonoBehaviour
public AudioSource master;
public AudioSource slave;
public float curSample;
void Update()
public bool smooth;
public float smoothInterval = 0.5f;
public float replayOffset;
float t;
private void Awake()
{
slave.time = Time.time;
master.time = Time.time;
t = smoothInterval;
}
void FixedUpdate()
{
if (smooth)
{
if(t < smoothInterval)
{
t += Time.deltaTime;
return;
}
else
{
t = 0;
slave.time = Time.time - replayOffset;
master.time = Time.time-replayOffset;
}
}
else
{
slave.time = Time.time;
master.time = Time.time;
}
}
}

View File

@@ -17,7 +17,7 @@ public class CamFollower : MonoBehaviour
}
// Update is called once per frame
void Update()
void FixedUpdate ()
{
transform.position = Vector3.Lerp(transform.position, target.position + offset, speed);
}

View File

@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class DyingLight : MonoBehaviour
{
Light2D l;
public float speed = 0.5f;
private void Awake()
{
l = GetComponent<Light2D>();
l.intensity = 0.5f;
}
void Update()
{
if(l.intensity < 0)
{
//Destroy(gameObject);
}
else
{
l.intensity -= Time.deltaTime * speed;
}
}
}

View File

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

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class GrowingLight : MonoBehaviour
{
Light2D l;
public float speed = 0.5f;
private void Awake()
{
l = GetComponent<Light2D>();
l.intensity = 0.3f;
}
void Update()
{
if(l.intensity < 1)
{
l.intensity += Time.deltaTime * speed;
}
l.shapeLightFalloffSize += Time.deltaTime * speed;
}
}

View File

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

View File

@@ -1,13 +1,17 @@
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.U2D;
public class Mover : MonoBehaviour
{
public Vector3 movingSpeed;
public float loudBoost = 1f;
public float momentumBoost = 1f;
public AudioSplitter splitter;
@@ -24,9 +28,11 @@ public class Mover : MonoBehaviour
public LineRenderer botLineRenderer, topLineRenderer;
public DrawShape botDrawer;
public DrawShape topDrawer;
public SpriteRenderer insideFill;
public GameObject txtDebug;
public bool isDebug = false;
public Light2D glowLight;
public float glowReductionSpeed = 2f;
public float fovZoomingSpeed = 0.5f;
[SerializeField]
@@ -42,12 +48,13 @@ public class Mover : MonoBehaviour
private void Awake()
{
defFOV = Camera.main.orthographicSize;
if (!playReplay) { themeMan.Randomize(); }
}
private void Start()
{
// Application.targetFrameRate = 164;
if(recordedStepsJson.Length > 1)
if(recordedStepsJson.Length > 1 && playReplay)
{
recordedSteps = JsonConvert.DeserializeObject<List<RecorderStep>>(recordedStepsJson);
GenerateRecordedPlatform();
@@ -64,13 +71,13 @@ public class Mover : MonoBehaviour
void Update()
{
if (insideFill.transform.localScale.x > 0)
if (glowLight.intensity > 0)
{
insideFill.transform.localScale = Vector3.one * (insideFill.transform.localScale.x - (Time.deltaTime * glowReductionSpeed));
glowLight.intensity=(glowLight.intensity- (Time.deltaTime * glowReductionSpeed));
}
insideFill.color = new Color(1,1,1, insideFill.transform.localScale.y);
trailParticle.emissionRate = 300 * (glowLight.intensity);
Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, defFOV, 3 * Time.deltaTime);
if (playReplay) { Camera.main.orthographicSize -= Time.deltaTime * fovZoomingSpeed; }
if (!manualFlip) { return; }
if(Input.GetKeyDown(KeyCode.LeftArrow))
@@ -91,14 +98,16 @@ public class Mover : MonoBehaviour
movingSpeed.y = -Mathf.Abs(movingSpeed.y);
}
cube.rotation = Quaternion.Lerp(cube.rotation, targetRotation, cubeRotateSpeed * Time.deltaTime);
}
void FixedUpdate()
{
movingSpeedMultiplier = Mathf.Lerp(movingSpeedMultiplier, 1, Time.deltaTime * 2);
transform.Translate(movingSpeed*Time.deltaTime * movingSpeedMultiplier);
float boostedX = movingSpeed.x * Mathf.Clamp((movingSpeedMultiplier * 1),0,1.25f);
float boostedY = movingSpeed.y * (movingSpeedMultiplier * 1f);
//transform.Translate(new Vector3(boostedX, boostedY)*Time.deltaTime);
transform.Translate(movingSpeed * Time.deltaTime * movingSpeedMultiplier);
if(recordedStepsJson.Length > 1 && playReplay)
{
PostWork();
@@ -236,13 +245,16 @@ public class Mover : MonoBehaviour
}
}
float tensionBuildup = 0f;
void PreWork()
{
float loudness_delta = splitter.loudness - prev_loud;
bool notTooShort = (Time.time - LastTime) > yieldTime;
bool oldLoudLogic = splitter.loudness > loudnessThreshold && prev_loud < loudnessThreshold;
bool newLoudLogic = (loudness_delta > loudnessThreshold && notTooShort);
tensionBuildup += Time.deltaTime;
if ((loudness_delta > loudnessThreshold && notTooShort) || Input.GetKeyDown(KeyCode.Space))
if (oldLoudLogic || Input.GetKeyDown(KeyCode.Space))
{
Debug.Log(LastTime - Time.time);
//Instantiate(prefab, transform.position, Quaternion.identity);
@@ -253,28 +265,32 @@ public class Mover : MonoBehaviour
{
movingSpeed.x = -movingSpeed.x;
Instantiate(prefab, transform.position + new Vector3(-1 / 5f, 0), Quaternion.Euler(new Vector3(0, 0, 0))).transform.GetComponentInChildren<TextMesh>().text = loudness_delta.ToString("n3");
movingSpeedMultiplier += (loudness_delta * loudBoost) / loudnessThreshold;
}
else
{
movingSpeed.y = -movingSpeed.y;
Instantiate(prefab, transform.position + new Vector3(0, -1 / 5f), Quaternion.Euler(new Vector3(0, 0, 90))).transform.GetComponentInChildren<TextMesh>().text = loudness_delta.ToString("n3"); ;
movingSpeedMultiplier += (loudness_delta * loudBoost) / loudnessThreshold;
}
movingSpeedMultiplier += (loudness_delta * loudBoost) / loudnessThreshold;
movingSpeedMultiplier += tensionBuildup * momentumBoost;
LastTime = Time.time;
currentSteps.Add(new RecorderStep(LastTime, movingSpeed, movingSpeedMultiplier, transform.position));
currentStepsJson = JsonConvert.SerializeObject(currentSteps);
LastPos = transform.position;
tensionBuildup = 0;
}
prev_loud = splitter.loudness;
}
int index = 0;
void PostWork()
{
if(recordedSteps.Count <= 0) { return; }
tensionBuildup += Time.deltaTime;
if (Time.time >= recordedSteps[0].time)
{
//Time to act
@@ -285,29 +301,54 @@ public class Mover : MonoBehaviour
recordedSteps.RemoveAt(0);
HitFX();
tensionBuildup = 0;
index++;
if (isDebug) { Instantiate(txtDebug, transform.position, Quaternion.identity).GetComponent<TextMeshPro>().text = index.ToString(); }
}
}
public GameObject particleFxPrefab;
public AudioSource musicSourceToSync;
public float fovChangeOnHit = 0.9f;
public float fovChangeOnHit = 0.1f;
public ParticleSystem trailParticle;
public GameObject shockwavePrefab;
public ThemeManager themeMan;
public Transform cube;
public float cubeRotateSpeed = 15f;
Quaternion targetRotation = Quaternion.identity;
void HitFX()
{
StartCoroutine(CoroutineScaleupGlow());
Vector3 movingSpeedY = movingSpeed;
movingSpeedY.x = 0;
Instantiate(particleFxPrefab, transform.position - (movingSpeedY/5f), Quaternion.LookRotation(-movingSpeedY));
Camera.main.orthographicSize = defFOV * fovChangeOnHit;
Vector3 hitpoint = transform.position - (movingSpeedY / 5f);
Instantiate(particleFxPrefab, hitpoint, Quaternion.LookRotation(-movingSpeedY)).GetComponent<ParticleSystem>().startColor =themeMan.mainColor;
Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize + (fovZoomingSpeed), 0,defFOV);
shockwavePrefab.GetComponent<ShockwaveShaderHelper>().Reset();
Instantiate(glowLight,hitpoint, Quaternion.identity).AddComponent<DyingLight>();
themeMan.Randomize(movingSpeedMultiplier /3f);
targetRotation *= Quaternion.Euler(0, 0, -90);
// themeMan.SetColor(new Color(Random.Range(0f,1f), Random.Range(0f,1f),Random.Range(0f,1f)));
/*themeMan.r = Random.Range(0f, 1f);
themeMan.g = Random.Range(0f, 1f);
themeMan.b = Random.Range(0f, 1f);
themeMan.Refresh();*/
// Instantiate(shockwavePrefab, shockwavePrefab.transform.parent).GetComponent<ShockwaveShaderHelper>().started = true;
}
IEnumerator CoroutineScaleupGlow()
{
while(insideFill.transform.localScale.x < 0.6f)
glowLight.intensity += 0.4f;
while(glowLight.intensity < 0.65f)
{
insideFill.transform.localScale = Vector3.one * (insideFill.transform.localScale.x + (Time.deltaTime * glowReductionSpeed * 5));
glowLight.intensity = (glowLight.intensity + (Time.deltaTime * glowReductionSpeed * 8));
yield return null;
}
}
}

View File

@@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShockwaveShaderHelper : MonoBehaviour
{
public Material mat;
// public Material _mat;
public Transform target;
public Vector2 offset;
public Vector2 screenOnPos;
public bool started = false;
public float speed = 1f;
public float val = 1f;
private void Awake()
{
// _mat = new Material(mat);
// GetComponent<SpriteRenderer>().material = _mat;
}
void Update()
{
screenOnPos = Camera.main.WorldToViewportPoint(target.position);
mat.SetVector("_RingSpawnPosition", offset + screenOnPos);
if(val < 1)
{
val += Time.deltaTime * speed;
}
mat.SetFloat("_WaveDistanceFromCenter", val );
/* if(_mat.GetFloat("_WaveDistanceFromCenter") >= 1f)
{
Destroy(gameObject);
}*/
}
public void Reset()
{
val = 0.087f;
}
}

View File

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

View File

@@ -0,0 +1,147 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class ThemeManager : MonoBehaviour
{
[Header("Color Mixer")]
[Range(0f,1f)]
public float r = 1;
[Range(0f, 1f)]
public float g = 1;
[Range(0f, 1f)]
public float b = 1;
public Color baseColor;
[Range(0f, 1f)]
public float accentMult = 0.5f;
public Color accentColor;
[Range(0f, 1f)]
public float mainMult = 0.2f;
public Color mainColor;
[Range(0f, 1f)]
public float fxMult = 0.6f;
public Color fxColor;
[Header("Receivers")]
public Material[] accentMats;
public Material[] mainMats;
public Material[] fxMats;
public ParticleSystem[] particleSystems;
public Light2D[] lights;
public float randomizerSmoothness = 0.01f;
public float randomizerIntensity = 0.1f;
public Camera mainCam;
private void OnValidate()
{
Refresh();
}
public void Refresh()
{
baseColor = new Color(r, g, b);
accentColor = new Color(r * accentMult, g * accentMult, b * accentMult);
mainColor = new Color(r * mainMult, g * mainMult, b * mainMult);
fxColor = new Color(r * fxMult, g * fxMult, b * fxMult);
foreach (Material mat in mainMats)
{
mat.color = mainColor;
}
foreach (Material mat in fxMats)
{
mat.color = fxColor;
}
foreach (Material mat in accentMats)
{
mat.color = accentColor;
}
foreach (ParticleSystem particle in particleSystems)
{
particle.startColor = fxColor;
}
foreach (Light2D light in lights)
{
light.color = fxColor;
}
mainCam.backgroundColor = mainColor;
}
private void Awake()
{
targetColor = baseColor;
}
Color targetColor;
public void SetColor(Color color)
{
targetColor = color;
}
private void Update()
{
r = Mathf.Lerp(r, targetColor.r, randomizerSmoothness * Time.deltaTime);
g = Mathf.Lerp(g, targetColor.g, randomizerSmoothness * Time.deltaTime);
b = Mathf.Lerp(b, targetColor.b, randomizerSmoothness * Time.deltaTime);
Refresh();
}
bool addR,addG, addB;
public float minR, minG, minB;
public void Randomize(float intensity = 1f)
{
Color newC = new Color(Random.Range(minR, 1f), Random.Range(minG, 1f), Random.Range(minB, 1f));
float rDiff = newC.r - r;
float gDiff = newC.g - g;
float bDiff = newC.b - b;
targetColor= new Color(r + (rDiff * randomizerIntensity), g + (gDiff * randomizerIntensity), b + (bDiff * randomizerIntensity));
return;
if(r <= minR)
{
addR = true;
}else if(r >= 0.9f)
{
addR = false;
}
if(g <= minG)
{
addG = true;
}else if(g >= 0.9f)
{
addG = false;
}
if(b <= minB)
{
addB = true;
}else if (b >= 0.9f)
{
addB = false;
}
float rA = ((addR) ? Random.Range(0f, 1 - r) : -Random.Range(0f, r / randomizerIntensity)) * intensity * randomizerIntensity;
float rG = ((addG) ? Random.Range(0f, 1 - g) : -Random.Range(0f, g / randomizerIntensity)) *intensity * randomizerIntensity;
float rB = ((addB) ? Random.Range(0f, 1 - b) : -Random.Range(0f, b / randomizerIntensity)) *intensity * randomizerIntensity;
targetColor = new Color(Mathf.Clamp(r+rA,minR,1), Mathf.Clamp(g + rG,minG,1), Mathf.Clamp(b + rB,minB,1));
}
}

View File

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