169 lines
6.0 KiB
C#
169 lines
6.0 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description: 游戏入口
|
||
* @Date: 2025年04月01日 星期二 11:04:16
|
||
* @Modify:
|
||
*/
|
||
|
||
|
||
using System;
|
||
using Logic.AI;
|
||
using Logic.Audio;
|
||
using Logic.Multilingual;
|
||
using UnityEngine;
|
||
using RuntimeData;
|
||
using Unity.VisualScripting;
|
||
|
||
|
||
namespace Logic
|
||
{
|
||
public class Main : MonoBehaviour
|
||
{
|
||
[Header("Debug Param")]
|
||
public bool NoAI = false;
|
||
public bool FullSight = true;
|
||
public float AIActionTime = 0.2f;
|
||
public bool AIAllTech = true;
|
||
public bool AIMoreMoney = true;
|
||
public float LandThreshold = -1f;
|
||
public float AnimationSpeed = 1f;
|
||
public bool DebugMode = false;
|
||
|
||
[Header("Play Settings")]
|
||
public int cityCount;
|
||
public int unitCount;
|
||
public int turn;
|
||
public int renko = 0; //真正的玩家一人
|
||
|
||
|
||
[Header("Manager")] public MapRenderer MapRenderer;
|
||
RenderUpdateManager renderUpdateManager; //用来管理Data和Renderer之间更新通讯
|
||
|
||
//--------------------------------new data type--------------------------------
|
||
[NonSerialized] public MapConfig MapConfig;
|
||
[NonSerialized] public MapData MapData;
|
||
|
||
//各Logic模块的引用
|
||
//一级logic,AI和input
|
||
public InputLogic InputLogic; //一级 输入logic
|
||
public MapGenerator MapGeneratorLogic;
|
||
public GameLogic GameLogic;
|
||
//二级logic,map的交互处理Logic
|
||
|
||
public MapInteraction MapInteractionLogic;
|
||
|
||
//三级logic,city/unit/player/tile/的处理
|
||
public static CityLogic CityLogic;
|
||
public static UnitLogic UnitLogic;
|
||
public static PlayerLogic PlayerLogic;
|
||
public UIManager UIManager;
|
||
|
||
//Library模块的引用
|
||
Table table;
|
||
|
||
void Start()
|
||
{
|
||
MapData = null;
|
||
|
||
new Table(); //Table单例
|
||
new Timer(); //Timer单例
|
||
new DebugCenter(); //Debug单例
|
||
|
||
|
||
DebugCenter.Instance.DebugNoAI = NoAI;
|
||
DebugCenter.Instance.DebugSelfPlayerAllSight = FullSight;
|
||
DebugCenter.Instance.DebugAIAllTech = AIAllTech;
|
||
DebugCenter.Instance.DebugAIMoreMoney = AIMoreMoney;
|
||
DebugCenter.Instance.DebugAIActionTime = AIActionTime;
|
||
DebugCenter.Instance.AnimationSpeed = AnimationSpeed;
|
||
DebugCenter.Instance.DebugMode = DebugMode;
|
||
if(LandThreshold > 0)
|
||
DebugCenter.Instance.DebugLandThreshold = LandThreshold;
|
||
|
||
CityLogic ??= new CityLogic();
|
||
UnitLogic ??= new UnitLogic();
|
||
PlayerLogic ??= new PlayerLogic(this);
|
||
|
||
GameLogic = new GameLogic(this);
|
||
UIManager = new UIManager(this);
|
||
UIManager.Init();
|
||
GameRecordManager.Instance.Init();
|
||
AchievementDataManager.Instance.Init();
|
||
AudioManager.Instance.Init();
|
||
MultilingualManager.Instance.Init();
|
||
AudioManager.Instance.PlayMusic("Main",0.3f,0.3f,true);
|
||
//StartGame(height,width,0,0);
|
||
// ContinueGame();
|
||
}
|
||
|
||
|
||
public void ContinueGame()
|
||
{
|
||
if (!HasArchive()) return;
|
||
MapData = MapData.GetMapData();
|
||
AchievementDataManager.Instance.BindMapData(MapData);
|
||
//初始化所有Logic
|
||
InputLogic = new InputLogic(this,MapData);
|
||
MapInteractionLogic = new MapInteraction(this,MapData);
|
||
MapGeneratorLogic = new MapGenerator(this,MapData);
|
||
|
||
MapRenderer = new MapRenderer(this,MapData);
|
||
UIManager.GameInit(MapData);
|
||
//MapGeneratorLogic.GenerateMap(MapData);
|
||
MapRenderer.FirstRenderMap();
|
||
GameLogic.ChangeState(GameState.PlayerRound);
|
||
//mapRenderer.CameraFocusOnTile(map.player[map.renko].cityList[0].cityCenter);
|
||
|
||
//移动镜头+显示开局提示
|
||
//UIManager.CenterMessageUI.SetCenterMessageShow(UICenterMessageID.StartGame,MapData.PlayerMap.SelfPlayerData);
|
||
}
|
||
public void StartGame(uint h, uint w,uint playerCount, uint civId, uint forceId)
|
||
{
|
||
MapConfig = new MapConfig(h,w,playerCount,civId,forceId);
|
||
//初始化所有Data
|
||
MapData = new MapData(MapConfig);
|
||
|
||
AchievementDataManager.Instance.BindMapData(MapData);
|
||
//初始化所有Logic
|
||
InputLogic = new InputLogic(this,MapData);
|
||
|
||
MapInteractionLogic = new MapInteraction(this,MapData);
|
||
MapGeneratorLogic = new MapGenerator(this,MapData);
|
||
|
||
MapRenderer = new MapRenderer(this,MapData);
|
||
UIManager.GameInit(MapData);
|
||
MapGeneratorLogic.GenerateMap(MapData);
|
||
MapRenderer.FirstRenderMap();
|
||
//mapRenderer.CameraFocusOnTile(map.player[map.renko].cityList[0].cityCenter);
|
||
|
||
//移动镜头+显示开局提示
|
||
|
||
var camera = GameObject.Find("Main Camera").GetComponent<CameraController>();
|
||
var selfp = MapData.PlayerMap.SelfPlayerData;
|
||
if(MapData.GetCapitalCityDataByPlayerId(selfp.Id, out var cap)
|
||
&& MapData.GetGridDataByCityId(cap.Id, out var grid))
|
||
camera.CameraFocusOnGrid(grid);
|
||
UIManager.CenterMessageUI.SetCenterMessageShow(UICenterMessageID.StartGame,MapData.PlayerMap.SelfPlayerData);
|
||
GameLogic.ChangeState(GameState.PlayerRound);
|
||
}
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
MainEditor.Instance.Update();
|
||
GameLogic.Update();
|
||
PlayerLogic.Update(MapData);
|
||
//先处理玩家输入
|
||
InputLogic?.Update();
|
||
MapRenderer?.Update();
|
||
UIManager.Update(MapData);
|
||
Timer.Instance.Update();
|
||
AudioManager.Instance.Update();
|
||
}
|
||
|
||
public bool HasArchive()
|
||
{
|
||
return PlayerPrefs.GetInt("Archive", 0) == 1;
|
||
}
|
||
}
|
||
}
|