WXMC/.svn/pristine/58/58929d2c9aa41b1457ca418e78179f9b6fd1b2d9.svn-base
2024-12-04 16:18:46 +08:00

40 lines
1.2 KiB
Plaintext

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PHomePetsUIDisplayer : MonoBehaviour
{
private Dictionary<PHomePet, PHomePetUIDisplayer> m_pets = new Dictionary<PHomePet, PHomePetUIDisplayer>();
[SerializeField]
private GameObject m_petPrefab;
public IEnumerable<PHomePet> Pets
{
set
{
Dictionary<PHomePet, PHomePetUIDisplayer> newPets = new Dictionary<PHomePet, PHomePetUIDisplayer>();
foreach (var item in value)
{
PHomePetUIDisplayer outPet;
if (m_pets.TryGetValue(item, out outPet))
{
newPets[item] = outPet;
m_pets.Remove(item);
}
else
{
var script = Instantiate(m_petPrefab, transform).GetComponent<PHomePetUIDisplayer>();
newPets[item] = script;
script.Pet = item;
}
}
foreach (var item in m_pets)
{
Destroy(item.Value.gameObject);
}
m_pets = newPets;
}
}
}