miss curve

This commit is contained in:
fu-majime 2024-04-05 10:22:27 +09:00
parent 582fb8da83
commit 33086b860a
3 changed files with 70 additions and 24 deletions

View file

@ -134,6 +134,7 @@ MonoBehaviour:
CurveHolder: {fileID: 516527611092978913} CurveHolder: {fileID: 516527611092978913}
ThingsTrans: {fileID: 2062427345527210161} ThingsTrans: {fileID: 2062427345527210161}
PosCurve: {fileID: 1821895289258124684} PosCurve: {fileID: 1821895289258124684}
fallY: -10
--- !u!1 &2761970376181234193 --- !u!1 &2761970376181234193
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -179,9 +180,9 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
curve: {fileID: 1500121995971928353} curve: {fileID: 1500121995971928353}
handleType: 0 handleType: 1
leftHandleLocalPosition: {x: 0.25, y: 4.2, z: 0} leftHandleLocalPosition: {x: 0.25, y: 4.2, z: 0}
rightHandleLocalPosition: {x: -0.25, y: -4.2, z: -0} rightHandleLocalPosition: {x: 0, y: 0, z: -0}
--- !u!1 &2844308134730805784 --- !u!1 &2844308134730805784
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -400,7 +401,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!4 &2554041347942322038 --- !u!4 &2554041347942322038
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -511,7 +512,7 @@ SpriteRenderer:
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: dd5b80f32157bb44386e3d0147282351, type: 3} m_Sprite: {fileID: 21300000, guid: 89cdbc339c5da68499d2877d62cf9018, type: 3}
m_Color: {r: 1, g: 1, b: 0, a: 0.5686275} m_Color: {r: 1, g: 1, b: 0, a: 0.5686275}
m_FlipX: 0 m_FlipX: 0
m_FlipY: 0 m_FlipY: 0
@ -1704,6 +1705,10 @@ PrefabInstance:
propertyPath: m_IsActive propertyPath: m_IsActive
value: 1 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5824484732720336883, guid: 1a184ba123ced3944863abbdb7d41709, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5860934180505614771, guid: 1a184ba123ced3944863abbdb7d41709, type: 3} - target: {fileID: 5860934180505614771, guid: 1a184ba123ced3944863abbdb7d41709, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 12 value: 12

View file

@ -18,13 +18,14 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
public Color color; public Color color;
[System.NonSerialized] public bool goal; [System.NonSerialized] public bool goal;
private bool isMiss;
private BouncyRoad game; private BouncyRoad game;
public void Init() public void Init()
{ {
game = BouncyRoad.instance; game = BouncyRoad.instance;
currentBeat = startBeat;
GetComponent<SpriteRenderer>().color = color; GetComponent<SpriteRenderer>().color = color;
Bounce(); Bounce();
} }
@ -35,6 +36,12 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
if (currentCurve is not null) if (currentCurve is not null)
{ {
float curveProg = cond.GetPositionFromBeat(currentBeat, lengthBeat); float curveProg = cond.GetPositionFromBeat(currentBeat, lengthBeat);
if (isMiss) {
curveProg = cond.GetPositionFromBeat(currentBeat, lengthBeat/2);
} else {
// curveProg /= (float)(1 + BouncyRoad.ngLateTime);
if (curveProg >= 1) curveProg = 1;
}
transform.position = currentCurve.GetPoint(curveProg); transform.position = currentCurve.GetPoint(curveProg);
} }
} }
@ -49,12 +56,17 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
MultiSound.Play(sounds.ToArray()); MultiSound.Play(sounds.ToArray());
var actions = new List<BeatAction.Action>(); var actions = new List<BeatAction.Action>();
actions.Add(new BeatAction.Action(startBeat - lengthBeat, delegate {
currentCurve = curve[0];
currentBeat = startBeat - lengthBeat;
}));
for (int i = 0; i < 12 ; i++) for (int i = 0; i < 12 ; i++)
{ {
int currentItr = i; int currentItr = i;
actions.Add(new BeatAction.Action(startBeat + currentItr * lengthBeat, delegate { actions.Add(new BeatAction.Action(startBeat + currentItr * lengthBeat, delegate {
game.ThingsAnim[currentItr].Play("podium", 0, 0); game.ThingsAnim[currentItr].Play("podium", 0, 0);
currentCurve = curve[currentItr]; currentCurve = curve[1+currentItr];
currentBeat = startBeat + currentItr * lengthBeat; currentBeat = startBeat + currentItr * lengthBeat;
})); }));
} }
@ -67,7 +79,7 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
{ {
SoundByte.PlayOneShotGame("bouncyRoad/ballRight"); SoundByte.PlayOneShotGame("bouncyRoad/ballRight");
game.ThingsAnim[12].Play("podium", 0, 0); game.ThingsAnim[12].Play("podium", 0, 0);
currentCurve = curve[12]; currentCurve = curve[1+12];
currentBeat = startBeat + 12 * lengthBeat; currentBeat = startBeat + 12 * lengthBeat;
game.ScheduleInput(startBeat + 12 * lengthBeat, lengthBeat, BouncyRoad.InputAction_Left, LeftSuccess, LeftMiss, Empty); game.ScheduleInput(startBeat + 12 * lengthBeat, lengthBeat, BouncyRoad.InputAction_Left, LeftSuccess, LeftMiss, Empty);
@ -76,10 +88,12 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
public void RightMiss(PlayerActionEvent caller) public void RightMiss(PlayerActionEvent caller)
{ {
SoundByte.PlayOneShotGame("bouncyRoad/ballBounce"); SoundByte.PlayOneShotGame("bouncyRoad/ballBounce");
currentCurve = curve[^2];
currentBeat = Conductor.instance.songPositionInBeats; currentBeat = Conductor.instance.songPositionInBeats;
isMiss = true;
BeatAction.New(game, new List<BeatAction.Action>() BeatAction.New(game, new List<BeatAction.Action>()
{ {
new BeatAction.Action(startBeat + 13 * lengthBeat, delegate new BeatAction.Action(currentBeat + lengthBeat / 2, delegate
{ {
Destroy(gameObject); Destroy(gameObject);
}), }),
@ -90,7 +104,7 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
{ {
SoundByte.PlayOneShotGame("bouncyRoad/ballLeft"); SoundByte.PlayOneShotGame("bouncyRoad/ballLeft");
game.ThingsAnim[13].Play("podium", 0, 0); game.ThingsAnim[13].Play("podium", 0, 0);
currentCurve = curve[13]; currentCurve = curve[1+13];
currentBeat = startBeat + 13 * lengthBeat; currentBeat = startBeat + 13 * lengthBeat;
if (goal) SoundByte.PlayOneShotGame("bouncyRoad/goal", startBeat + 14 * lengthBeat); if (goal) SoundByte.PlayOneShotGame("bouncyRoad/goal", startBeat + 14 * lengthBeat);
@ -99,7 +113,7 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
new BeatAction.Action(startBeat + 14 * lengthBeat, delegate new BeatAction.Action(startBeat + 14 * lengthBeat, delegate
{ {
game.ThingsAnim[14].Play("podium", 0, 0); game.ThingsAnim[14].Play("podium", 0, 0);
currentCurve = curve[14]; currentCurve = curve[1+14];
currentBeat = startBeat + 14 * lengthBeat; currentBeat = startBeat + 14 * lengthBeat;
}), }),
new BeatAction.Action(startBeat + 15 * lengthBeat, delegate new BeatAction.Action(startBeat + 15 * lengthBeat, delegate
@ -112,10 +126,12 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
public void LeftMiss(PlayerActionEvent caller) public void LeftMiss(PlayerActionEvent caller)
{ {
SoundByte.PlayOneShotGame("bouncyRoad/ballBounce"); SoundByte.PlayOneShotGame("bouncyRoad/ballBounce");
currentCurve = curve[^1];
currentBeat = Conductor.instance.songPositionInBeats; currentBeat = Conductor.instance.songPositionInBeats;
isMiss = true;
BeatAction.New(game, new List<BeatAction.Action>() BeatAction.New(game, new List<BeatAction.Action>()
{ {
new BeatAction.Action(startBeat + 14 * lengthBeat, delegate new BeatAction.Action(currentBeat + lengthBeat / 2, delegate
{ {
Destroy(gameObject); Destroy(gameObject);
}), }),

View file

@ -55,6 +55,8 @@ namespace HeavenStudio.Games
[System.NonSerialized] public Dictionary<float, BezierCurve3D[]> CurveCache; [System.NonSerialized] public Dictionary<float, BezierCurve3D[]> CurveCache;
[SerializeField] BezierCurve3D PosCurve; [SerializeField] BezierCurve3D PosCurve;
[SerializeField] float fallY;
public static BouncyRoad instance; public static BouncyRoad instance;
const int IALeft = 0; const int IALeft = 0;
@ -102,11 +104,11 @@ namespace HeavenStudio.Games
ThingsAnim[childIndex++] = child.GetComponent<Animator>(); ThingsAnim[childIndex++] = child.GetComponent<Animator>();
} }
var newCurves = new BezierCurve3D[ThingsTrans.childCount]; var newCurves = new BezierCurve3D[ThingsTrans.childCount + 3];
// for (var i = 0; i < ThingsAnim.Length; ++i) // for (var i = 0; i < ThingsAnim.Length + 1; ++i)
// { // {
// var prog1 = (float)i/(ThingsTrans.childCount-1); // var prog1 = (float)(i-1)/(ThingsTrans.childCount-1);
// var prog2 = (float)(i+1)/(ThingsTrans.childCount-1); // var prog2 = (float)(i)/(ThingsTrans.childCount-1);
// var pos1 = PosCurve.GetPoint(prog1); // var pos1 = PosCurve.GetPoint(prog1);
// var pos2 = PosCurve.GetPoint(prog2); // var pos2 = PosCurve.GetPoint(prog2);
@ -115,20 +117,28 @@ namespace HeavenStudio.Games
// newCurves[i] = newCurve.GetComponent<BezierCurve3D>(); // newCurves[i] = newCurve.GetComponent<BezierCurve3D>();
// } // }
{ {
Vector3 pos1, pos2;
pos1 = PosCurve.GetPoint((float)(-1)/(ThingsAnim.Length-1));
pos2 = PosCurve.GetPoint(0);
newCurves[0] = GenerateInitCurve(pos1, pos2).GetComponent<BezierCurve3D>();
for (var i = 0; i < ThingsAnim.Length-1; ++i) for (var i = 0; i < ThingsAnim.Length-1; ++i)
{ {
var pos1 = ThingsTrans.GetChild(i).transform.localPosition; pos1 = ThingsTrans.GetChild(i).transform.localPosition;
var pos2 = ThingsTrans.GetChild(i+1).transform.localPosition; pos2 = ThingsTrans.GetChild(i+1).transform.localPosition;
var newCurve = GenerateInitCurve(pos1, pos2); var newCurve = GenerateInitCurve(pos1, pos2);
newCurves[i] = newCurve.GetComponent<BezierCurve3D>(); newCurves[1+i] = newCurve.GetComponent<BezierCurve3D>();
} }
var posA = PosCurve.GetPoint(1);
var posB = PosCurve.GetPoint((float)(ThingsAnim.Length)/(ThingsAnim.Length-1));
newCurves[ThingsAnim.Length-1] = GenerateInitCurve(posA, posB).GetComponent<BezierCurve3D>(); pos1 = PosCurve.GetPoint(1);
pos2 = PosCurve.GetPoint((float)(ThingsAnim.Length)/(ThingsAnim.Length-1));
newCurves[ThingsAnim.Length] = GenerateInitCurve(pos1, pos2).GetComponent<BezierCurve3D>();
} }
newCurves[^2] = GenerateMissCurve(13).GetComponent<BezierCurve3D>();
newCurves[^1] = GenerateMissCurve(14).GetComponent<BezierCurve3D>();
CurveCache = new Dictionary<float, BezierCurve3D[]>(); CurveCache = new Dictionary<float, BezierCurve3D[]>();
CurveCache.Add(1, newCurves); CurveCache.Add(1, newCurves);
} }
@ -161,7 +171,7 @@ namespace HeavenStudio.Games
BeatAction.New(instance, new List<BeatAction.Action>() BeatAction.New(instance, new List<BeatAction.Action>()
{ {
new BeatAction.Action(beat, delegate new BeatAction.Action(beat - length, delegate
{ {
newBall.Init(); newBall.Init();
newBall.gameObject.SetActive(true); newBall.gameObject.SetActive(true);
@ -189,6 +199,21 @@ namespace HeavenStudio.Games
return newCurve; return newCurve;
} }
private Transform GenerateMissCurve(int number)
{
var curve = CurveHolder.GetChild(number);
var newCurve = Instantiate(curve, CurveHolder).transform;
var point0 = newCurve.GetChild(0);
var point1 = newCurve.GetChild(1);
Vector3 pos1 = point1.transform.localPosition;
point1.transform.localPosition = pos1 + new Vector3(0, fallY, 0);
return newCurve;
}
private BezierCurve3D[] GetHeightCurve(float length) private BezierCurve3D[] GetHeightCurve(float length)
{ {
BezierCurve3D[] newCurves; BezierCurve3D[] newCurves;
@ -208,8 +233,8 @@ namespace HeavenStudio.Games
var point1 = child.GetChild(1); var point1 = child.GetChild(1);
Vector3 scale = point0.transform.localScale; Vector3 scale = point0.transform.localScale;
point0.transform.localScale = new Vector3(scale.x, length, scale.z); point0.transform.localScale = new Vector3(scale.x, length * scale.y, scale.z);
point1.transform.localScale = new Vector3(scale.x, length, scale.z); point1.transform.localScale = new Vector3(scale.x, length * scale.y, scale.z);
newCurves[childIndex++] = child.GetComponent<BezierCurve3D>(); newCurves[childIndex++] = child.GetComponent<BezierCurve3D>();
} }
CurveCache.Add(length, newCurves); CurveCache.Add(length, newCurves);