基础内容-2

Track Percent Point 和 Track Head Point 重构优化

Note基础

特效框架(Effect Submodule 和 Effect基础类),将用于“时间触发型特效容器”与“Note特效容器“
This commit is contained in:
SoulliesOfficial
2025-01-27 10:29:38 -05:00
parent 8d0abec75f
commit 8d887d5a7c
25 changed files with 449 additions and 102 deletions

View File

@@ -28,3 +28,5 @@ MonoBehaviour:
track: {fileID: 8828428123186639208, guid: 20234a708961745eeafa459c79524348, type: 3}
pathNode: {fileID: 7248180033186031075, guid: 609cdf441cd2f4c78a430e7df78a40f4,
type: 3}
defaultTrackMaterial: {fileID: 2100000, guid: 2424431729f1047c4b42f971c2cdd2b6,
type: 2}

View File

@@ -0,0 +1,171 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: DefaultTrackMaterial
m_Shader: {fileID: 211, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- GRABPASS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BlendOp: 0
- _BumpScale: 1
- _CameraFadingEnabled: 0
- _CameraFarFadeDistance: 2
- _CameraNearFadeDistance: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _ColorMode: 0
- _Cull: 0
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DistortionBlend: 0.5
- _DistortionEnabled: 0
- _DistortionStrength: 1
- _DistortionStrengthScaled: 0
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EmissionEnabled: 0
- _EnableExternalAlpha: 0
- _EnvironmentReflections: 1
- _FlipbookMode: 0
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossinessSource: 0
- _GlossyReflections: 0
- _LightingEnabled: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0
- _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 0
- _SoftParticlesFarFadeDistance: 1
- _SoftParticlesNearFadeDistance: 0
- _SpecSource: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _ColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
--- !u!114 &2523386628062252728
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 7

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2424431729f1047c4b42f971c2cdd2b6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -19,7 +19,8 @@ namespace Ichni
public float totalTime; //总时间
public AnimationCurveType animationCurveType; //动画曲线类型
public AnimatedFloat(float startTime, float endTime, float startValue, float endValue, AnimationCurveType animationCurveType)
public AnimatedFloat(float startTime, float endTime, float startValue, float endValue,
AnimationCurveType animationCurveType)
{
this.startValue = startValue;
this.endValue = endValue;
@@ -66,8 +67,8 @@ namespace Ichni
{
animations.Sort();
}
/// <summary>
/// 在动画脚本的Update中更新value
/// </summary>
@@ -78,7 +79,8 @@ namespace Ichni
if (nowAnimatedFloat != null) //如果能获取到,表明当前时间点存在动画
{
//获取songTime时间点时基于动画曲线的AnimatedFloat比例点->01
float nowPercent = AnimationCurveEvaluator.Evaluate(nowAnimatedFloat.animationCurveType, (nowTime - nowAnimatedFloat.startTime) / nowAnimatedFloat.totalTime);
float nowPercent = AnimationCurveEvaluator.Evaluate(nowAnimatedFloat.animationCurveType,
(nowTime - nowAnimatedFloat.startTime) / nowAnimatedFloat.totalTime);
value = nowAnimatedFloat.startValue + nowPercent * nowAnimatedFloat.differenceValue; //计算value
returnType = FlexibleReturnType.MiddleExecuting;
return;
@@ -98,10 +100,11 @@ namespace Ichni
{
value = nowAnimatedFloat.startValue;
}
returnType = FlexibleReturnType.Before;
return;
}
if (nowTime > finalEndTime) //如果当前时间大于最后一个动画的结束时间
{
nowAnimatedFloat = animations[animations.Count - 1];
@@ -111,14 +114,16 @@ namespace Ichni
{
value = nowAnimatedFloat.endValue;
}
returnType = FlexibleReturnType.After;
return;
}
if (currentAnimationIndex >= 0)//如果当前时间点在动画之间
if (currentAnimationIndex >= 0) //如果当前时间点在动画之间
{
value = animations[currentAnimationIndex].endValue;
}
returnType = FlexibleReturnType.MiddleInterval;
return;
}
@@ -147,88 +152,5 @@ namespace Ichni
return null;
}
// [BurstCompile]
// public void UpdateFlexibleFloat(float nowTime)
// {
// var animationData = new NativeArray<AnimatedFloat>(animations.ToArray(), Allocator.TempJob);
// var result = new NativeArray<float>(1, Allocator.TempJob);
// var returnTypeResult = new NativeArray<FlexibleReturnType>(1, Allocator.TempJob);
//
// var job = new FlexibleFloatJob
// {
// nowTime = nowTime,
// animationData = animationData,
// result = result,
// returnTypeResult = returnTypeResult
// };
//
// var handle = job.Schedule();
// handle.Complete();
//
// value = result[0];
// returnType = returnTypeResult[0];
//
// animationData.Dispose();
// result.Dispose();
// returnTypeResult.Dispose();
// }
}
/*
[BurstCompile]
struct FlexibleFloatJob : IJob
{
public float nowTime;
[ReadOnly] public NativeArray<AnimatedFloat> animationData;
public NativeArray<float> result;
public NativeArray<FlexibleReturnType> returnTypeResult;
public void Execute()
{
FlexibleReturnType currentReturnType = FlexibleReturnType.None;
float outputValue = 0;
if(animationData.Length == 0)
{
result[0] = outputValue;
returnTypeResult[0] = currentReturnType;
return;
}
if (nowTime < animationData[0].startTime)
{
outputValue = animationData[0].startValue;
currentReturnType = FlexibleReturnType.Before;
}
else if (nowTime > animationData[animationData.Length - 1].endTime)
{
outputValue = animationData[animationData.Length - 1].endValue;
currentReturnType = FlexibleReturnType.After;
}
for (int i = 0; i < animationData.Length; i++)
{
var anim = animationData[i];
if (nowTime >= anim.startTime && nowTime <= anim.endTime)
{
float nowPercent = AnimationCurveEvaluator.Evaluate(anim.animationCurveType,(nowTime - anim.startTime) / anim.totalTime);
outputValue = anim.startValue + nowPercent * anim.differenceValue;
currentReturnType = FlexibleReturnType.MiddleExecuting;
break;
}
}
if (currentReturnType == FlexibleReturnType.None)
{
currentReturnType = FlexibleReturnType.MiddleInterval;
}
result[0] = outputValue;
returnTypeResult[0] = currentReturnType;
}
}*/
}

