196 lines
6.6 KiB
C#
196 lines
6.6 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description: 游戏入口
|
||
* @Date: 2025年04月01日 星期二 11:04:16
|
||
* @Modify:
|
||
*/
|
||
using System;
|
||
using Logic.Audio;
|
||
using Logic.CrashSight;
|
||
using Logic.Multilingual;
|
||
using Logic.Timeline;
|
||
using UnityEngine;
|
||
using RuntimeData;
|
||
using TH1Renderer;
|
||
using TH1Resource;
|
||
using UnityEngine.Diagnostics;
|
||
|
||
|
||
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;
|
||
public bool DebugHideCenterMessage = false;
|
||
|
||
[Header("Play Settings")]
|
||
public int cityCount;
|
||
public int unitCount;
|
||
public int turn;
|
||
public int renko = 0; //真正的玩家一人
|
||
|
||
|
||
[Header("RenderObject")]
|
||
public GameObject ROMapRenderer;
|
||
|
||
//--------------------------------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 StartInstanceGroup()
|
||
{
|
||
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;
|
||
DebugCenter.Instance.DebugHideCenterMessage = DebugHideCenterMessage;
|
||
|
||
//初始化SpriteCache,加载所有sprite
|
||
new ResourceCache(); //ResourceCache单例 ,缓存所有resource
|
||
ResourceCache.Instance.Init();
|
||
|
||
new UIManager(); //UIManager单例
|
||
UIManager.Instance.Init(this);
|
||
}
|
||
|
||
void Start()
|
||
{
|
||
CrashSightManager.Instance.Initialize();
|
||
|
||
MapData = null;
|
||
|
||
//初始化各种单例
|
||
StartInstanceGroup();
|
||
|
||
|
||
|
||
|
||
if(LandThreshold > 0)
|
||
DebugCenter.Instance.DebugLandThreshold = LandThreshold;
|
||
|
||
CityLogic ??= new CityLogic();
|
||
UnitLogic ??= new UnitLogic();
|
||
PlayerLogic ??= new PlayerLogic(this);
|
||
|
||
GameLogic = new GameLogic(this);
|
||
|
||
|
||
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,然后重新初始化
|
||
MapRenderer.Dispose();
|
||
MapRenderer.Initialize(this,MapData);
|
||
UIManager.Instance.GameInit(MapData);
|
||
|
||
MapRenderer.Instance.FirstRenderMap();
|
||
|
||
GameLogic.ChangeState(GameState.PlayerRound);
|
||
|
||
}
|
||
public void StartGame(uint h, uint w,uint playerCount, uint civId, uint forceId)
|
||
{
|
||
//LogSystem.LogInfo($"Game Start!!!!");
|
||
|
||
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,然后重新初始化
|
||
MapRenderer.Dispose();
|
||
MapRenderer.Initialize(this,MapData);
|
||
|
||
UIManager.Instance.GameInit(MapData);
|
||
MapGeneratorLogic.GenerateMap(MapData);
|
||
MapRenderer.Instance.FirstRenderMap();
|
||
|
||
//移动镜头+显示开局提示
|
||
|
||
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,true);
|
||
UIManager.Instance.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.TryUpdate();
|
||
UIManager.Instance.Update(MapData);
|
||
Timer.Instance.Update();
|
||
AudioManager.Instance.Update();
|
||
TimelineManager.Instance.Update();
|
||
}
|
||
|
||
public bool HasArchive()
|
||
{
|
||
return PlayerPrefs.GetInt("Archive", 0) == 1;
|
||
}
|
||
}
|
||
}
|