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)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<UnitComponent>().Remove(pet.petUnitId );
|
2021-04-11 19:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
pet.petUnitId = Game.IdGenerater.GenerateId();
|
2021-04-20 00:25:04 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
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;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<UnitComponent>().Remove(petUnitId);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|