notebook实装功能,galgame继续,一些bug修复

This commit is contained in:
2026-03-06 02:08:43 +08:00
parent 9011fa022e
commit 1f4077cf21
468 changed files with 50175 additions and 11402 deletions
@@ -1,5 +1,8 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
public class loadSettlementTeamPrefab : MonoBehaviour
{
@@ -11,6 +14,18 @@ public class loadSettlementTeamPrefab : MonoBehaviour
public GameObject settleTeamCardsPrefab;
public GameObject objectToPutdown;
[Header("Settlement Entry Animation")]
[SerializeField] private bool enableAllySlotEntryTween = true;
[SerializeField] private float allySlotEntryOffsetX = 240f;
[SerializeField] private float allySlotEntryDuration = 0.35f;
[SerializeField] private float allySlotEntryStagger = 0.06f;
[SerializeField] private Ease allySlotEntryEase = Ease.OutCubic;
[SerializeField] private bool allySlotEntryUseUnscaledTime = true;
private readonly List<RectTransform> spawnedCardRoots = new List<RectTransform>();
private readonly List<Vector2> spawnedCardBasePositions = new List<Vector2>();
private Sequence allySlotEntrySequence;
/// <summary>
/// Instantiate five settlement cards under objectToPutdown and populate their fields.
/// Uses tuic.GetCurrentAllySOs() for profile/name when available, falls back to AllyHero_SO via allySlotIds.
@@ -18,6 +33,10 @@ public class loadSettlementTeamPrefab : MonoBehaviour
/// </summary>
public void PopulateSettlementCards()
{
KillAllySlotEntrySequence();
spawnedCardRoots.Clear();
spawnedCardBasePositions.Clear();
if (settleTeamCardsPrefab == null)
{
Debug.LogWarning("loadSettlementTeamPrefab: prefab not assigned");
@@ -86,6 +105,7 @@ public class loadSettlementTeamPrefab : MonoBehaviour
{
rectTransform.anchoredPosition = Vector2.zero;
rectTransform.sizeDelta = Vector2.zero;
spawnedCardRoots.Add(rectTransform);
}
// Diagnostic: verify parenting applied
@@ -244,6 +264,81 @@ public class loadSettlementTeamPrefab : MonoBehaviour
if (GameConfig.verboseLogs) Debug.Log($"[loadSettlementTeamPrefab] Created card for slot {i+1}");
}
CaptureSpawnedCardBasePositions();
if (enableAllySlotEntryTween)
SetSpawnedCardsAlpha(0f);
}
public IEnumerator PlayAllySlotEntryBeforeMask()
{
if (!enableAllySlotEntryTween)
yield break;
CaptureSpawnedCardBasePositions();
if (spawnedCardRoots.Count == 0)
yield break;
KillAllySlotEntrySequence();
float duration = Mathf.Max(0.01f, allySlotEntryDuration);
float stagger = Mathf.Max(0f, allySlotEntryStagger);
float offsetX = allySlotEntryOffsetX;
allySlotEntrySequence = DOTween.Sequence().SetUpdate(allySlotEntryUseUnscaledTime);
for (int i = 0; i < spawnedCardRoots.Count; i++)
{
RectTransform rt = spawnedCardRoots[i];
if (rt == null) continue;
Vector2 basePos = spawnedCardBasePositions[i];
CanvasGroup group = GetOrAddCanvasGroup(rt.transform);
if (group != null) group.alpha = 0f;
rt.anchoredPosition = new Vector2(basePos.x + offsetX, basePos.y);
float startAt = i * stagger; // top -> bottom (sibling order)
allySlotEntrySequence.Insert(startAt, rt.DOAnchorPos(basePos, duration).SetEase(allySlotEntryEase).SetUpdate(allySlotEntryUseUnscaledTime));
if (group != null)
allySlotEntrySequence.Insert(startAt, group.DOFade(1f, duration).SetEase(allySlotEntryEase).SetUpdate(allySlotEntryUseUnscaledTime));
}
if (allySlotEntrySequence != null && allySlotEntrySequence.active)
yield return allySlotEntrySequence.WaitForCompletion();
allySlotEntrySequence = null;
}
public bool HasSpawnedCards()
{
if (!enableAllySlotEntryTween)
return false;
if (spawnedCardRoots.Count > 0)
return true;
return objectToPutdown != null && objectToPutdown.transform.childCount > 0;
}
public void ShowSpawnedCardsInstantly()
{
CaptureSpawnedCardBasePositions();
SetSpawnedCardsAlpha(1f);
}
public void CompleteAllySlotEntryImmediately()
{
CaptureSpawnedCardBasePositions();
KillAllySlotEntrySequence();
for (int i = 0; i < spawnedCardRoots.Count; i++)
{
RectTransform rt = spawnedCardRoots[i];
if (rt == null) continue;
if (i < spawnedCardBasePositions.Count)
rt.anchoredPosition = spawnedCardBasePositions[i];
SetCanvasAlpha(rt.transform, 1f);
}
}
/// <summary>
@@ -264,4 +359,90 @@ public class loadSettlementTeamPrefab : MonoBehaviour
}
return $"{designation} {name}";
}
private void OnDisable()
{
KillAllySlotEntrySequence();
}
private void CaptureSpawnedCardBasePositions()
{
if (objectToPutdown == null)
return;
Canvas.ForceUpdateCanvases();
RectTransform parentRt = objectToPutdown.transform as RectTransform;
if (parentRt != null)
LayoutRebuilder.ForceRebuildLayoutImmediate(parentRt);
List<RectTransform> validCards = new List<RectTransform>();
// Prefer freshly instantiated references from this run.
for (int i = 0; i < spawnedCardRoots.Count; i++)
{
RectTransform rt = spawnedCardRoots[i];
if (rt == null) continue;
if (rt.parent != objectToPutdown.transform) continue;
validCards.Add(rt);
}
// Fallback scan if cache is empty.
if (validCards.Count == 0)
{
Transform parent = objectToPutdown.transform;
for (int i = 0; i < parent.childCount; i++)
{
RectTransform rt = parent.GetChild(i) as RectTransform;
if (rt == null) continue;
validCards.Add(rt);
}
}
validCards.Sort((a, b) => a.GetSiblingIndex().CompareTo(b.GetSiblingIndex()));
spawnedCardRoots.Clear();
spawnedCardBasePositions.Clear();
for (int i = 0; i < validCards.Count; i++)
{
RectTransform rt = validCards[i];
spawnedCardRoots.Add(rt);
spawnedCardBasePositions.Add(rt.anchoredPosition);
SetCanvasAlpha(rt.transform, 1f);
}
}
private void SetSpawnedCardsAlpha(float alpha)
{
float clamped = Mathf.Clamp01(alpha);
for (int i = 0; i < spawnedCardRoots.Count; i++)
{
RectTransform rt = spawnedCardRoots[i];
if (rt == null) continue;
SetCanvasAlpha(rt.transform, clamped);
}
}
private void KillAllySlotEntrySequence()
{
if (allySlotEntrySequence == null)
return;
if (allySlotEntrySequence.active)
allySlotEntrySequence.Kill(false);
allySlotEntrySequence = null;
}
private static CanvasGroup GetOrAddCanvasGroup(Transform root)
{
if (root == null) return null;
CanvasGroup cg = root.GetComponent<CanvasGroup>();
if (cg == null) cg = root.gameObject.AddComponent<CanvasGroup>();
return cg;
}
private static void SetCanvasAlpha(Transform root, float alpha)
{
CanvasGroup cg = GetOrAddCanvasGroup(root);
if (cg == null) return;
cg.alpha = Mathf.Clamp01(alpha);
}
}