完成Note预制体的创建体系
This commit is contained in:
@@ -48,6 +48,14 @@ namespace Demo.Game
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
foreach (var child in Prefabs)
|
||||
{
|
||||
child.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnBegin()
|
||||
{
|
||||
foreach (var child in Prefabs)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Convention;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -19,6 +18,7 @@ namespace Demo.Game
|
||||
[Content, SerializeField] private IInteraction MyInteractionModule;
|
||||
[Content, SerializeField] private InteractiveEffectType MyInteractiveLevel = default;
|
||||
|
||||
public abstract void OnInit();
|
||||
public abstract void OnBegin();
|
||||
public abstract void OnEnd();
|
||||
|
||||
@@ -31,24 +31,28 @@ namespace Demo.Game
|
||||
{
|
||||
case InteractiveEffectType.VisibleDuration:
|
||||
{
|
||||
MyInteractionModule.VisibleDurationBeforeEvent.AddListener(OnInit);
|
||||
MyInteractionModule.VisibleDurationBeginEvent.AddListener(OnBegin);
|
||||
MyInteractionModule.VisibleDurationEndEvent.AddListener(OnEnd);
|
||||
}
|
||||
break;
|
||||
case InteractiveEffectType.InteractiveDuration:
|
||||
{
|
||||
MyInteractionModule.InteractiveDurationBeforeEvent.AddListener(OnInit);
|
||||
MyInteractionModule.InteractiveDurationBeginEvent.AddListener(OnBegin);
|
||||
MyInteractionModule.InteractiveDurationEndEvent.AddListener(OnEnd);
|
||||
}
|
||||
break;
|
||||
case InteractiveEffectType.InteractableScoreInterval:
|
||||
{
|
||||
MyInteractionModule.InteractableScoreIntervalBeforeEvent.AddListener(OnInit);
|
||||
MyInteractionModule.InteractableScoreIntervalBeginEvent.AddListener(OnBegin);
|
||||
MyInteractionModule.InteractableScoreIntervalEndEvent.AddListener(OnEnd);
|
||||
}
|
||||
break;
|
||||
case InteractiveEffectType.InteractableIntervalThatCanScoreBest:
|
||||
{
|
||||
MyInteractionModule.InteractableIntervalThatCanScoreBestBeforeEvent.AddListener(OnInit);
|
||||
MyInteractionModule.InteractableIntervalThatCanScoreBestBeginEvent.AddListener(OnBegin);
|
||||
MyInteractionModule.InteractableIntervalThatCanScoreBestEndEvent.AddListener(OnEnd);
|
||||
}
|
||||
@@ -65,24 +69,28 @@ namespace Demo.Game
|
||||
{
|
||||
case InteractiveEffectType.VisibleDuration:
|
||||
{
|
||||
MyInteractionModule.VisibleDurationBeforeEvent.RemoveListener(OnInit);
|
||||
MyInteractionModule.VisibleDurationBeginEvent.RemoveListener(OnBegin);
|
||||
MyInteractionModule.VisibleDurationEndEvent.RemoveListener(OnEnd);
|
||||
}
|
||||
break;
|
||||
case InteractiveEffectType.InteractiveDuration:
|
||||
{
|
||||
MyInteractionModule.InteractiveDurationBeforeEvent.RemoveListener(OnInit);
|
||||
MyInteractionModule.InteractiveDurationBeginEvent.RemoveListener(OnBegin);
|
||||
MyInteractionModule.InteractiveDurationEndEvent.RemoveListener(OnEnd);
|
||||
}
|
||||
break;
|
||||
case InteractiveEffectType.InteractableScoreInterval:
|
||||
{
|
||||
MyInteractionModule.InteractableScoreIntervalBeforeEvent.RemoveListener(OnInit);
|
||||
MyInteractionModule.InteractableScoreIntervalBeginEvent.RemoveListener(OnBegin);
|
||||
MyInteractionModule.InteractableScoreIntervalEndEvent.RemoveListener(OnEnd);
|
||||
}
|
||||
break;
|
||||
case InteractiveEffectType.InteractableIntervalThatCanScoreBest:
|
||||
{
|
||||
MyInteractionModule.InteractableIntervalThatCanScoreBestBeforeEvent.RemoveListener(OnInit);
|
||||
MyInteractionModule.InteractableIntervalThatCanScoreBestBeginEvent.RemoveListener(OnBegin);
|
||||
MyInteractionModule.InteractableIntervalThatCanScoreBestEndEvent.RemoveListener(OnEnd);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Convention;
|
||||
using Demo.Editor.UI;
|
||||
using UnityEngine;
|
||||
@@ -19,6 +19,7 @@ namespace Demo.Game
|
||||
item.SetupDuration(new(VisibleDuration.x, VisibleDuration.y), GetTimelineItemColor());
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public enum DurationStats
|
||||
{
|
||||
BeforeBegin = 0,
|
||||
@@ -27,24 +28,34 @@ namespace Demo.Game
|
||||
Judgement
|
||||
}
|
||||
|
||||
public const float IdentifiableJudgementTerminal = 0.16f;
|
||||
|
||||
[Header(nameof(VisibleDuration))]
|
||||
[Content, SerializeField] private Vector2 VisibleDuration;
|
||||
[Content, SerializeField] public UnityEvent VisibleDurationBeginEvent = new(), VisibleDurationEndEvent = new();
|
||||
public static float DefaultVisibleLength = IdentifiableJudgementTerminal * 15;
|
||||
[Content, SerializeField] public UnityEvent VisibleDurationBeforeEvent = new(),
|
||||
VisibleDurationBeginEvent = new(), VisibleDurationEndEvent = new();
|
||||
[Content, SerializeField] private DurationStats VisibleDurationStats = default;
|
||||
|
||||
[Header(nameof(InteractiveDuration))]
|
||||
[Content, SerializeField] private Vector2 InteractiveDuration;
|
||||
[Content, SerializeField] public UnityEvent InteractiveDurationBeginEvent = new(), InteractiveDurationEndEvent = new();
|
||||
public static float DefaultInteractiveLength = IdentifiableJudgementTerminal * 9;
|
||||
[Content, SerializeField] public UnityEvent InteractiveDurationBeforeEvent = new(),
|
||||
InteractiveDurationBeginEvent = new(), InteractiveDurationEndEvent = new();
|
||||
[Content, SerializeField] private DurationStats InteractiveDurationStats = default;
|
||||
|
||||
[Header(nameof(InteractableScoreInterval))]
|
||||
[Content, SerializeField] private Vector2 InteractableScoreInterval;
|
||||
[Content, SerializeField] public UnityEvent InteractableScoreIntervalBeginEvent = new(), InteractableScoreIntervalEndEvent = new();
|
||||
public static float DefaultInteractableScoreIntervalLength = IdentifiableJudgementTerminal * 6;
|
||||
[Content, SerializeField] public UnityEvent InteractableScoreIntervalBeforeEvent = new(),
|
||||
InteractableScoreIntervalBeginEvent = new(), InteractableScoreIntervalEndEvent = new();
|
||||
[Content, SerializeField] private DurationStats InteractableScoreIntervalStats = default;
|
||||
|
||||
[Header(nameof(InteractableIntervalThatCanScoreBest))]
|
||||
[Content, SerializeField] private Vector2 InteractableIntervalThatCanScoreBest;
|
||||
[Content, SerializeField] public UnityEvent InteractableIntervalThatCanScoreBestBeginEvent = new(), InteractableIntervalThatCanScoreBestEndEvent = new();
|
||||
public static float DefaultInteractableIntervalLengthThatCanScoreBest = IdentifiableJudgementTerminal * 3;
|
||||
[Content, SerializeField] public UnityEvent InteractableIntervalThatCanScoreBestBeforeEvent = new(),
|
||||
InteractableIntervalThatCanScoreBestBeginEvent = new(), InteractableIntervalThatCanScoreBestEndEvent = new();
|
||||
[Content, SerializeField] private DurationStats InteractableIntervalThatCanScoreBestStats = default;
|
||||
|
||||
[Header("Judgement")]
|
||||
@@ -70,9 +81,9 @@ namespace Demo.Game
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
if (BestJudgementTimePoint < 0)
|
||||
if (BestJudgementTimePoint <= 0)
|
||||
{
|
||||
BestJudgementTimePoint = Mathf.Lerp(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBest.y, 0.5f);
|
||||
DoSetupJudgement(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +116,17 @@ namespace Demo.Game
|
||||
InteractableIntervalThatCanScoreBestEndEvent.Invoke();
|
||||
}
|
||||
|
||||
private static DurationStats UpdateDurationStats(float begin, UnityEvent beginEvent, float end, UnityEvent endEvent,
|
||||
private static DurationStats UpdateDurationStats(float begin, UnityEvent beforeEvent, UnityEvent beginEvent, float end, UnityEvent endEvent,
|
||||
float current, DurationStats currentStats)
|
||||
{
|
||||
if (currentStats == DurationStats.After)
|
||||
return DurationStats.After;
|
||||
else if (current < begin)
|
||||
{
|
||||
if (currentStats != DurationStats.BeforeBegin)
|
||||
beforeEvent.Invoke();
|
||||
return DurationStats.BeforeBegin;
|
||||
}
|
||||
else if (current < end)
|
||||
{
|
||||
if (currentStats == DurationStats.BeforeBegin)
|
||||
@@ -136,41 +151,103 @@ namespace Demo.Game
|
||||
|
||||
public abstract JudgementLevel JudgementBehaviour(float timePoint);
|
||||
|
||||
private void DoUpdateJudgementStats(float currentTime)
|
||||
{
|
||||
// 可见区间
|
||||
VisibleDurationStats = UpdateDurationStats(VisibleDuration.x, VisibleDurationBeforeEvent,
|
||||
VisibleDurationBeginEvent, VisibleDuration.y, VisibleDurationEndEvent,
|
||||
currentTime, VisibleDurationStats);
|
||||
if (VisibleDurationStats != DurationStats.BeforeEnd)
|
||||
return;
|
||||
// 可判定区间
|
||||
InteractiveDurationStats = UpdateDurationStats(InteractiveDuration.x, InteractiveDurationBeforeEvent,
|
||||
InteractiveDurationBeginEvent, InteractiveDuration.y, InteractiveDurationEndEvent,
|
||||
currentTime, InteractiveDurationStats);
|
||||
if (InteractiveDurationStats != DurationStats.BeforeEnd)
|
||||
return;
|
||||
// 1级判定区间
|
||||
InteractableScoreIntervalStats = UpdateDurationStats(InteractableScoreInterval.x, InteractableScoreIntervalBeforeEvent,
|
||||
InteractableScoreIntervalBeginEvent, InteractableScoreInterval.y, InteractableScoreIntervalEndEvent,
|
||||
currentTime, InteractableScoreIntervalStats);
|
||||
if (InteractableScoreIntervalStats != DurationStats.BeforeEnd)
|
||||
return;
|
||||
// 0级判定区间
|
||||
InteractableIntervalThatCanScoreBestStats = UpdateDurationStats(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBestBeforeEvent,
|
||||
InteractableIntervalThatCanScoreBestBeginEvent, InteractableIntervalThatCanScoreBest.y, InteractableIntervalThatCanScoreBestEndEvent,
|
||||
currentTime, InteractableIntervalThatCanScoreBestStats);
|
||||
}
|
||||
|
||||
public override void ResetEnterGameStatus()
|
||||
{
|
||||
base.ResetEnterGameStatus();
|
||||
DoUpdateJudgementStats(Mathf.NegativeInfinity);
|
||||
}
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
if (tickType == TickType.Start || tickType == TickType.Reset)
|
||||
{
|
||||
VisibleDurationStats = DurationStats.BeforeBegin;
|
||||
InteractiveDurationStats = DurationStats.BeforeBegin;
|
||||
InteractableScoreIntervalStats = DurationStats.BeforeBegin;
|
||||
InteractableIntervalThatCanScoreBestStats = DurationStats.BeforeBegin;
|
||||
}
|
||||
//预判断
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
// 预判断
|
||||
if (VisibleDurationStats == DurationStats.Judgement)
|
||||
return;
|
||||
//检定
|
||||
// 检定
|
||||
InvokeJudgement(JudgementBehaviour(currentTime));
|
||||
if (tickType == TickType.Update)
|
||||
{
|
||||
// 可见区间
|
||||
VisibleDurationStats = UpdateDurationStats(VisibleDuration.x, VisibleDurationBeginEvent, VisibleDuration.y, VisibleDurationEndEvent,
|
||||
currentTime, VisibleDurationStats);
|
||||
if (VisibleDurationStats != DurationStats.BeforeEnd)
|
||||
return;
|
||||
// 可判定区间
|
||||
InteractiveDurationStats = UpdateDurationStats(InteractiveDuration.x, InteractiveDurationBeginEvent, InteractiveDuration.y, InteractiveDurationEndEvent,
|
||||
currentTime, InteractiveDurationStats);
|
||||
if (InteractiveDurationStats != DurationStats.BeforeEnd)
|
||||
return;
|
||||
// 1级判定区间
|
||||
InteractableScoreIntervalStats = UpdateDurationStats(InteractableScoreInterval.x, InteractableScoreIntervalBeginEvent, InteractableScoreInterval.y, InteractableScoreIntervalEndEvent,
|
||||
currentTime, InteractableScoreIntervalStats);
|
||||
if (InteractableScoreIntervalStats != DurationStats.BeforeEnd)
|
||||
return;
|
||||
// 0级判定区间
|
||||
InteractableIntervalThatCanScoreBestStats = UpdateDurationStats(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBestBeginEvent, InteractableIntervalThatCanScoreBest.y, InteractableIntervalThatCanScoreBestEndEvent,
|
||||
currentTime, InteractableIntervalThatCanScoreBestStats);
|
||||
}
|
||||
// 更新状态
|
||||
DoUpdateJudgementStats(currentTime);
|
||||
}
|
||||
|
||||
public void DoSetupJudgementLevels(
|
||||
float bestJudgementTimePoint,
|
||||
float interactableIntervalThatCanScoreBest,
|
||||
float interactableScoreInterval,
|
||||
float interactiveDuration,
|
||||
float visibleDuration)
|
||||
{
|
||||
this.BestJudgementTimePoint = bestJudgementTimePoint;
|
||||
var bestJudgementTimePointValue = bestJudgementTimePoint;
|
||||
// InteractableIntervalThatCanScoreBest
|
||||
var interactableIntervalThatCanScoreBestValue = interactableIntervalThatCanScoreBest * 0.5f;
|
||||
InteractableIntervalThatCanScoreBest = new(bestJudgementTimePointValue - interactableIntervalThatCanScoreBestValue,
|
||||
bestJudgementTimePointValue + interactableIntervalThatCanScoreBestValue);
|
||||
|
||||
// InteractableScoreInterval
|
||||
var interactableScoreIntervalValue = interactableScoreInterval * 0.5f;
|
||||
InteractableScoreInterval = new(bestJudgementTimePointValue - interactableScoreIntervalValue,
|
||||
bestJudgementTimePointValue + interactableScoreIntervalValue);
|
||||
|
||||
// InteractiveDuration
|
||||
var interactiveDurationValue = interactiveDuration * 0.5f;
|
||||
InteractiveDuration = new(bestJudgementTimePointValue - interactiveDurationValue,
|
||||
bestJudgementTimePointValue + interactiveDurationValue);
|
||||
|
||||
// InteractableScoreInterval
|
||||
var visibleDurationValue = visibleDuration * 0.5f;
|
||||
VisibleDuration = new(bestJudgementTimePointValue - visibleDurationValue,
|
||||
bestJudgementTimePointValue + visibleDurationValue);
|
||||
}
|
||||
|
||||
public void DoSetupJudgement(float bestJudgementTimePoint)
|
||||
{
|
||||
DoSetupJudgementLevels(
|
||||
bestJudgementTimePoint,
|
||||
DefaultInteractableIntervalLengthThatCanScoreBest,
|
||||
DefaultInteractableScoreIntervalLength,
|
||||
DefaultInteractiveLength,
|
||||
DefaultVisibleLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用配置中的区间长度设置以最佳判定点为中心的各级区间
|
||||
/// </summary>
|
||||
/// <param name="bestJudgementTimePoint">最佳判定点</param>
|
||||
[ScriptableCall(@"
|
||||
<summary>
|
||||
使用配置中的区间长度设置以最佳判定点为中心的各级区间
|
||||
</summary>
|
||||
<param name=""bestJudgementTimePoint"">最佳判定点</param>
|
||||
")]
|
||||
public void SetupJudgement(string bestJudgementTimePoint)
|
||||
{
|
||||
DoSetupJudgement(Parse(bestJudgementTimePoint));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,26 +283,12 @@ namespace Demo.Game
|
||||
string interactiveDuration,
|
||||
string visibleDuration)
|
||||
{
|
||||
var bestJudgementTimePointValue = Parse(bestJudgementTimePoint);
|
||||
// InteractableIntervalThatCanScoreBest
|
||||
var interactableIntervalThatCanScoreBestValue = Parse(interactableIntervalThatCanScoreBest) * 0.5f;
|
||||
InteractableIntervalThatCanScoreBest = new(bestJudgementTimePointValue - interactableIntervalThatCanScoreBestValue,
|
||||
bestJudgementTimePointValue + interactableIntervalThatCanScoreBestValue);
|
||||
|
||||
// InteractableScoreInterval
|
||||
var interactableScoreIntervalValue = Parse(interactableScoreInterval) * 0.5f;
|
||||
InteractableScoreInterval = new(bestJudgementTimePointValue - interactableScoreIntervalValue,
|
||||
bestJudgementTimePointValue + interactableScoreIntervalValue);
|
||||
|
||||
// InteractiveDuration
|
||||
var interactiveDurationValue = Parse(interactiveDuration) * 0.5f;
|
||||
InteractiveDuration = new(bestJudgementTimePointValue - interactiveDurationValue,
|
||||
bestJudgementTimePointValue + interactiveDurationValue);
|
||||
|
||||
// InteractableScoreInterval
|
||||
var visibleDurationValue = Parse(visibleDuration) * 0.5f;
|
||||
VisibleDuration = new(bestJudgementTimePointValue - visibleDurationValue,
|
||||
bestJudgementTimePointValue + visibleDurationValue);
|
||||
DoSetupJudgementLevels(
|
||||
Parse(bestJudgementTimePoint),
|
||||
Parse(interactableIntervalThatCanScoreBest),
|
||||
Parse(interactableScoreInterval),
|
||||
Parse(interactiveDuration),
|
||||
Parse(visibleDuration));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -328,6 +391,10 @@ namespace Demo.Game
|
||||
public void SetInteractableIntervalThatCanScoreBestBegin(string value)
|
||||
{
|
||||
InteractableIntervalThatCanScoreBest.x = Parse(value);
|
||||
if (BestJudgementTimePoint < 0)
|
||||
{
|
||||
BestJudgementTimePoint = Mathf.Lerp(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBest.y, 0.5f);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置0级判定区间(最佳判定)结束时间
|
||||
@@ -342,6 +409,10 @@ namespace Demo.Game
|
||||
public void SetInteractableIntervalThatCanScoreBestEnd(string value)
|
||||
{
|
||||
InteractableIntervalThatCanScoreBest.y = Parse(value);
|
||||
if (BestJudgementTimePoint < 0)
|
||||
{
|
||||
BestJudgementTimePoint = Mathf.Lerp(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBest.y, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user