40 lines
1.2 KiB
Plaintext
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;
|
||
|
}
|
||
|
}
|
||
|
}
|