This commit is contained in:
2026-07-25 16:13:21 +08:00
parent 3d834c3c68
commit 7f0b9e4e1a
4 changed files with 34 additions and 36 deletions
+18 -27
View File
@@ -1,18 +1,17 @@
using System;
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using Newtonsoft.Json.Linq;
/// <summary>
/// 北京时间管理器 - 获取一次后持续自增
/// 北京时间管理器 - 同步时记录服务器时间与本地系统时间的差值,获取时返回本地时间+差值
/// </summary>
public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
{
[Header("时间状态")]
[SerializeField] private bool _isTimeSynced = false;
[SerializeField] private DateTime _currentBeijingTime;
[SerializeField] private float _timeSinceLastSync;
[SerializeField] private TimeSpan _serverTimeOffset; // 服务器时间 - 本地系统时间
/// <summary>
/// 获取当前北京时间
@@ -23,7 +22,7 @@ public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
{
if (_isTimeSynced)
{
return _currentBeijingTime.AddSeconds(_timeSinceLastSync);
return DateTime.Now + _serverTimeOffset;
}
return DateTime.Now; // 未同步时返回本地时间
}
@@ -63,14 +62,6 @@ public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
SyncBeijingTime();
}
private void Update()
{
if (_isTimeSynced)
{
_timeSinceLastSync += Time.deltaTime;
}
}
/// <summary>
/// 同步北京时间
/// </summary>
@@ -112,16 +103,16 @@ public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
if (url.Contains("timeapi.io"))
{
string timeStr = json["dateTime"]?.ToString();
Debug.Log(timeStr);
if (!string.IsNullOrEmpty(timeStr))
{
_currentBeijingTime = DateTime.Parse(timeStr);
_timeSinceLastSync = 0;
DateTime serverTime = DateTime.Parse(timeStr);
_serverTimeOffset = serverTime - DateTime.Now;
_isTimeSynced = true;
Debug.Log($"北京时间同步成功:{_currentBeijingTime:yyyy-MM-dd HH:mm:ss}");
OnTimeSynced?.Invoke(_currentBeijingTime);
Debug.Log($"北京时间同步成功:{CurrentBeijingTime:yyyy-MM-dd HH:mm:ss},偏移量:{_serverTimeOffset.TotalSeconds:F1}s");
OnTimeSynced?.Invoke(CurrentBeijingTime);
yield break;
}
}
@@ -133,13 +124,13 @@ public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
if (!string.IsNullOrEmpty(timeStr))
{
_currentBeijingTime = DateTimeOffset.Parse(timeStr)
DateTime serverTime = DateTimeOffset.Parse(timeStr)
.ToOffset(TimeSpan.FromHours(8))
.DateTime;
_timeSinceLastSync = 0;
_serverTimeOffset = serverTime - DateTime.Now;
_isTimeSynced = true;
Debug.Log($"北京时间同步成功:{_currentBeijingTime:yyyy-MM-dd HH:mm:ss}");
OnTimeSynced?.Invoke(_currentBeijingTime);
Debug.Log($"北京时间同步成功:{CurrentBeijingTime:yyyy-MM-dd HH:mm:ss},偏移量:{_serverTimeOffset.TotalSeconds:F1}s");
OnTimeSynced?.Invoke(CurrentBeijingTime);
yield break;
}
}
@@ -150,11 +141,11 @@ public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
if (!string.IsNullOrEmpty(timeStr))
{
_currentBeijingTime = DateTime.ParseExact(timeStr, "yyyy-MM-dd HH:mm:ss", null);
_timeSinceLastSync = 0;
DateTime serverTime = DateTime.ParseExact(timeStr, "yyyy-MM-dd HH:mm:ss", null);
_serverTimeOffset = serverTime - DateTime.Now;
_isTimeSynced = true;
Debug.Log($"北京时间同步成功:{_currentBeijingTime:yyyy-MM-dd HH:mm:ss}");
OnTimeSynced?.Invoke(_currentBeijingTime);
Debug.Log($"北京时间同步成功:{CurrentBeijingTime:yyyy-MM-dd HH:mm:ss},偏移量:{_serverTimeOffset.TotalSeconds:F1}s");
OnTimeSynced?.Invoke(CurrentBeijingTime);
yield break;
}
}
@@ -169,7 +160,7 @@ public class BeijingTimeManager : MonoSingleton<BeijingTimeManager>
}
Debug.LogError("所有时间服务器都失败了,使用本地时间");
_currentBeijingTime = DateTime.Now;
_serverTimeOffset = TimeSpan.Zero;
_isTimeSynced = false;
}
@@ -140,11 +140,11 @@ public class MonsterContral : MonoBehaviour
// ================================================================
// Unity 生命周期
// ================================================================
public bool baseMmove;
public virtual void Awake()
{
LoadHitEffect();
baseMmove = isMove;
}
public async void LoadHitEffect()
{
@@ -158,11 +158,14 @@ public class MonsterContral : MonoBehaviour
}
public virtual void OnEnable()
{
// ⭐ 重置 isMove=true:池回收的鱼重新生成时,必须恢复移动状态。
// 之前被注释掉导致:冰冻时 FreezeAllFish 设 isMove=false → 鱼被回收 →
// 重新生成后 isMove 残留 false → 鱼永远不动(一直在中间不会游动)。
// 冰冻中重新激活的鱼,FreezeAllFish 会立即覆盖为 false,安全。
isMove = true;
// ⭐ 用 baseMmove 恢复 isMove:Awake 时记录预制体原始 isMove 状态。
// - 普通鱼预制体 isMove=true → 池回收后恢复 true,正常游动
// (之前被注释导致:冰冻时 FreezeAllFish 设 isMove=false → 鱼回收 →
// 重新生成后残留 false → 鱼永远不动)
// - 爆奖 Boss 预制体 isMove=false → 恢复 false,固定在 (0,0,0) 播放动画
// (金龙/雷龙/玉龙等不走路径,直到爆奖结束销毁)
// - 冰冻中重新激活的鱼,末尾会覆盖为 false,安全
isMove = baseMmove;
fishenum = (FishTypeEnum)monsterData.fishTypeConfig.fishType;
uirootRect = UIManager.Instance.uiRoot.GetComponent<RectTransform>();
mainCamera = Camera.main;
@@ -170,7 +173,7 @@ public class MonsterContral : MonoBehaviour
InitAnimList();
ChangeState(CharacterStateType.move);
// ⭐ 同步冰冻特效状态:池回收的鱼 bingDongEffect 可能残留激活状态,
// ⭐ 同步冰冻特效状态:池回收的鱼 bingDongEffect 可能残留激活状态,
// 重新生成时会显示白色冰冻蒙皮。根据当前是否冰冻中决定显隐
bool frozen = CreateFishManager.Instance != null && CreateFishManager.Instance.isFrozen;
SetFreezeEffect(frozen);
@@ -204,6 +204,9 @@ public class GameManager : MonoSingleton<GameManager>
_ => 60
};
// ⭐ 防止手机屏幕自动黑屏休眠
Screen.sleepTimeout = SleepTimeout.NeverSleep;
AudioResourcesData audioResourcesData = new AudioResourcesData();
InItLoad();
//TurretResourcesData turretResourcesData = new TurretResourcesData();
@@ -1509,7 +1509,8 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
CrossPlatformInput input = GetInput();
if (!toggle_Lock.isOn) return;
if (!input.wasPressedThisFrame && !input.wasReleasedThisFrame) return;
//if (!input.wasPressedThisFrame && !input.wasReleasedThisFrame) return;
if (!input.wasPressedThisFrame) return;
if (IsPointerOverUI(input.position)) return;
// 射线从相机出发,指向鼠标点击点