Commit 0d5bb492 authored by hex's avatar hex

remove safeGO

parent 83c2db9b
Pipeline #39483 failed
......@@ -1242,6 +1242,63 @@ public class Program : MonoBehaviour
}
if (GameTextureManager.IsInitialized)
{
ProcessTextureManagerUpdates();
}
fixALLcamerasPreFrame();
HandleUnifiedInput();
UpdateRaycast();
for (int i = 0; i < servants.Count; i++)
{
servants[i].Update();
}
TcpHelper.preFrameFunction();
ProcessDelayedTasks();
}
private void UpdateRaycast()
{
pointedGameObject = null;
pointedCollider = null;
Vector3 inputPosition = Input.mousePosition;
Ray line = Camera.main.ScreenPointToRay(inputPosition);
RaycastHit hit;
if (Physics.Raycast(line, out hit, 1000f, rayFilter))
{
pointedGameObject = hit.collider.gameObject;
pointedCollider = hit.collider;
}
GameObject hoverobject = UICamera.Raycast(inputPosition) ?
UICamera.lastHit.collider.gameObject : null;
if (hoverobject != null)
{
if (hoverobject.layer == 11 || pointedGameObject == null)
{
pointedGameObject = hoverobject;
pointedCollider = UICamera.lastHit.collider;
}
}
}
private void HandleUnifiedInput()
{
wheelValue = UICamera.GetAxis("Mouse ScrollWheel") * 50;
InputGetMouseButtonDown_0 = Input.GetMouseButtonDown(0);
InputGetMouseButtonUp_0 = Input.GetMouseButtonUp(0);
InputGetMouseButtonDown_1 = Input.GetMouseButtonDown(1);
InputGetMouseButtonUp_1 = Input.GetMouseButtonUp(1);
InputEnterDown = Input.GetKeyDown(KeyCode.Return);
InputGetMouseButton_0 = Input.GetMouseButton(0);
}
private void ProcessTextureManagerUpdates()
{
// 1. 实现下载限流
// 只要当前活跃的下载数小于最大限制,并且队列里有待下载的任务,就启动新的下载。
......@@ -1278,56 +1335,29 @@ public class Program : MonoBehaviour
}
}
fixALLcamerasPreFrame();
wheelValue = UICamera.GetAxis("Mouse ScrollWheel") * 50;
pointedGameObject = null;
pointedCollider = null;
Ray line = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(line, out hit, (float)1000, rayFilter))
{
pointedGameObject = hit.collider.gameObject;
pointedCollider = hit.collider;
}
GameObject hoverobject = UICamera.Raycast(Input.mousePosition)
? UICamera.lastHit.collider.gameObject
: null;
if (hoverobject != null)
{
if (hoverobject.layer == 11 || pointedGameObject == null)
private void ProcessDelayedTasks()
{
pointedGameObject = hoverobject;
pointedCollider = UICamera.lastHit.collider;
}
}
InputGetMouseButtonDown_0 = Input.GetMouseButtonDown(0);
InputGetMouseButtonUp_0 = Input.GetMouseButtonUp(0);
InputGetMouseButtonDown_1 = Input.GetMouseButtonDown(1);
InputGetMouseButtonUp_1 = Input.GetMouseButtonUp(1);
InputEnterDown = Input.GetKeyDown(KeyCode.Return);
InputGetMouseButton_0 = Input.GetMouseButton(0);
for (int i = 0; i < servants.Count; i++)
{
servants[i].Update();
}
TcpHelper.preFrameFunction();
delayedTask remove = null;
while (true)
int maxTasksPerFrame = 5; // 限制每帧处理的延迟任务数量
int processedTasks = 0;
while (processedTasks < maxTasksPerFrame)
{
remove = null;
for (int i = 0; i < delayedTasks.Count; i++)
{
if (Program.TimePassed() > delayedTasks[i].timeToBeDone)
if (TimePassed() > delayedTasks[i].timeToBeDone)
{
remove = delayedTasks[i];
try
{
remove.act();
}
catch (System.Exception e)
catch (Exception e)
{
UnityEngine.Debug.Log(e);
Debug.Log(e);
}
processedTasks++;
break;
}
}
......
using System;
using System.Collections.Generic;
using System.IO;
using DG.Tweening;
using UnityEngine;
using YGOSharp.OCGWrapper.Enums;
using DG.Tweening;
public class Servant
......@@ -57,11 +57,6 @@ public class Servant
}
allGameObjects.Clear();
updateActions_s.Clear();
for (int i = 0; i < delayedTasks.Count; i++)
{
Program.notGo(delayedTasks[i].act);
}
delayedTasks.Clear();
}
public virtual void fixScreenProblem()
......@@ -312,16 +307,6 @@ public class Servant
}
}
List<Program.delayedTask> delayedTasks = new List<Program.delayedTask>();
public void safeGogo(int delay_, Action act_)
{
Program.go(delay_, act_);
delayedTasks.Add(
new Program.delayedTask { act = act_, timeToBeDone = delay_ + Program.TimePassed() }
);
}
#region remasterMessageSystem
public Vector3 centre(bool fix = false)
......
......@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DG.Tweening;
using UnityEngine;
using YGOSharp.OCGWrapper.Enums;
using DG.Tweening;
public class DeckManager : ServantWithCardDescription
......@@ -23,6 +23,10 @@ public class DeckManager : ServantWithCardDescription
private bool isContinuouslyAdding = false; // 是否已进入持续添加模式
private float nextAddCardTime = 0f; // 下一次可以添加卡片的时间点
private Sequence deckLoadSequence;
private enum CardZone { Main, Extra, Side }
public enum Condition
{
editDeck = 1,
......@@ -1406,6 +1410,11 @@ public class DeckManager : ServantWithCardDescription
public override void hide()
{
if (deckLoadSequence != null && deckLoadSequence.IsActive())
{
deckLoadSequence.Kill();
}
if (isShowed)
{
hideDetail();
......@@ -2082,86 +2091,124 @@ public class DeckManager : ServantWithCardDescription
bool canSave = false;
public void FormCodedDeckToObjectDeck()
/// <summary>
/// 将指定卡组的创建和入场动画添加到DOTween序列中。
/// </summary>
/// <param name="seq">要添加动画的目标序列。</param>
/// <param name="startTime">这组动画在序列时间线上的起始时间。</param>
/// <param name="cardIds">要创建的卡片的ID列表。</param>
/// <param name="objectList">用于存储创建出的MonoCardInDeckManager对象的列表。</param>
/// <param name="zone">卡片所属的区域(主卡组、额外、副卡组)。</param>
/// <returns>这组动画完成后的序列时间点。</returns>
private float AppendCardAnimations(Sequence seq, float startTime, IList<int> cardIds, IList<MonoCardInDeckManager> objectList, CardZone zone)
{
canSave = false;
safeGogo(
4000,
() =>
if (cardIds == null || cardIds.Count == 0)
{
canSave = true;
return startTime; // 如果没有卡片,直接返回起始时间
}
);
int indexOfLogic = 0;
int[] hangshu = UIHelper.get_decklieshuArray(deck.Main.Count);
foreach (var item in deck.Main)
// 根据区域决定动画的交错延迟
float staggerDelay = (zone == CardZone.Main) ? 0.015f : 0.045f;
int[] hangshu = (zone == CardZone.Main) ? UIHelper.get_decklieshuArray(cardIds.Count) : null;
for (int i = 0; i < cardIds.Count; i++)
{
Vector2 v = UIHelper.get_hang_lieArry(indexOfLogic, hangshu);
Vector3 toVector = new Vector3(
// C# 闭包陷阱:必须在循环内部为lambda表达式捕获变量的当前值
int currentIndex = i;
int cardId = cardIds[i];
// 计算卡片的目标位置
Vector3 toVector;
switch (zone)
{
case CardZone.Main:
Vector2 v = UIHelper.get_hang_lieArry(currentIndex, hangshu);
toVector = new Vector3(
UIHelper.get_left_right_index(-12.5f, 12.5f, (int)v.y, hangshu[(int)v.x]),
0.5f + v.y / 3f + v.x / 3f,
11.8f - v.x * 4f
);
YGOSharp.Card data = YGOSharp.CardsManager.Get(item);
safeGogo(
indexOfLogic * 15,
() =>
{
MonoCardInDeckManager card = createCard();
card.cardData = data;
card.gameObject.layer = 16;
deck.IMain.Add(card);
card.tweenToVectorAndFall(toVector, new Vector3(90, 0, 0));
}
);
indexOfLogic++;
}
indexOfLogic = 0;
foreach (var item in deck.Extra)
{
Vector3 toVector = new Vector3(
UIHelper.get_left_right_indexZuo(-12.5f, 12.5f, indexOfLogic, deck.Extra.Count, 10),
0.5f + (float)indexOfLogic / 3f,
break;
case CardZone.Extra:
toVector = new Vector3(
UIHelper.get_left_right_indexZuo(-12.5f, 12.5f, currentIndex, cardIds.Count, 10),
0.5f + (float)currentIndex / 3f,
-6.2f
);
YGOSharp.Card data = YGOSharp.CardsManager.Get(item);
safeGogo(
indexOfLogic * 45,
() =>
break;
case CardZone.Side:
toVector = new Vector3(
UIHelper.get_left_right_indexZuo(-12.5f, 12.5f, currentIndex, cardIds.Count, 10),
0.5f + (float)currentIndex / 3f,
-12f
);
break;
default:
toVector = Vector3.zero;
break;
}
// 使用 InsertCallback 在序列的指定时间点执行卡片创建和动画开始的逻辑
// 这是整个重构的核心,它将原来的 safeGogo(delay, action) 替换为更精确的时间线插入
seq.InsertCallback(startTime + currentIndex * staggerDelay, () =>
{
YGOSharp.Card data = YGOSharp.CardsManager.Get(cardId);
if (data == null) return;
MonoCardInDeckManager card = createCard();
card.cardData = data;
card.gameObject.layer = 16;
deck.IExtra.Add(card);
objectList.Add(card);
// tweenToVectorAndFall 本身就是DoTween动画, 它会独立运行,
// 而我们的Sequence只负责在正确的时间点触发它。
card.tweenToVectorAndFall(toVector, new Vector3(90, 0, 0));
});
}
);
indexOfLogic++;
// 返回这组动画播放完毕后的总时间
return startTime + cardIds.Count * staggerDelay;
}
indexOfLogic = 0;
foreach (var item in deck.Side)
public void FormCodedDeckToObjectDeck()
{
Vector3 toVector = new Vector3(
UIHelper.get_left_right_indexZuo(-12.5f, 12.5f, indexOfLogic, deck.Side.Count, 10),
0.5f + (float)indexOfLogic / 3f,
-12f
);
YGOSharp.Card data = YGOSharp.CardsManager.Get(item);
safeGogo(
indexOfLogic * 45,
() =>
canSave = false;
// 如果上一个动画序列还在播放,则安全地销毁它,防止重叠或冲突
if (deckLoadSequence != null && deckLoadSequence.IsActive())
{
MonoCardInDeckManager card = createCard();
card.cardData = data;
card.gameObject.layer = 16;
deck.ISide.Add(card);
card.tweenToVectorAndFall(toVector, new Vector3(90, 0, 0));
}
);
indexOfLogic++;
deckLoadSequence.Kill();
}
// 创建一个新的序列
deckLoadSequence = DOTween.Sequence();
// 用于追踪序列当前的时间点
float animationTimeline = 0f;
// 1. 将主卡组的动画添加到序列中,从时间 0 开始
AppendCardAnimations(deckLoadSequence, 0f, deck.Main, deck.IMain, CardZone.Main);
// 2. 将额外卡组的动画也添加到序列中,同样从时间 0 开始
AppendCardAnimations(deckLoadSequence, 0f, deck.Extra, deck.IExtra, CardZone.Extra);
// 3. 将副卡组的动画也添加到序列中,还是从时间 0 开始
AppendCardAnimations(deckLoadSequence, 0f, deck.Side, deck.ISide, CardZone.Side);
// 4. 设置整个序列播放完成后的回调
// 这比硬编码的4秒延迟要精确和可靠得多
deckLoadSequence.OnComplete(() =>
{
canSave = true;
// 可以在这里加一句Debug日志,方便调试
// Debug.Log("Deck loading animation completed. Saving is now enabled.");
});
// 5. 播放整个动画序列
deckLoadSequence.Play();
}
void ShowObjectDeck()
{
float k = (float)(1.5 * 0.1 / 0.130733633);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment