217 lines
5.7 KiB
C#
217 lines
5.7 KiB
C#
using AmazingAssets.CurvedWorld;
|
|
using Config.config;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 地图管理器
|
|
/// </summary>
|
|
public partial class MapManager : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 最大车道数
|
|
/// </summary>
|
|
private int maxTrack;
|
|
|
|
/// <summary>
|
|
/// 最小车道数
|
|
/// </summary>
|
|
private int minTrack;
|
|
|
|
/// <summary>
|
|
/// 道路数
|
|
/// </summary>
|
|
private int trackNumber;
|
|
|
|
/// <summary>
|
|
/// 是否交换
|
|
/// </summary>
|
|
private bool isExchange;
|
|
|
|
/// <summary>
|
|
/// 玩家
|
|
/// </summary>
|
|
private Player player;
|
|
|
|
/// <summary>
|
|
/// 关卡配置
|
|
/// </summary>
|
|
private LevelConfig levelConfig;
|
|
|
|
/// <summary>
|
|
/// 弯道控制
|
|
/// </summary>
|
|
public CurvedWorldController curvedWorld;
|
|
|
|
/// <summary>
|
|
/// 路段一
|
|
/// </summary>
|
|
public SectionRoad sectionRoadOne;
|
|
|
|
/// <summary>
|
|
/// 路段二
|
|
/// </summary>
|
|
public SectionRoad sectionRoadTwo;
|
|
|
|
/// <summary>
|
|
/// 当前路段
|
|
/// </summary>
|
|
[HideInInspector]public SectionRoad currentSectionRoad;
|
|
|
|
/// <summary>
|
|
/// 补充路段
|
|
/// </summary>
|
|
[HideInInspector]public SectionRoad supplementSectionRoad;
|
|
|
|
private void Update()
|
|
{
|
|
SetCurvedWorld();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置关卡
|
|
/// </summary>
|
|
public void SetLevel(LevelConfig levelConfig)
|
|
{
|
|
this.levelConfig = levelConfig;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
InitCurvedWorld();
|
|
sectionRoadOne.Init();
|
|
sectionRoadOne.transform.localPosition = Vector3.zero;
|
|
sectionRoadTwo.Init();
|
|
sectionRoadOne.SetBuildingTheme(levelConfig);
|
|
sectionRoadTwo.SetBuildingTheme(levelConfig);
|
|
sectionRoadTwo.transform.localPosition = sectionRoadOne.transform.localPosition+ Vector3.forward*311;
|
|
sectionRoadOne.InitLaneNumber(levelConfig.InitialTrack);
|
|
sectionRoadTwo.BothAreConsistent(sectionRoadOne);
|
|
trackNumber = levelConfig.InitialTrack;
|
|
minTrack = levelConfig.MinTrack;
|
|
maxTrack = levelConfig.MaxTrack;
|
|
currentSectionRoad = sectionRoadOne;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化生成车
|
|
/// </summary>
|
|
public void InitGenerateNPCCar()
|
|
{
|
|
if (GuidanceManger.Instance.isEnableNormalMode)
|
|
{
|
|
sectionRoadTwo.GenerateNPCCar(new List<int>() { 0, 1, 2 }, levelConfig);
|
|
sectionRoadOne.GenerateRoadblock(sectionRoadTwo);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化新手引导生成车
|
|
/// </summary>
|
|
public void InitguidanceGenerateNPCCar()
|
|
{
|
|
supplementSectionRoad.GenerateNPCCar(new List<int>() { 0, 1, 2 }, levelConfig);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 复活初始化
|
|
/// </summary>
|
|
public void ResurgenceInit()
|
|
{
|
|
sectionRoadOne.PutRoadblockObjs();
|
|
sectionRoadTwo.PutRoadblockObjs();
|
|
supplementSectionRoad.GenerateNPCCar(new List<int>() { 0, 1, 2 }, levelConfig);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置玩家
|
|
/// </summary>
|
|
public void SetPlayer(Player player)
|
|
{
|
|
this.player = player;
|
|
curvedWorld.bendPivotPoint = player.transform;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 游戏结束
|
|
/// </summary>
|
|
public void GameOver()
|
|
{
|
|
sectionRoadOne.PutCar();
|
|
sectionRoadTwo.PutCar();
|
|
sectionRoadTwo.PutRoadblockObjs();
|
|
supplementSectionRoad.BothAreConsistent(currentSectionRoad);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 交换
|
|
/// </summary>
|
|
public void Exchange()
|
|
{
|
|
if (isExchange) return;
|
|
isExchange = true;
|
|
if (currentSectionRoad == sectionRoadOne)
|
|
{
|
|
currentSectionRoad = sectionRoadTwo;
|
|
supplementSectionRoad=sectionRoadOne;
|
|
}
|
|
else
|
|
{
|
|
currentSectionRoad = sectionRoadOne;
|
|
supplementSectionRoad= sectionRoadTwo;
|
|
}
|
|
player.SetSectionRoad(currentSectionRoad);
|
|
|
|
DelayedProcessingManager.Instance.DelayDoSecond(this, 0.2f, () =>
|
|
{
|
|
ExchangeRenderer();
|
|
isExchange = false;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 交换渲染
|
|
/// </summary>
|
|
public void ExchangeRenderer()
|
|
{
|
|
supplementSectionRoad.PutRoadblockObjs();
|
|
supplementSectionRoad.transform.position = currentSectionRoad.transform.position+currentSectionRoad.transform.forward * 311;
|
|
if (ProbabilityManager.Instance.GetPercent(60) && Scenes.Instance.e_GameState == E_GameState.Gameing&& UserDataManager.Instance.userData.guidance.isOverInitialEntry)
|
|
{
|
|
trackNumber = Random.Range(minTrack, (maxTrack + 1));
|
|
supplementSectionRoad.BothAreConsistent(currentSectionRoad);
|
|
supplementSectionRoad.InitLaneNumber(trackNumber);
|
|
}
|
|
else
|
|
{
|
|
supplementSectionRoad.BothAreConsistent(currentSectionRoad);
|
|
}
|
|
|
|
if (Scenes.Instance.e_GameState == E_GameState.Gameing)
|
|
{
|
|
if (GuidanceManger.Instance.isEnableNormalMode)
|
|
{
|
|
if (ProbabilityManager.Instance.GetPercent(30))
|
|
{
|
|
supplementSectionRoad.GenerateTrain(levelConfig);
|
|
}
|
|
else
|
|
{
|
|
supplementSectionRoad.GenerateNPCCar(new List<int>() { 0, 1, 2 }, levelConfig);
|
|
}
|
|
currentSectionRoad.GenerateRoadblock(supplementSectionRoad);
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|