CTT/Unity/Assets/Hotfix/Logic/Model/Game/Entity/Map/UnitySceneComponent.cs

113 lines
3.8 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using ET;
using Cal.DataTable;
using UnityEngine;
namespace ET
{
public class UnitySceneComponentAwakeSystem : AwakeSystem<UnitySceneComponent>
{
public override void Awake(UnitySceneComponent self)
{
self.Awake();
self.ZoneScene().AddComponent<MainStoryMonsterTeamComponent>();
self.ZoneScene().AddComponent<TrialCopyMonsterTeamComponent>();
self.AddComponent<BattleComponent>();
self.AddComponent<BossComponent>();
}
}
public class UnitySceneComponentDestroySystem : DestroySystem<UnitySceneComponent>
{
public override void Destroy(UnitySceneComponent self)
{
self.Destroy();
}
}
public class UnitySceneComponent : Entity
{
public static UnitySceneComponent Instance { get; private set; }
public void Awake()
{
Instance = this;
}
public void InitScenePoint(Scene zoneScene, int sceneId, int mapLayer)
{
Game.EventSystem.Publish(new ET.EventType.RemoveTransPoint
{
zoneScene = zoneScene
}).Coroutine();
SceneTransConfig sceneTransConfig = SceneTransConfigCategory.Instance.Get(sceneId);
Sys_Scene sysScene = DataTableHelper.Get<Sys_Scene>(sceneId);
if (sceneTransConfig.TransPosArr == null)
return;
if (sceneId != Sys_SceneId.Scene_MainCity)
{
//非主城情况
for (int i = 0; i < sceneTransConfig.TransPosArr.Length; i++)
{
SceneTransConfig.TransPos transPos = sceneTransConfig.TransPosArr[i];
Game.EventSystem.Publish(new ET.EventType.CreateTransPoint
{
zoneScene = zoneScene,
transIndex = i,
currSceneId = sceneId,
pos = new Vector2(transPos.TransPos_x, transPos.TransPos_y),
}).Coroutine();
}
}
else
{
for (int i = 0; i < sceneTransConfig.TransPosArr.Length; i++)
{
SceneTransConfig.TransPos transPos = sceneTransConfig.TransPosArr[i];
Game.EventSystem.Publish(new ET.EventType.CreateTransPoint
{
zoneScene = zoneScene,
transIndex = i,
currSceneId = sceneId,
pos = new Vector2(transPos.TransPos_x, transPos.TransPos_y),
}).Coroutine();
}
}
}
public async ETTask LoadSceneAsync(Scene zoneScene, int sceneId, Vector3 pos)
{
//关闭主线怪物
BossComponent.Instance.RemoveBoss();
Game.EventSystem.Publish(new ET.EventType.RemoveTransPoint
{
zoneScene = zoneScene
}).Coroutine();
Sys_Scene sysScene = DataTableHelper.Get<Sys_Scene>(sceneId);
var unitComponent = zoneScene.GetComponent<UnitComponent>();
zoneScene.GetComponent<UnitComponent>().MyUnit ??= (zoneScene.GetComponent<UnitComponent>().Get(zoneScene.GetComponent<GlobalVariable>().MyId));
zoneScene.GetComponent<UnitComponent>().MyUnit.Position = new Vector3(pos.x, pos.y, PosHelper.PlayerPos_Z);
zoneScene.GetComponent<UnitComponent>().MyUnit.YAngle = (int) pos.z;
await Game.EventSystem.Publish(new ET.EventType.LoadUnityScene
{
zoneScene = zoneScene,
name = sysScene.SceneName,
id = (int) sysScene.Id
});
}
public void Destroy()
{
}
}
}