STARS BLINK NOW

This commit is contained in:
Rapandrasmus 2023-06-24 22:22:15 +02:00
parent a06b6a4e9b
commit 1fcaaf1e29
3 changed files with 68 additions and 4 deletions

View file

@ -36,7 +36,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0

View file

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using HeavenStudio.Util; using HeavenStudio.Util;
using System;
namespace HeavenStudio.Games.Scripts_AgbNightWalk namespace HeavenStudio.Games.Scripts_AgbNightWalk
{ {
@ -11,7 +12,8 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk
private float originY; private float originY;
private AgbStarHandler handler; private AgbStarHandler handler;
private Animator anim; private Animator anim;
private int evoStage = 1; [NonSerialized] public int evoStage = 1;
private bool devolved = false;
private void Awake() private void Awake()
{ {
@ -33,19 +35,25 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk
public void Blink() public void Blink()
{ {
anim.Play("Blink" + evoStage, 0, 0); if (devolved) return;
if (anim.IsAnimationNotPlaying())
{
anim.Play("Blink" + evoStage, 0, 0);
}
} }
public void Evolve() public void Evolve()
{ {
if (evoStage >= 5) return; if (evoStage >= 5 || devolved) return;
anim.Play("Evolve" + evoStage, 0, 0); anim.Play("Evolve" + evoStage, 0, 0);
evoStage++; evoStage++;
} }
public void Devolve() public void Devolve()
{ {
if (devolved) return;
anim.Play("Devolve" + evoStage, 0, 0); anim.Play("Devolve" + evoStage, 0, 0);
devolved = true;
} }
} }
} }

View file

@ -14,18 +14,63 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk
public float boundaryY = 10; public float boundaryY = 10;
[SerializeField] private int starCount = 45; [SerializeField] private int starCount = 45;
[SerializeField] private double blinkFrequency = 0.125;
[SerializeField] private int blinkAmount = 5;
[NonSerialized] public float normalizedX; [NonSerialized] public float normalizedX;
[NonSerialized] public float normalizedY; [NonSerialized] public float normalizedY;
private AgbStar[] currentStars;
private int collectiveEvoStage = 1;
private GameEvent blinkEvent = new GameEvent();
private void Awake() private void Awake()
{ {
currentStars = new AgbStar[starCount];
for (int i = 0; i < starCount; i++) for (int i = 0; i < starCount; i++)
{ {
AgbStar spawnedStar = Instantiate(starRef, transform); AgbStar spawnedStar = Instantiate(starRef, transform);
float xPos = UnityEngine.Random.Range(-boundaryX, boundaryX); float xPos = UnityEngine.Random.Range(-boundaryX, boundaryX);
float yPos = UnityEngine.Random.Range(-boundaryY, boundaryY); float yPos = UnityEngine.Random.Range(-boundaryY, boundaryY);
spawnedStar.Init(xPos, yPos, this); spawnedStar.Init(xPos, yPos, this);
currentStars[i] = spawnedStar;
}
}
private void Update()
{
var cond = Conductor.instance;
if (cond.isPlaying && !cond.isPaused)
{
if (ReportBlinkBeat(ref blinkEvent.lastReportedBeat))
{
Blink();
}
}
}
private void Blink()
{
for (int i = 0; i < blinkAmount; i++)
{
currentStars[UnityEngine.Random.Range(0, currentStars.Length)].Blink();
}
}
public void Evolve(int amount)
{
for (int i = 0; i < amount; i++)
{
currentStars[UnityEngine.Random.Range(0, currentStars.Length)].Evolve();
}
}
public void Devolve()
{
foreach (var star in currentStars)
{
star.Devolve();
} }
} }
@ -61,6 +106,17 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk
Gizmos.color = Color.blue; Gizmos.color = Color.blue;
Gizmos.DrawWireCube(Vector3.zero, new Vector3(boundaryX, boundaryY, 0)); Gizmos.DrawWireCube(Vector3.zero, new Vector3(boundaryX, boundaryY, 0));
} }
private bool ReportBlinkBeat(ref double lastReportedBeat)
{
var cond = Conductor.instance;
bool result = cond.songPositionInBeats >= (lastReportedBeat) + blinkFrequency;
if (result)
{
lastReportedBeat += blinkFrequency;
}
return result;
}
} }
} }