From 552651efbc34bfd80e5f3d06954a37db3cc9e299 Mon Sep 17 00:00:00 2001 From: SoulliesOfficial <77235731+SoulliesOfficial@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:58:39 -0500 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E5=86=85=E5=AE=B9-4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tap,Stay,Flick基础构造 --- .../Base/GeneralSubmodules/EffectSubmodule.cs | 26 ++++++ .../Base/Manager/BasePrefabsCollection.cs | 13 +++ .../GameElements/GeneralEffects/BloomShake.cs | 2 +- Assets/Scripts/GameElements/Notes/Flick.cs | 48 ++++++++-- .../FullScreenBalancedJudgeSubmodule.cs | 14 +-- .../FullScreenNearTimeJudgeSubmodule.cs | 14 +-- .../TouchAreaJudgeSubmodule.cs | 18 ---- .../JudgeSubmodules/TouchAreaJudgeUnit.cs | 11 +++ ...ule.cs.meta => TouchAreaJudgeUnit.cs.meta} | 0 .../TriggerConnectJudgeSubmodule.cs | 14 +-- Assets/Scripts/GameElements/Notes/NoteBase.cs | 93 ++++++++++++++++++- Assets/Scripts/GameElements/Notes/Stay.cs | 46 +++++++-- Assets/Scripts/GameElements/Notes/Tap.cs | 46 +++++++-- .../TrackSubmodules/TrackTimeSubmodule.cs | 2 +- 14 files changed, 269 insertions(+), 78 deletions(-) delete mode 100644 Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeSubmodule.cs create mode 100644 Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeUnit.cs rename Assets/Scripts/GameElements/Notes/JudgeSubmodules/{TouchAreaJudgeSubmodule.cs.meta => TouchAreaJudgeUnit.cs.meta} (100%) diff --git a/Assets/Scripts/Base/GeneralSubmodules/EffectSubmodule.cs b/Assets/Scripts/Base/GeneralSubmodules/EffectSubmodule.cs index 6e6b5a68..6e980d42 100644 --- a/Assets/Scripts/Base/GeneralSubmodules/EffectSubmodule.cs +++ b/Assets/Scripts/Base/GeneralSubmodules/EffectSubmodule.cs @@ -45,6 +45,32 @@ namespace Ichni.RhythmGame this.effectTime = effectTime; this.nowEffectState = EffectState.Before; } + + public virtual void UpdateEffect() + { + EffectState state = CheckEffectState(); + + if (state == EffectState.Before && nowEffectState != EffectState.Before) + { + nowEffectState = EffectState.Before; + Recover(); + } + else if (state == EffectState.Middle) + { + nowEffectState = EffectState.Middle; + Execute(); + } + else if (state == EffectState.After && nowEffectState != EffectState.After) + { + nowEffectState = EffectState.After; + Adjust(); + } + } + + public virtual EffectState CheckEffectState() + { + throw new System.NotImplementedException(); + } /// /// 在效果的持续时间内,触发这个方法 diff --git a/Assets/Scripts/Base/Manager/BasePrefabsCollection.cs b/Assets/Scripts/Base/Manager/BasePrefabsCollection.cs index 678fe610..a1167e05 100644 --- a/Assets/Scripts/Base/Manager/BasePrefabsCollection.cs +++ b/Assets/Scripts/Base/Manager/BasePrefabsCollection.cs @@ -15,6 +15,19 @@ public class BasePrefabsCollection : SerializedScriptableObject public GameObject pathNode; public Material defaultTrackMaterial; + [Title("Note 相关")] + public GameObject tapNote; + public GameObject stayNote; + public GameObject holdNote; + public GameObject flickNote; + public AudioClip tapNoteSound; + public AudioClip stayNoteSound; + public AudioClip holdNoteStartSound; + public AudioClip holdNoteLoopSound; + public AudioClip holdNoteEndSound; + public AudioClip flickNoteSound; + + [Title("Effect相关")] public GameObject bloomShake; } diff --git a/Assets/Scripts/GameElements/GeneralEffects/BloomShake.cs b/Assets/Scripts/GameElements/GeneralEffects/BloomShake.cs index 81281084..73298048 100644 --- a/Assets/Scripts/GameElements/GeneralEffects/BloomShake.cs +++ b/Assets/Scripts/GameElements/GeneralEffects/BloomShake.cs @@ -13,7 +13,7 @@ namespace Ichni.RhythmGame { public float bloomTime; public float bloomPeak; - + [Button("Test Bloom Shake")] public override void Adjust() { diff --git a/Assets/Scripts/GameElements/Notes/Flick.cs b/Assets/Scripts/GameElements/Notes/Flick.cs index a2d51dab..49c40ed5 100644 --- a/Assets/Scripts/GameElements/Notes/Flick.cs +++ b/Assets/Scripts/GameElements/Notes/Flick.cs @@ -1,18 +1,48 @@ using System.Collections; using System.Collections.Generic; +using Lean.Pool; using UnityEngine; -public class Flick : MonoBehaviour +namespace Ichni.RhythmGame { - // Start is called before the first frame update - void Start() + public class Flick : NoteBase { - - } + public List availableFlickDirections; + public static Flick GenerateElement(string elementName, float exactJudgeTime, BaseElement attach, List directions) + { + Flick flick = LeanPool.Spawn(EditorManager.instance.basePrefabs.tapNote, attach.transform).GetComponent(); + flick.NewInitialize(elementName, exactJudgeTime); + flick.availableFlickDirections = directions; + flick.SetParent(attach); + + if (attach.TryGetComponent(out Track track)) + { + if (track.trackTimeSubmodule != null) + { + flick.track = track; + flick.trackPositioner.spline = track.trackPathSubmodule.path; + flick.isOnTrack = true; + flick.UpdateNoteInTrack(); + } + else + { + throw new System.Exception("如果Note要生成在Track上,Track必须有TrackTimeSubmodule组件。"); + } + } + else + { + + } - // Update is called once per frame - void Update() - { + return flick; + } + public void NewInitialize(string elementName, float exactJudgeTime) + { + base.NewInitialize(elementName); + this.exactJudgeTime = exactJudgeTime; + this.track = null; + this.isOnTrack = false; + } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenBalancedJudgeSubmodule.cs b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenBalancedJudgeSubmodule.cs index c1b5c81d..164e9d46 100644 --- a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenBalancedJudgeSubmodule.cs +++ b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenBalancedJudgeSubmodule.cs @@ -2,17 +2,11 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class FullScreenBalancedJudgeSubmodule : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - // Update is called once per frame - void Update() +namespace Ichni.RhythmGame +{ + public class FullScreenBalancedJudgeSubmodule : NoteJudgeUnit { } -} +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenNearTimeJudgeSubmodule.cs b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenNearTimeJudgeSubmodule.cs index 2e7ad04d..3ddb1d75 100644 --- a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenNearTimeJudgeSubmodule.cs +++ b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/FullScreenNearTimeJudgeSubmodule.cs @@ -2,17 +2,11 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class FullScreenNearTimeJudgeSubmodule : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - // Update is called once per frame - void Update() +namespace Ichni.RhythmGame +{ + public class FullScreenNearTimeJudgeSubmodule : NoteJudgeUnit { } -} +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeSubmodule.cs b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeSubmodule.cs deleted file mode 100644 index bcc6cc7e..00000000 --- a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeSubmodule.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class TouchAreaJudgeSubmodule : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeUnit.cs b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeUnit.cs new file mode 100644 index 00000000..4cb2f5a1 --- /dev/null +++ b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeUnit.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Ichni.RhythmGame +{ + public class TouchAreaJudgeUnit : NoteJudgeUnit + { + + } +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeSubmodule.cs.meta b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeUnit.cs.meta similarity index 100% rename from Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeSubmodule.cs.meta rename to Assets/Scripts/GameElements/Notes/JudgeSubmodules/TouchAreaJudgeUnit.cs.meta diff --git a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TriggerConnectJudgeSubmodule.cs b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TriggerConnectJudgeSubmodule.cs index 6f5029ca..4d235f96 100644 --- a/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TriggerConnectJudgeSubmodule.cs +++ b/Assets/Scripts/GameElements/Notes/JudgeSubmodules/TriggerConnectJudgeSubmodule.cs @@ -2,17 +2,11 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class TriggerConnectJudgeSubmodule : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - // Update is called once per frame - void Update() +namespace Ichni.RhythmGame +{ + public class TriggerConnectJudgeSubmodule : NoteJudgeUnit { } -} +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/NoteBase.cs b/Assets/Scripts/GameElements/Notes/NoteBase.cs index 5bc965a1..c6440180 100644 --- a/Assets/Scripts/GameElements/Notes/NoteBase.cs +++ b/Assets/Scripts/GameElements/Notes/NoteBase.cs @@ -7,7 +7,7 @@ using UnityEngine; namespace Ichni.RhythmGame { - public class NoteBase : BaseElement + public abstract class NoteBase : BaseElement { [Title("Basic Info")] public float exactJudgeTime; @@ -40,5 +40,96 @@ namespace Ichni.RhythmGame [Title("In-Game Info")] public Vector2 noteScreenPosition; public bool isJudged; + + /// + /// 在MovableTrack上更新Note的位置,注意HoldNote需要重写这个方法 + /// + public virtual void UpdateNoteInMovableTrack() + { + trackPositioner.SetPercent((track.trackTimeSubmodule as TrackTimeSubmoduleMovable).GetTrackPercent(exactJudgeTime)); + } + + /// + /// 在StaticTrack上更新Note的位置,注意HoldNote需要重写这个方法 + /// + public virtual void UpdateNoteInStaticTrack() + { + float songTime = EditorManager.instance.songModule.songTime; + TrackTimeSubmoduleStatic trackTimeSubmoduleStatic = track.trackTimeSubmodule as TrackTimeSubmoduleStatic; + + float startMove = exactJudgeTime - trackTimeSubmoduleStatic.trackTotalTime; + float percent = AnimationCurveEvaluator.Evaluate(trackTimeSubmoduleStatic.animationCurveType, (songTime - startMove) / trackTimeSubmoduleStatic.trackTotalTime); + + percent = Mathf.Max(percent, 0); + percent = Mathf.Min(percent, 1); + + trackPositioner.SetPercent(1 - percent); + } + + public override void AfterInitialize() + { + generateEffects.effectList.ForEach(e => e.Recover()); + generalJudgeEffects.effectList.ForEach(e => e.Recover()); + perfectJudgeEffects.effectList.ForEach(e => e.Recover()); + goodJudgeEffects.effectList.ForEach(e => e.Recover()); + badJudgeEffects.effectList.ForEach(e => e.Recover()); + missJudgeEffects.effectList.ForEach(e => e.Recover()); + } + + private void Update() + { + if (isOnTrack) + { + if (track.trackTimeSubmodule is TrackTimeSubmoduleStatic) + { + UpdateNoteInStaticTrack(); + } + } + + float songTime = EditorManager.instance.songModule.songTime; + + if (isJudged && songTime < exactJudgeTime) + { + isJudged = false; + } + + if (!isJudged && songTime >= exactJudgeTime) + { + if (!isJudged) + { + AudioSource.PlayClipAtPoint(EditorManager.instance.basePrefabs.tapNoteSound, Camera.main.transform.position, 1f); + isJudged = true; + } + } + + foreach (var effect in generateEffects.effectList) + { + effect.UpdateEffect(); + } + foreach (var effect in perfectJudgeEffects.effectList) + { + effect.UpdateEffect(); + } + } + + public void ExecuteStartJudge() + { + + } + + public void UpdateNoteInTrack() + { + if (isOnTrack && track.trackTimeSubmodule != null) + { + if (track.trackTimeSubmodule is TrackTimeSubmoduleMovable) + { + UpdateNoteInMovableTrack(); + } + else if (track.trackTimeSubmodule is TrackTimeSubmoduleStatic) + { + UpdateNoteInStaticTrack(); + } + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/Stay.cs b/Assets/Scripts/GameElements/Notes/Stay.cs index af5af878..7a39c2a7 100644 --- a/Assets/Scripts/GameElements/Notes/Stay.cs +++ b/Assets/Scripts/GameElements/Notes/Stay.cs @@ -1,18 +1,46 @@ using System.Collections; using System.Collections.Generic; +using Lean.Pool; using UnityEngine; -public class Stay : MonoBehaviour +namespace Ichni.RhythmGame { - // Start is called before the first frame update - void Start() + public class Stay : NoteBase { - - } + public static Stay GenerateElement(string elementName, float exactJudgeTime, BaseElement attach) + { + Stay stay = LeanPool.Spawn(EditorManager.instance.basePrefabs.tapNote, attach.transform).GetComponent(); + stay.NewInitialize(elementName, exactJudgeTime); + stay.SetParent(attach); + + if (attach.TryGetComponent(out Track track)) + { + if (track.trackTimeSubmodule != null) + { + stay.track = track; + stay.trackPositioner.spline = track.trackPathSubmodule.path; + stay.isOnTrack = true; + stay.UpdateNoteInTrack(); + } + else + { + throw new System.Exception("如果Note要生成在Track上,Track必须有TrackTimeSubmodule组件。"); + } + } + else + { + + } - // Update is called once per frame - void Update() - { + return stay; + } + public void NewInitialize(string elementName, float exactJudgeTime) + { + base.NewInitialize(elementName); + this.exactJudgeTime = exactJudgeTime; + this.track = null; + this.isOnTrack = false; + } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Notes/Tap.cs b/Assets/Scripts/GameElements/Notes/Tap.cs index 34f33960..97beadfe 100644 --- a/Assets/Scripts/GameElements/Notes/Tap.cs +++ b/Assets/Scripts/GameElements/Notes/Tap.cs @@ -1,18 +1,46 @@ using System.Collections; using System.Collections.Generic; +using Lean.Pool; using UnityEngine; -public class Tap : MonoBehaviour +namespace Ichni.RhythmGame { - // Start is called before the first frame update - void Start() + public class Tap : NoteBase { - - } + public static Tap GenerateElement(string elementName, float exactJudgeTime, BaseElement attach) + { + Tap tap = LeanPool.Spawn(EditorManager.instance.basePrefabs.tapNote, attach.transform).GetComponent(); + tap.NewInitialize(elementName, exactJudgeTime); + tap.SetParent(attach); + + if (attach.TryGetComponent(out Track track)) + { + if (track.trackTimeSubmodule != null) + { + tap.track = track; + tap.trackPositioner.spline = track.trackPathSubmodule.path; + tap.isOnTrack = true; + tap.UpdateNoteInTrack(); + } + else + { + throw new System.Exception("如果Note要生成在Track上,Track必须有TrackTimeSubmodule组件。"); + } + } + else + { + + } - // Update is called once per frame - void Update() - { + return tap; + } + public void NewInitialize(string elementName, float exactJudgeTime) + { + base.NewInitialize(elementName); + this.exactJudgeTime = exactJudgeTime; + this.track = null; + this.isOnTrack = false; + } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/GameElements/Track/TrackSubmodules/TrackTimeSubmodule.cs b/Assets/Scripts/GameElements/Track/TrackSubmodules/TrackTimeSubmodule.cs index 64d9f899..f50cb566 100644 --- a/Assets/Scripts/GameElements/Track/TrackSubmodules/TrackTimeSubmodule.cs +++ b/Assets/Scripts/GameElements/Track/TrackSubmodules/TrackTimeSubmodule.cs @@ -45,7 +45,7 @@ namespace Ichni.RhythmGame } } - private float GetTrackPercent(float songTimeInTime) + public float GetTrackPercent(float songTimeInTime) { float per = AnimationCurveEvaluator.Evaluate(animationCurveType, (songTimeInTime - trackStartTime) / trackTotalTime); return Mathf.Clamp01(per);