CTT/Unity/Assets/HotfixView/Event/SwitchPetDisplayEvent.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2021-04-11 19:50:39 +08:00
using Cal.DataTable;
using ET.EventType;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace ET
{
public class SwitchPetDisplayEvent : AEvent<SwitchPetDisplay>
{
public override async ETTask Run(SwitchPetDisplay args)
{
var zoneScene = args.zoneScene;
2021-04-11 19:50:39 +08:00
Pet pet = args.unit.GetComponent<Pet>();
if (args.isShow)
{
if (pet.petUnitId != 0)
{
zoneScene.GetComponent<UnitComponent>().Remove(pet.petUnitId );
2021-04-11 19:50:39 +08:00
}
pet.petUnitId = Game.IdGenerater.GenerateId();
Unit petUnit = await UnitFactory.CreatePet(zoneScene, pet.petUnitId);
2021-04-11 19:50:39 +08:00
PetConfig petConfig = PetConfigCategory.Instance.Get(pet.petId);
if (petConfig == null) return;
Transform go = await ResourceViewHelper.LoadPrefabAsync(petConfig.PrefabId);
petUnit.AddComponent<UnitView, GameObject>(go.gameObject);
petUnit.Position = args.unit.Position;
HudComponent.Instance.Init(petUnit);
Game.EventSystem.Publish_Sync(new ET.EventType.SetHudCharacter
{
zoneScene = zoneScene,
2021-04-11 19:50:39 +08:00
jobType = 0,
level = pet.level,
name=pet.name,
unit=petUnit
}) ;
}
else
{
long petUnitId = pet.petUnitId;
pet.petUnitId = 0;
zoneScene.GetComponent<UnitComponent>().Remove(petUnitId);
2021-04-11 19:50:39 +08:00
}
await ETTask.CompletedTask;
}
}
}