View File

@@ -28,6 +28,10 @@ namespace Ichni.RhythmGame
this.emissionEnabled = false;
this.originalEmissionColor = Color.black;
this.originalEmissionIntensity = 0;
this.currentBaseColor = originalBaseColor;
this.currentEmissionColor = Color.black;
this.currentEmissionIntensity = 0;
}
public ColorSubmodule(Color originalBaseColor, bool emissionEnabled, Color originalEmissionColor, float originalEmissionIntensity)
@@ -36,6 +40,10 @@ namespace Ichni.RhythmGame
this.emissionEnabled = emissionEnabled;
this.originalEmissionColor = originalEmissionColor;
this.originalEmissionIntensity = originalEmissionIntensity;
this.currentBaseColor = originalBaseColor;
this.currentEmissionColor = originalEmissionColor;
this.currentEmissionIntensity = originalEmissionIntensity;
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class EffectSubmodule : SubmoduleBase
{
public List<EffectBase> effectList;
}
public abstract class EffectBase
{
public abstract void Execute();
}
}

View File

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

View File

@@ -9,6 +9,9 @@ public class BasePrefabsCollection : SerializedScriptableObject
[Title("基础预制体")]
public GameObject emptyObject;
public GameObject elementFolder;
[Title("Track相关")]
public GameObject track;
public GameObject pathNode;
public Material defaultTrackMaterial;
}

View File

@@ -30,7 +30,7 @@ namespace Ichni
(t0.trackTimeSubmodule as TrackTimeSubmoduleMovable).NewInitialize(t0, 0, 1, 1, AnimationCurveType.Linear);
(t0.trackRendererSubmodule as TrackRendererSubmoduleAutoOrient).NewInitialize(t0);
var p0 = PathNode.GeneratePathNode("PathNode-0", t0, 0, Vector3.zero, Vector3.forward, 1, Color.white);
var p1 = PathNode.GeneratePathNode("PathNode-1", t0, 1, Vector3.one * 10f, Vector3.left, 0, Color.white);
var p1 = PathNode.GeneratePathNode("PathNode-1", t0, 1, Vector3.one * 10f, Vector3.left, 0, Color.red);
t0.AfterInitialize();
}

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PostProcessingManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2f9d3b833668d4a309f2dc75315c18e8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 62e1a33dede934d3fb2c3282b6641d59
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class NoteBase : BaseElement
{
[Title("Basic Info")]
public float exactJudgeTime;
[Title("Track Info")]
public bool isOnTrack;
public Track track;
public SplinePositioner trackPositioner;
// [Title("NoteVisual")]
// public GeneralNoteVisual noteVisual;
//
// [Title("NoteEffect")]
// public List<NoteEffectGenerate> noteEffectGenerateList;
// public List<NoteEffectPerfect> noteEffectPerfectList;
// public List<NoteEffectGood> noteEffectGoodList;
// public List<NoteEffectMiss> noteEffectMissList;
[Title("In-Game Info")]
public Vector2 noteScreenPosition;
public bool isJudged;
}
}

View File

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

View File

