2026-02-03 11:35:19 +08:00
|
|
|
|
using Assets.MyGame.Scripts.Net;
|
|
|
|
|
|
using Assets.MyGame.Scripts.Net.API;
|
2026-04-29 01:18:39 +08:00
|
|
|
|
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
2026-04-25 18:53:04 +08:00
|
|
|
|
using CameraShake;
|
2026-02-03 11:35:19 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2026-03-09 09:25:01 +08:00
|
|
|
|
using System;
|
2026-04-29 01:18:39 +08:00
|
|
|
|
using System.Collections.Generic;
|
2026-06-08 21:23:40 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2025-12-11 16:40:24 +08:00
|
|
|
|
using UnityEngine;
|
2026-03-18 17:26:14 +08:00
|
|
|
|
using UnityEngine.InputSystem;
|
2026-04-17 18:30:51 +08:00
|
|
|
|
using UnityEngine.Rendering;
|
2026-02-03 11:35:19 +08:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2026-04-21 23:02:51 +08:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UnityEngine.Video;
|
2025-12-11 16:40:24 +08:00
|
|
|
|
|
|
|
|
|
|
public class GameManager : MonoSingleton<GameManager>
|
|
|
|
|
|
{
|
2026-06-16 23:45:31 +08:00
|
|
|
|
[Header("人机")]
|
|
|
|
|
|
public bool enableBot = true; // 人机开关
|
|
|
|
|
|
|
2026-02-03 11:35:19 +08:00
|
|
|
|
public GameConfig gameConfig;
|
2026-04-29 01:18:39 +08:00
|
|
|
|
public Dictionary<string, FishTypeConfig> dic_fishTypeConfigs=new Dictionary<string, FishTypeConfig>();
|
2026-04-13 18:30:55 +08:00
|
|
|
|
public UserData user;
|
2026-03-09 09:25:01 +08:00
|
|
|
|
public GameData gameData = new GameData();
|
2026-02-03 11:35:19 +08:00
|
|
|
|
public Scene scene;
|
2026-06-21 18:20:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 头像更新事件(换了头像后触发,所有头像控件统一刷新)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public event Action<Sprite> OnAvatarChanged;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>头像字典(name → sprite),从 Resources/Avatar 加载</summary>
|
|
|
|
|
|
private Dictionary<string, Sprite> avatarSpriteDict = new Dictionary<string, Sprite>();
|
|
|
|
|
|
|
2026-06-21 22:38:18 +08:00
|
|
|
|
/// <summary>默认头像(新账号无头像时使用)</summary>
|
|
|
|
|
|
private Sprite defaultAvatar;
|
|
|
|
|
|
|
2026-06-21 18:20:55 +08:00
|
|
|
|
/// <summary>触发头像更新事件</summary>
|
|
|
|
|
|
public void TriggerAvatarChanged(Sprite sprite)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnAvatarChanged?.Invoke(sprite);
|
|
|
|
|
|
}
|
2026-04-29 01:18:39 +08:00
|
|
|
|
public CameraShaker cameraShake;
|
2026-04-26 20:29:22 +08:00
|
|
|
|
public Camera ZhuCam;
|
|
|
|
|
|
|
|
|
|
|
|
// // 指定此方法在加载时立即调用,在显示启动动画前之前执行
|
|
|
|
|
|
// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
|
|
|
|
|
|
// private static void BeforeSplashScreen()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// //平台适配
|
|
|
|
|
|
//#if UNITY_WEBGL
|
|
|
|
|
|
// // 如果在 WebGL 平台上运行,立即停止启动动画
|
|
|
|
|
|
// SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
|
|
|
|
|
|
//#else
|
|
|
|
|
|
// // 如果不是在 WebGL 平台上,启动一个异步任务来停止启动动画
|
|
|
|
|
|
// System.Threading.Tasks.Task.Run(() =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
|
|
|
|
|
|
// });
|
|
|
|
|
|
//#endif
|
|
|
|
|
|
// }
|
2026-06-21 18:20:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化头像缓存(从 Resources/Avatar 加载所有Sprite)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void InitAvatarCache()
|
|
|
|
|
|
{
|
|
|
|
|
|
avatarSpriteDict.Clear();
|
|
|
|
|
|
var sprites = Resources.LoadAll<Sprite>("Avatar");
|
|
|
|
|
|
foreach (var s in sprites)
|
|
|
|
|
|
avatarSpriteDict[s.name] = s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据名称获取头像 Sprite
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Sprite GetAvatarSprite(string avatarName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (avatarSpriteDict.Count == 0) InitAvatarCache();
|
2026-06-21 22:38:18 +08:00
|
|
|
|
if (string.IsNullOrEmpty(avatarName) || !avatarSpriteDict.TryGetValue(avatarName, out var sprite))
|
|
|
|
|
|
sprite = GetDefaultAvatar();
|
2026-06-21 18:20:55 +08:00
|
|
|
|
return sprite;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-21 22:38:18 +08:00
|
|
|
|
private Sprite GetDefaultAvatar()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (defaultAvatar == null && avatarSpriteDict.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 取缓存中第一个头像作为默认
|
|
|
|
|
|
foreach (var kv in avatarSpriteDict)
|
|
|
|
|
|
{
|
|
|
|
|
|
defaultAvatar = kv.Value;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return defaultAvatar;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-21 18:20:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更换头像:上传服务端 → 更新本地 → 触发全局刷新
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ApplyAvatar(string avatarUrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
APIRequestList.UpdateAvatar(avatarUrl, (result) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
user.BaseInfo.avatarUrl = avatarUrl;
|
|
|
|
|
|
user.BaseInfo.avatarSprite = null;
|
|
|
|
|
|
|
|
|
|
|
|
var sprite = GetAvatarSprite(avatarUrl);
|
|
|
|
|
|
TriggerAvatarChanged(sprite);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-13 18:30:55 +08:00
|
|
|
|
public void UpdataUserData(UserData user)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.user = user;
|
|
|
|
|
|
var a = UIManager.Instance.Get<UIHomeMain>(UIPanel.HomeMainPanel);
|
|
|
|
|
|
if (a!=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
a.UpdateUserData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2026-06-08 21:23:40 +08:00
|
|
|
|
protected override void Awake()
|
2025-12-26 11:15:56 +08:00
|
|
|
|
{
|
2026-06-21 00:07:26 +08:00
|
|
|
|
// ⭐ 游戏启动时加载已保存的画质和帧率设置
|
|
|
|
|
|
int quality = PlayerPrefs.GetInt("GraphicsQuality", 1);
|
|
|
|
|
|
QualitySettings.SetQualityLevel(quality, true);
|
|
|
|
|
|
|
|
|
|
|
|
int fps = PlayerPrefs.GetInt("TargetFps", 1);
|
|
|
|
|
|
Application.targetFrameRate = fps switch
|
|
|
|
|
|
{
|
|
|
|
|
|
0 => 30,
|
|
|
|
|
|
1 => 60,
|
|
|
|
|
|
2 => -1,
|
|
|
|
|
|
_ => 60
|
|
|
|
|
|
};
|
2026-04-03 09:28:13 +08:00
|
|
|
|
|
2026-04-29 23:53:55 +08:00
|
|
|
|
AudioResourcesData audioResourcesData=new AudioResourcesData();
|
2026-06-08 21:23:40 +08:00
|
|
|
|
InItLoad();
|
|
|
|
|
|
//TurretResourcesData turretResourcesData = new TurretResourcesData();
|
2026-02-26 11:05:56 +08:00
|
|
|
|
Application.runInBackground = true;
|
2026-04-03 09:28:13 +08:00
|
|
|
|
|
2025-12-26 11:15:56 +08:00
|
|
|
|
base.Awake();
|
2026-04-25 18:53:04 +08:00
|
|
|
|
cameraShake = Camera.main.GetComponent<CameraShaker>();
|
2026-03-09 09:25:01 +08:00
|
|
|
|
gameData.currUser = "123";
|
2026-02-03 11:35:19 +08:00
|
|
|
|
//string json = Resources.Load<TextAsset>("Config/GameConfig").text;
|
|
|
|
|
|
//gameConfig = JsonConvert.DeserializeObject<APIResponse<GameConfig>>(json).data;
|
2026-04-29 01:18:39 +08:00
|
|
|
|
APIManager.Response<GameConfig>(APIType.GameConfig_Get, res => { gameConfig = res; var v = CreateFishManager.Instance.CreateDic;
|
|
|
|
|
|
foreach (var item in gameConfig.fishTypeConfigs)
|
|
|
|
|
|
{
|
|
|
|
|
|
dic_fishTypeConfigs[item.fishNumber]=item;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-02-03 11:35:19 +08:00
|
|
|
|
|
2026-03-09 09:25:01 +08:00
|
|
|
|
}
|
2026-06-08 21:23:40 +08:00
|
|
|
|
public async Task InItLoad()
|
|
|
|
|
|
{
|
|
|
|
|
|
await TurretResourcesData.LoadTurretAssetsData();
|
|
|
|
|
|
}
|
2026-03-09 09:25:01 +08:00
|
|
|
|
public void StartGame(Action action)
|
2025-12-13 18:18:28 +08:00
|
|
|
|
{
|
2026-02-03 11:35:19 +08:00
|
|
|
|
|
2025-12-26 11:15:56 +08:00
|
|
|
|
switch (gameData.currGameType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case GameType.JQQD:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GameType.defaultPanel:
|
|
|
|
|
|
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
|
|
|
|
|
break;
|
2026-03-12 10:48:53 +08:00
|
|
|
|
case GameType.FLZY:
|
|
|
|
|
|
if (action != null)
|
|
|
|
|
|
WebSocketManager.Instance.Connect(SocketType.game, action);
|
|
|
|
|
|
//UIManager.Instance.ShowAsync(UIPanel.MainGamePanelFLZY);
|
2025-12-26 11:15:56 +08:00
|
|
|
|
break;
|
2026-05-07 03:46:03 +08:00
|
|
|
|
case GameType.YYSC:
|
|
|
|
|
|
if (action != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WebSocketManager.Instance.Connect(SocketType.game, action);
|
|
|
|
|
|
}
|
2025-12-26 11:15:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case GameType.ZGXQ:
|
2026-02-13 19:23:01 +08:00
|
|
|
|
//UIManager.Instance.ShowAsync(UIPanel.MainGamePanelZGXQ);
|
|
|
|
|
|
//这里设置触发棋盘的初始化
|
|
|
|
|
|
|
2025-12-26 11:15:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case GameType.XJMH:
|
2026-03-09 09:25:01 +08:00
|
|
|
|
if (action != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WebSocketManager.Instance.Connect(SocketType.game, action);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
WebSocketManager.Instance.Connect(SocketType.game);
|
2025-12-26 11:15:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case GameType.HHWK:
|
2026-03-18 17:26:14 +08:00
|
|
|
|
//UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
|
|
|
|
|
if (action != null)
|
|
|
|
|
|
WebSocketManager.Instance.Connect(SocketType.game, action);
|
2025-12-26 11:15:56 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2026-03-09 09:25:01 +08:00
|
|
|
|
|
2025-12-13 18:18:28 +08:00
|
|
|
|
}
|
2025-12-11 16:40:24 +08:00
|
|
|
|
// Start is called before the first frame update
|
2026-04-21 23:02:51 +08:00
|
|
|
|
public Button btn_Skip;
|
|
|
|
|
|
public VideoClip startVideoClip;
|
2025-12-11 16:40:24 +08:00
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
2026-04-21 23:02:51 +08:00
|
|
|
|
var v = UIManager.Instance.ShowLoadPanel(startVideoClip);
|
2026-04-23 17:24:31 +08:00
|
|
|
|
UIManager.Instance.ShowAsync(UIPanel.LoginPanel, null, (a) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
v.LoadBar(100);
|
|
|
|
|
|
}, 28);
|
2026-04-21 23:02:51 +08:00
|
|
|
|
btn_Skip.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
2026-04-22 00:23:14 +08:00
|
|
|
|
UIManager.Instance.StopShowPanel();
|
2026-04-21 23:02:51 +08:00
|
|
|
|
UIManager.Instance.ShowAsync(UIPanel.LoginPanel, null, null, 0);
|
|
|
|
|
|
v.LoadBar(100);
|
|
|
|
|
|
});
|
2025-12-11 16:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
2026-03-18 17:26:14 +08:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
if (Keyboard.current.qKey.wasPressedThisFrame)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.ShowBoardGongGao("太有实力了dadadadwawafdsdrgdfghdsufhkjghjksdfdgdffghgjhgykhjkhjghjfg");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
2025-12-26 11:15:56 +08:00
|
|
|
|
|
2025-12-11 16:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|