调整 Directive 逻辑并添加章节之间的承接功能
This commit is contained in:
@@ -10,23 +10,23 @@ namespace UI
|
||||
public class AIChatForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private TMP_Text _returnButtonText;
|
||||
|
||||
|
||||
[SerializeField] private TMP_InputField _inputField;
|
||||
|
||||
|
||||
[SerializeField] private RectTransform _dialogContent;
|
||||
|
||||
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
|
||||
[SerializeField] private ScrollRect _historyScrollRect;
|
||||
|
||||
|
||||
[SerializeField] private AIDialogItem _aiDialogItemPrefab;
|
||||
|
||||
|
||||
[SerializeField] private PlayerDialogItem _playerDialogItemPrefab;
|
||||
|
||||
|
||||
[SerializeField] private HorizonSelectGroup _languageSelectGroup;
|
||||
|
||||
|
||||
[SerializeField] private string _returnButtonNormalText = "<sprite name=\"KEYBOARD_Esc\"> Back";
|
||||
|
||||
|
||||
[SerializeField] private string _returnButtonHoverText = "<sprite name=\"KEYBOARD_Esc\"><u> Back </u>";
|
||||
|
||||
private readonly List<Component> _dialogItems = new List<Component>();
|
||||
|
||||
@@ -13,14 +13,25 @@ namespace UI
|
||||
[SerializeField] private Image _dimImage;
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
[SerializeField] private TMP_Text _subtitleText;
|
||||
[SerializeField] private float _dimFadeInDuration = 0.2f;
|
||||
[SerializeField] private float _preBlackDuration = 0.25f;
|
||||
[SerializeField] private float _titleFadeInDelay = 0f;
|
||||
[SerializeField] private float _fadeInDuration = 0.3f;
|
||||
[SerializeField] private float _holdDuration = 1.2f;
|
||||
[SerializeField] private float _fadeOutDuration = 0.3f;
|
||||
[SerializeField] private float _dimFadeOutDuration = 0.2f;
|
||||
|
||||
private Coroutine _playCoroutine;
|
||||
private int _requestId;
|
||||
private int _chapterId;
|
||||
private bool _hasPublishedCompletion;
|
||||
private float _runtimeDimFadeInDuration;
|
||||
private float _runtimePreBlackDuration;
|
||||
private float _runtimeTitleFadeInDelay;
|
||||
private float _runtimeTitleFadeInDuration;
|
||||
private float _runtimeHoldDuration;
|
||||
private float _runtimeTitleFadeOutDuration;
|
||||
private float _runtimeDimFadeOutDuration;
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
@@ -33,7 +44,8 @@ namespace UI
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
StopPlay();
|
||||
SetContentAlpha(0f);
|
||||
SetDimAlpha(0f);
|
||||
SetTitleAlpha(0f);
|
||||
if (!isShutdown)
|
||||
{
|
||||
PublishCompletionIfNeeded();
|
||||
@@ -55,6 +67,11 @@ namespace UI
|
||||
_contentGroup = CreateContentGroup(rootRect);
|
||||
}
|
||||
|
||||
if (_contentGroup != null)
|
||||
{
|
||||
_contentGroup.alpha = 1f;
|
||||
}
|
||||
|
||||
RectTransform contentRect = _contentGroup != null && _contentGroup.transform is RectTransform contentTransform
|
||||
? contentTransform
|
||||
: rootRect;
|
||||
@@ -105,6 +122,7 @@ namespace UI
|
||||
private void ApplyContext(ChapterTitleFormContext context)
|
||||
{
|
||||
_hasPublishedCompletion = false;
|
||||
ResetRuntimeTimings(context);
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
@@ -157,10 +175,17 @@ namespace UI
|
||||
|
||||
private IEnumerator PlayRoutine()
|
||||
{
|
||||
SetContentAlpha(0f);
|
||||
yield return FadeAlpha(0f, 1f, _fadeInDuration);
|
||||
yield return WaitUnscaled(_holdDuration);
|
||||
yield return FadeAlpha(1f, 0f, _fadeOutDuration);
|
||||
SetDimAlpha(0f);
|
||||
SetTitleAlpha(0f);
|
||||
|
||||
yield return FadeDimAlpha(0f, 1f, _runtimeDimFadeInDuration);
|
||||
yield return WaitUnscaled(_runtimePreBlackDuration);
|
||||
yield return WaitUnscaled(_runtimeTitleFadeInDelay);
|
||||
yield return FadeTitleAlpha(0f, 1f, _runtimeTitleFadeInDuration);
|
||||
yield return WaitUnscaled(_runtimeHoldDuration);
|
||||
yield return FadeTitleAlpha(1f, 0f, _runtimeTitleFadeOutDuration);
|
||||
yield return FadeDimAlpha(1f, 0f, _runtimeDimFadeOutDuration);
|
||||
|
||||
_playCoroutine = null;
|
||||
|
||||
PublishCompletionIfNeeded();
|
||||
@@ -170,12 +195,12 @@ namespace UI
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FadeAlpha(float from, float to, float duration)
|
||||
private IEnumerator FadeDimAlpha(float from, float to, float duration)
|
||||
{
|
||||
float safeDuration = Mathf.Max(0f, duration);
|
||||
if (safeDuration <= 0f)
|
||||
{
|
||||
SetContentAlpha(to);
|
||||
SetDimAlpha(to);
|
||||
yield break;
|
||||
}
|
||||
|
||||
@@ -184,11 +209,32 @@ namespace UI
|
||||
{
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
float t = Mathf.Clamp01(elapsed / safeDuration);
|
||||
SetContentAlpha(Mathf.Lerp(from, to, t));
|
||||
SetDimAlpha(Mathf.Lerp(from, to, t));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
SetContentAlpha(to);
|
||||
SetDimAlpha(to);
|
||||
}
|
||||
|
||||
private IEnumerator FadeTitleAlpha(float from, float to, float duration)
|
||||
{
|
||||
float safeDuration = Mathf.Max(0f, duration);
|
||||
if (safeDuration <= 0f)
|
||||
{
|
||||
SetTitleAlpha(to);
|
||||
yield break;
|
||||
}
|
||||
|
||||
float elapsed = 0f;
|
||||
while (elapsed < safeDuration)
|
||||
{
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
float t = Mathf.Clamp01(elapsed / safeDuration);
|
||||
SetTitleAlpha(Mathf.Lerp(from, to, t));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
SetTitleAlpha(to);
|
||||
}
|
||||
|
||||
private static IEnumerator WaitUnscaled(float duration)
|
||||
@@ -207,14 +253,57 @@ namespace UI
|
||||
}
|
||||
}
|
||||
|
||||
private void SetContentAlpha(float alpha)
|
||||
private void SetDimAlpha(float alpha)
|
||||
{
|
||||
if (_contentGroup == null)
|
||||
if (_dimImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_contentGroup.alpha = Mathf.Clamp01(alpha);
|
||||
Color color = _dimImage.color;
|
||||
color.a = Mathf.Clamp01(alpha);
|
||||
_dimImage.color = color;
|
||||
}
|
||||
|
||||
private void SetTitleAlpha(float alpha)
|
||||
{
|
||||
float clampedAlpha = Mathf.Clamp01(alpha);
|
||||
SetTextAlpha(_titleText, clampedAlpha);
|
||||
SetTextAlpha(_subtitleText, clampedAlpha);
|
||||
}
|
||||
|
||||
private static void SetTextAlpha(TMP_Text text, float alpha)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Color color = text.color;
|
||||
color.a = alpha;
|
||||
text.color = color;
|
||||
}
|
||||
|
||||
private void ResetRuntimeTimings(ChapterTitleFormContext context)
|
||||
{
|
||||
_runtimeDimFadeInDuration = ResolveDuration(context != null ? context.DimFadeInDuration : -1f,
|
||||
_dimFadeInDuration);
|
||||
_runtimePreBlackDuration = ResolveDuration(context != null ? context.PreBlackDuration : -1f,
|
||||
_preBlackDuration);
|
||||
_runtimeTitleFadeInDelay = ResolveDuration(context != null ? context.TitleFadeInDelay : -1f,
|
||||
_titleFadeInDelay);
|
||||
_runtimeTitleFadeInDuration = ResolveDuration(context != null ? context.TitleFadeInDuration : -1f,
|
||||
_fadeInDuration);
|
||||
_runtimeHoldDuration = ResolveDuration(context != null ? context.HoldDuration : -1f, _holdDuration);
|
||||
_runtimeTitleFadeOutDuration = ResolveDuration(context != null ? context.TitleFadeOutDuration : -1f,
|
||||
_fadeOutDuration);
|
||||
_runtimeDimFadeOutDuration = ResolveDuration(context != null ? context.DimFadeOutDuration : -1f,
|
||||
_dimFadeOutDuration);
|
||||
}
|
||||
|
||||
private static float ResolveDuration(float overrideDuration, float fallbackDuration)
|
||||
{
|
||||
return overrideDuration >= 0f ? overrideDuration : Mathf.Max(0f, fallbackDuration);
|
||||
}
|
||||
|
||||
private void PublishCompletionIfNeeded()
|
||||
|
||||
Reference in New Issue
Block a user