@@ -34,11 +34,6 @@ namespace Ichni.RhythmGame
this.track = track;
this.index = index;
if (track.trackPathSubmodule.pathNodeList.Count > index)
{
this.index = track.trackPathSubmodule.pathNodeList.Count;
}
this.transformSubmodule = new TransformSubmodule(nodePosition, Quaternion.LookRotation(nodeNormal, Vector3.up).eulerAngles, Vector3.one * nodeSize);
this.colorSubmodule = new ColorSubmodule(nodeColor);

View File

@@ -40,8 +40,7 @@ namespace Ichni.RhythmGame
public override void AfterInitialize()
{
trackPathSubmodule.path.RebuildImmediate();
//Refresh();
}
private void Update()

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 50c407d9db7cf4ed096db0106bdc3c0c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Lean.Pool;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class TrackHeadPoint : BaseElement
{
public Track track;
public TrackTimeSubmoduleMovable trackTimeSubmoduleMovable;
public SplinePositioner trackPositioner;
public static TrackHeadPoint GenerateElement(string elementName, Track track)
{
TrackHeadPoint head = LeanPool.Spawn(EditorManager.instance.basePrefabs.emptyObject, track.transform).AddComponent<TrackHeadPoint>();
head.NewInitialize(elementName, track);
head.SetParent(track);
return head;
}
private void NewInitialize(string elementName, Track track)
{
base.NewInitialize(elementName);
this.track = track;
this.trackPositioner = gameObject.AddComponent<SplinePositioner>();
this.trackPositioner.spline = track.trackPathSubmodule.path;
this.trackTimeSubmoduleMovable = track.trackTimeSubmodule as TrackTimeSubmoduleMovable;
}
public void Update()
{
if (track.timeDurationSubmodule.CheckTimeInDuration(EditorManager.instance.songModule.songTime))
{
trackPositioner.SetPercent(trackTimeSubmoduleMovable.headPercent);
}
}
}
}

View File

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

View File

@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Lean.Pool;
using UniRx;
using UnityEngine;
namespace Ichni.RhythmGame
{
/// <summary>
/// 在轨道上根据百分比进行运动的点
/// </summary>
public class TrackPercentPoint : BaseElement
{
public Track track;
public SplinePositioner trackPositioner;
public FlexibleFloat trackPercent;
public static TrackPercentPoint GenerateElement(string elementName, Track track, FlexibleFloat trackPercent)
{
TrackPercentPoint point = LeanPool.Spawn(EditorManager.instance.basePrefabs.emptyObject, track.transform).AddComponent<TrackPercentPoint>();
point.NewInitialize(elementName, track, trackPercent);
point.SetParent(track);
return point;
}
private void NewInitialize(string elementName, Track track, FlexibleFloat trackPercent)
{
base.NewInitialize(elementName);
this.track = track;
this.trackPositioner = gameObject.AddComponent<SplinePositioner>();
this.trackPositioner.spline = track.trackPathSubmodule.path;
this.trackPercent = trackPercent;
}
public void Update()
{
if (trackPercent.animations.Count > 0)
{
trackPercent.UpdateFlexibleFloat(EditorManager.instance.songModule.songTime);
if (trackPercent.returnType == FlexibleReturnType.MiddleExecuting)
{
trackPositioner.SetPercent(trackPercent.value);
}
}
}
}
}

View File

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

View File

@@ -11,25 +11,29 @@ namespace Ichni.RhythmGame
public Track track;
public MeshGenerator meshGenerator;
public MeshRenderer meshRenderer;
public Material renderMaterial;
}
public class TrackRendererSubmoduleAutoOrient : TrackRendererSubmodule
{
public SplineRenderer splineRenderer;
public void NewInitialize(Track track)
public void NewInitialize(Track track, Material material = null)
{
this.track = track;
this.track.trackRendererSubmodule = this;
this.splineRenderer = track.AddComponent<SplineRenderer>();
this.meshRenderer = splineRenderer.GetComponent<MeshRenderer>();
this.meshGenerator = splineRenderer;
this.renderMaterial = material == null ? EditorManager.instance.basePrefabs.defaultTrackMaterial : material;
this.splineRenderer.spline = track.trackPathSubmodule.path;
this.splineRenderer.clipFrom = 0;
this.splineRenderer.clipTo = 1;
this.meshRenderer.material = renderMaterial;
Debug.Log(splineRenderer.clipFrom + " " + splineRenderer.clipTo);
this.splineRenderer.color = Color.white;
}
public override void InitialRefresh()
{
if (track.trackTimeSubmodule is TrackTimeSubmoduleMovable)

View File

@@ -37,9 +37,7 @@ namespace Ichni.RhythmGame
headPercent = GetTrackPercent(songTime);
tailPercent = GetTrackPercent(songTime - visibleTrackTimeLength);
Debug.Log("Head: " + headPercent + " Tail: " + tailPercent);
if (track.trackRendererSubmodule != null)
{
track.trackRendererSubmodule.meshGenerator.clipFrom = tailPercent;