49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
|
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)
|
|||
|
{
|
|||
|
Pet pet = args.unit.GetComponent<Pet>();
|
|||
|
if (args.isShow)
|
|||
|
{
|
|||
|
if (pet.petUnitId != 0)
|
|||
|
{
|
|||
|
UnitComponent.Instance.Remove(pet.petUnitId );
|
|||
|
}
|
|||
|
pet.petUnitId = Game.IdGenerater.GenerateId();
|
|||
|
Unit petUnit = await UnitFactory.CreatePet(args.scene, pet.petUnitId);
|
|||
|
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 = args.scene,
|
|||
|
jobType = 0,
|
|||
|
level = pet.level,
|
|||
|
name=pet.name,
|
|||
|
unit=petUnit
|
|||
|
}) ;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
long petUnitId = pet.petUnitId;
|
|||
|
pet.petUnitId = 0;
|
|||
|
UnitComponent.Instance.Remove(petUnitId);
|
|||
|
}
|
|||
|
|
|||
|
await ETTask.CompletedTask;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|