HeavenStudio/Assets/Scripts/Games/BuiltToScaleRvl/Square.cs
フマジメ cb3304d217
Built To Scale (Wii) (#804)
* prefab

* Spawn Rod

* Shoot Rod

* Square

* Shoot Rod EX

* Custom Bounce

* Fix spawn

* fix animation

* Change Block

* Change Block Animation

* Destroy Square

* Fix block's transition

* Shoot Rod (mute)

* High Curve

* animation tweaks, revert to old spritesheet

* more accurate placement

* more animations

* finished anims

* all animations done

* shake more

* Minor correction

* fixed square rotations

* upscale

* icon

* Add miss curve and Toggle Blocks

---------

Co-authored-by: ev <85412919+iloveoatmeal2022@users.noreply.github.com>
2024-03-27 15:22:51 +00:00

64 lines
1.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using NaughtyBezierCurves;
namespace HeavenStudio.Games.Scripts_BuiltToScaleRvl
{
using HeavenStudio.Util;
public class Square : MonoBehaviour
{
public string anim;
public double startBeat, targetBeat, lengthBeat = 1;
public int endTime;
public Vector3 CorrectionPos;
private Animator squareAnim;
private BuiltToScaleRvl game;
public void Init()
{
game = BuiltToScaleRvl.instance;
squareAnim = GetComponent<Animator>();
var endTime = (int)Math.Ceiling((targetBeat - startBeat)/lengthBeat);
transform.position = transform.position - endTime * CorrectionPos;
double beat = targetBeat - lengthBeat * endTime;
squareAnim.Play(anim, 0, (beat==0 ? 0 : 1));
Recursion(beat, lengthBeat);
}
private void Recursion(double beat, double length)
{
if (beat > targetBeat + 10 * lengthBeat) End();
BeatAction.New(this, new List<BeatAction.Action>()
{
new BeatAction.Action(beat + length, delegate
{
transform.position = transform.position + CorrectionPos;
squareAnim.Play(anim, 0, 0);
Recursion(beat + length, length);
}),
});
}
void PositionCorrection()
{
var pos = transform.position;
Debug.Log(transform.position);
transform.position = pos + CorrectionPos;
Debug.Log(transform.position);
}
void ChangeSortingOrder(int order)
{
GetComponent<SortingGroup>().sortingOrder = order;
}
void End()
{
Destroy(gameObject);
}
}
}