using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.Events;
|
|
|
public class StageLoad : SingletonMonobehaviour<StageLoad>
|
{
|
StageLoadProcessor stageLoadProcessor;
|
public float progress
|
{
|
get
|
{
|
if (stageLoadProcessor != null)
|
{
|
return stageLoadProcessor.progress;
|
}
|
else
|
{
|
return 0f;
|
}
|
}
|
}
|
|
Stage m_CurrentStage;
|
public Stage currentStage
|
{
|
get { return m_CurrentStage; }
|
set { m_CurrentStage = value; }
|
}
|
|
public Stage.E_StageType stageType
|
{
|
get
|
{
|
return (currentStage != null && currentStage is DungeonStage) ? Stage.E_StageType.Dungeon : Stage.E_StageType.MainCity;
|
}
|
}
|
|
public event Action<int> onStartStageLoadingEvent;
|
public UnityAction onStageLoadFinish;
|
|
StageLoadCommand currentCommand;
|
Queue<StageLoadCommand> commands = new Queue<StageLoadCommand>();
|
|
bool server0109Ok_Main = false;
|
bool server0109Ok_CrossServer;
|
|
float loadStartTime = 0f;
|
public bool isLoading { get; private set; }
|
public bool isLoadingScene;
|
|
public int mapIdRecord { get; private set; }
|
public int lineIdRecord { get; private set; }
|
|
public void PushSceneLoadCommand(StageLoadCommand command)
|
{
|
if (!isLoading && commands.Count == 0)
|
{
|
currentCommand = command;
|
currentCommand.fromMapId = mapIdRecord;
|
currentCommand.fromLineId = lineIdRecord;
|
ExcuteCommand(currentCommand);
|
}
|
else
|
{
|
commands.Enqueue(command);
|
}
|
}
|
|
private void ExcuteCommand(StageLoadCommand command)
|
{
|
var tasks = new Queue<StageLoadProcessor.StageLoadTask>();
|
var needLoadResource = true;
|
if (command.needLoadResource)
|
{
|
if (command.fromMapId != command.toMapId)
|
{
|
needLoadResource = true;
|
}
|
else
|
{
|
var config1 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.fromMapId), command.fromLineId);
|
var config2 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.toMapId), command.toLineId);
|
if (config1 == null || config2 == null)
|
{
|
needLoadResource = true;
|
}
|
else
|
{
|
needLoadResource = config1.MapResources != config2.MapResources;
|
}
|
}
|
}
|
else
|
{
|
needLoadResource = false;
|
}
|
|
var assetValid = AssetVersionUtility.IsSceneAssetValid(command.toMapId, command.toLineId);
|
if (!assetValid)
|
{
|
tasks.Enqueue(new StageLoadProcessor.Wait0109Task(command));
|
if (command.serverType == ServerType.Main)
|
{
|
tasks.Enqueue(new StageLoadProcessor.WaitLoginCompleteTask(command));
|
}
|
tasks.Enqueue(new StageLoadProcessor.WaitSecondsTask(command, 1));
|
tasks.Enqueue(new StageLoadProcessor.ReturnToNoviceVillageTask(command));
|
}
|
else
|
{
|
if (needLoadResource)
|
{
|
tasks.Enqueue(new StageLoadProcessor.PreProcessTask(command));
|
if (command.isClientLoadMap && command.toMapId != 3)
|
{
|
tasks.Enqueue(new StageLoadProcessor.WaitSecondsTask(command, 0.5f));
|
}
|
tasks.Enqueue(new StageLoadProcessor.UnLoadAndGCTask(command));
|
}
|
|
if (needLoadResource && command.needEmpty)
|
{
|
tasks.Enqueue(new StageLoadProcessor.LoadEmptyTask(command));
|
}
|
|
if (needLoadResource)
|
{
|
tasks.Enqueue(new StageLoadProcessor.LoadNewSceneTask(command));
|
isLoadingScene = true;
|
}
|
|
if (!command.isClientLoadMap)
|
{
|
tasks.Enqueue(new StageLoadProcessor.Wait0109Task(command));
|
if (command.serverType == ServerType.Main)
|
{
|
tasks.Enqueue(new StageLoadProcessor.WaitLoginCompleteTask(command));
|
}
|
}
|
|
if (needLoadResource)
|
{
|
tasks.Enqueue(new StageLoadProcessor.PostProcessTask(command));
|
}
|
}
|
|
UpdateServerFlag(command.serverType, false);
|
|
var gameObject = new GameObject("StageLoadProcessor");
|
DontDestroyOnLoad(gameObject);
|
stageLoadProcessor = gameObject.AddComponent<StageLoadProcessor>();
|
stageLoadProcessor.Begin(tasks);
|
|
StageLoadTimeOutCatcher.Begin(command.toMapId);
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
loadStartTime = Time.time;
|
isLoading = true;
|
}
|
|
public void ReportComplete(int mapId, int lineId, bool record)
|
{
|
if (record)
|
{
|
mapIdRecord = mapId;
|
lineIdRecord = lineId;
|
}
|
|
isLoading = false;
|
StageLoadTimeOutCatcher.Stop();
|
|
if (stageLoadProcessor != null)
|
{
|
DestroyImmediate(stageLoadProcessor.gameObject);
|
stageLoadProcessor = null;
|
}
|
}
|
|
public void UpdateServerFlag(ServerType serverType, bool ok)
|
{
|
if (ok)
|
{
|
if (currentCommand != null && !currentCommand.isClientLoadMap && !currentCommand.serverFlag0109)
|
{
|
currentCommand.serverFlag0109 = true;
|
}
|
else
|
{
|
foreach (var command in commands)
|
{
|
if (command.serverType == serverType && !command.serverFlag0109)
|
{
|
command.serverFlag0109 = true;
|
break;
|
}
|
}
|
}
|
}
|
|
switch (serverType)
|
{
|
case ServerType.Main:
|
server0109Ok_Main = ok;
|
break;
|
case ServerType.CrossSever:
|
server0109Ok_CrossServer = ok;
|
break;
|
default:
|
break;
|
}
|
}
|
|
public void BroadcastStageLoadStartEvent(int mapId)
|
{
|
try
|
{
|
if (onStartStageLoadingEvent != null)
|
{
|
onStartStageLoadingEvent(mapId);
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
|
}
|
|
public void BroadcastStageLoadEndEvent()
|
{
|
try
|
{
|
if (onStageLoadFinish != null)
|
{
|
onStageLoadFinish();
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError(ex);
|
}
|
|
}
|
|
void Update()
|
{
|
if (!isLoading && commands.Count > 0)
|
{
|
currentCommand = commands.Dequeue();
|
currentCommand.fromMapId = mapIdRecord;
|
currentCommand.fromLineId = lineIdRecord;
|
ExcuteCommand(currentCommand);
|
}
|
|
if (isLoading)
|
{
|
if (Time.time - loadStartTime > 25f)
|
{
|
if (stageLoadProcessor != null)
|
{
|
DestroyImmediate(stageLoadProcessor.gameObject);
|
stageLoadProcessor = null;
|
}
|
|
currentCommand = null;
|
isLoading = false;
|
commands.Clear();
|
StageLoadTimeOutCatcher.ReportLoadingOverTime();
|
GameNetSystem.Instance.Reconnect();
|
}
|
}
|
}
|
|
public class StageLoadCommand
|
{
|
public int fromMapId;
|
public int fromLineId;
|
public int toMapId;
|
public int toLineId;
|
|
public bool needEmpty;
|
public ServerType serverType;
|
public bool isClientLoadMap;
|
public bool needLoadResource;
|
public bool refreshPlayerDatas;
|
public bool exitClientMap;
|
|
public bool serverFlag0109 = false;
|
}
|
|
public bool IsServerPrepareOk(ServerType socketType)
|
{
|
switch (socketType)
|
{
|
case ServerType.Main:
|
return server0109Ok_Main;
|
case ServerType.CrossSever:
|
return server0109Ok_CrossServer;
|
default:
|
return false;
|
}
|
}
|
|
int m_InitHeroStep = -1;
|
public int initHeroStep { get { return m_InitHeroStep; } }
|
|
public void InitHero()
|
{
|
m_InitHeroStep = 0;
|
|
// 初始化摄像机
|
if (!CameraController.Instance)
|
{
|
var prefab = UnityEngine.Object.Instantiate(BuiltInLoader.LoadPrefab("GameCamera"));
|
CameraController.Instance.SetcamerePrefab(prefab);
|
CameraController.Instance.AcceptInput = false;
|
CameraController.Instance.CameraObject.enabled = false;
|
}
|
|
m_InitHeroStep = 1;
|
var hero = PlayerDatas.Instance.hero;
|
if (hero == null)
|
{
|
hero = GAMgr.Instance.RequestPlayer<GA_Hero>(PlayerDatas.Instance.PlayerId, E_ActorGroup.User, null);
|
}
|
|
m_InitHeroStep = 2;
|
hero.State = E_ActorState.Idle;
|
hero.ActorInfo.ResetHp((long)PlayerDatas.Instance.baseData.HP, (long)PlayerDatas.Instance.extersion.MaxHP);
|
hero.CalculateMoveSpeed((ushort)PlayerDatas.Instance.extersion.SpeedValue);
|
hero.CalculateAtkSpeed(PlayerDatas.Instance.extersion.battleValEx1);
|
hero.InitBornPos(PlayerDatas.Instance.baseData.PosX, PlayerDatas.Instance.baseData.PosY);
|
m_InitHeroStep = 3;
|
CameraController.Instance.SetLookTarget(hero.Root);
|
CameraController.Instance.Apply();
|
|
var apperance = ModelCenter.Instance.GetModel<EquipModel>().GetAppearance();
|
|
m_InitHeroStep = 4;
|
if (apperance.fashionClothes != 0)
|
{
|
hero.SwitchClothes((uint)apperance.fashionClothes, (int)RoleEquipType.FashionClothes);
|
}
|
else
|
{
|
hero.SwitchClothes((uint)apperance.clothes);
|
}
|
|
m_InitHeroStep = 5;
|
if (apperance.fashionWeapon != 0)
|
{
|
hero.SwitchWeapon((uint)apperance.fashionWeapon, (int)RoleEquipType.FashionWeapon);
|
}
|
else
|
{
|
hero.SwitchWeapon((uint)apperance.weapon);
|
}
|
|
m_InitHeroStep = 6;
|
if (apperance.fashionSecondary != 0)
|
{
|
hero.SwitchSecondary((uint)apperance.fashionSecondary, (int)RoleEquipType.FashionWeapon2);
|
}
|
else
|
{
|
hero.SwitchSecondary((uint)apperance.secondary);
|
}
|
|
m_InitHeroStep = 7;
|
|
if (apperance.wings != 0)
|
{
|
hero.SwitchWing((uint)apperance.wings);
|
}
|
|
m_InitHeroStep = 8;
|
var mapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
|
if (mapConfig.CanRide != 1)
|
{
|
hero.SwitchHorse(0);
|
}
|
|
m_InitHeroStep = 9;
|
|
var pack = ModelCenter.Instance.GetModel<PackModel>();
|
var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(0, (int)RoleEquipType.Guard));
|
var _itemModel = pack.GetItemByIndex(PackType.Equip, equipIndex);
|
if (_itemModel != null && _itemModel.itemInfo != null)
|
{
|
hero.SwitchGuard((uint)_itemModel.itemId);
|
}
|
|
m_InitHeroStep = 10;
|
|
hero.SyncSuitEffect(apperance.isSuit);
|
|
m_InitHeroStep = 11;
|
hero.IdleImmediate();
|
|
hero.SetFairyLeagueHeadUp(PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON);
|
hero.CheckAncientHeadUp();
|
|
GA_Pet _pet = GAMgr.Instance.GetBySID(PlayerDatas.Instance.PlayerId * 10 + 1) as GA_Pet;
|
|
if (_pet != null)
|
{
|
Debug.LogFormat("主角已有宠物,这里卸载掉");
|
GAMgr.Instance.ServerDie(_pet.ServerInstID);
|
GAMgr.Instance.Release(_pet);
|
}
|
|
|
if (ModelCenter.Instance.GetModel<PetModel>().PetNow != 0 && mapConfig.CanOutPet == 1)
|
{
|
var _package = new H0435_tagPetAppear();
|
_package.PetID = PlayerDatas.Instance.PlayerId * 10 + 1;
|
_package.NPCID = (uint)ModelCenter.Instance.GetModel<PetModel>().PetNow;
|
_package.PlayerID = PlayerDatas.Instance.PlayerId;
|
_package.PosX = (uint)(hero.Pos.x * 2);
|
_package.PosX = (uint)(hero.Pos.z * 2);
|
|
_pet = GAMgr.Instance.RequestNPCFight<GA_Pet>(_package.PetID, _package.NPCID, hero.Group, _package);
|
hero.petSid = PlayerDatas.Instance.PlayerId * 10 + 1;
|
_pet.Pos = hero.Pos;
|
_pet.ActorInfo.moveSpeed = hero.ActorInfo.moveSpeed;
|
_pet.ActorInfo.ownerSID = hero.ServerInstID;
|
}
|
|
m_InitHeroStep = 12;
|
var titleId = 0;
|
if (PlayerDatas.Instance.baseData.MapID != 31160)
|
{
|
var titelModel = ModelCenter.Instance.GetModel<TitleModel>();
|
var title = titelModel.GetTitleEquip();
|
titleId = title != null && titelModel.IsTitleGain(title.id) ? title.id : 0;
|
}
|
hero.SwitchTitle((uint)titleId);
|
|
m_InitHeroStep = 13;
|
// 判断buff
|
if (StatusMgr.Instance.IsExist(PlayerDatas.Instance.PlayerId, StatusMgr.Instance.redNameBuffID))
|
{
|
hero.SwitchRedName(true);
|
}
|
|
hero.RequestLight();
|
|
m_InitHeroStep = 14;
|
PlayerDatas.Instance.hero = hero;
|
|
var preLoadSkillEffects = GeneralDefine.PreloadSkillEffect[hero.JobSetup.Job - 1];
|
if (preLoadSkillEffects != null && preLoadSkillEffects.Length > 0)
|
{
|
foreach (var _id in preLoadSkillEffects)
|
{
|
InstanceResourcesLoader.PreloadSkillEffect(_id);
|
}
|
}
|
|
m_InitHeroStep = 15;
|
}
|
|
}
|