using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class RealmBriefBehaviour : MonoBehaviour
|
{
|
[SerializeField] Image m_Icon;
|
[SerializeField] PropertyBehaviour m_ClonePropertyBeha;
|
[SerializeField] Transform m_PropertyRoot;
|
[SerializeField] List<PropertyBehaviour> m_Properties;
|
[SerializeField] Transform m_ContainerUnlockEquip;
|
[SerializeField] Image m_UnlockEquip;
|
[SerializeField] Button m_Preview;
|
|
int realmLevel = 0;
|
|
RealmModel model { get { return ModelCenter.Instance.GetModel<RealmModel>(); } }
|
|
private void Awake()
|
{
|
m_Preview.AddListener(OnEquipPreview);
|
}
|
|
public void Display(int realmLevel)
|
{
|
this.realmLevel = realmLevel;
|
CreatePropertyBehaviour();
|
DisplayBase();
|
DisplayProperty();
|
DisplayEquip();
|
}
|
|
void DisplayBase()
|
{
|
var config = RealmConfig.Get(realmLevel);
|
m_Icon.SetSprite(config.Img);
|
}
|
|
void DisplayProperty()
|
{
|
var index = 0;
|
Dictionary<int, int> propertyDict;
|
if (model.TryGetRealmProperty(realmLevel, out propertyDict))
|
{
|
var keys = propertyDict.Keys;
|
foreach (var property in keys)
|
{
|
m_Properties[index].gameObject.SetActive(true);
|
m_Properties[index].Display(property, propertyDict[property]);
|
index++;
|
}
|
}
|
for (int i = index; i < m_Properties.Count; i++)
|
{
|
m_Properties[i].gameObject.SetActive(false);
|
}
|
}
|
|
void DisplayEquip()
|
{
|
var level = 0;
|
if (model.IsUnlockEquipRealm(realmLevel, out level))
|
{
|
m_ContainerUnlockEquip.gameObject.SetActive(true);
|
var config = RealmConfig.Get(realmLevel);
|
m_UnlockEquip.SetSprite(config.equipNameIcon);
|
}
|
else
|
{
|
m_ContainerUnlockEquip.gameObject.SetActive(false);
|
}
|
}
|
|
void CreatePropertyBehaviour()
|
{
|
Dictionary<int, int> propertyDict;
|
var requireBehaCount = 0;
|
if (model.TryGetRealmProperty(realmLevel, out propertyDict))
|
{
|
requireBehaCount = propertyDict.Count;
|
}
|
if (requireBehaCount > m_Properties.Count)
|
{
|
var start = m_Properties.Count;
|
for (int i = start; i < requireBehaCount; i++)
|
{
|
var clone = GameObject.Instantiate<PropertyBehaviour>(m_ClonePropertyBeha, Vector3.zero, Quaternion.identity);
|
clone.transform.SetParent(m_PropertyRoot);
|
clone.transform.localScale = Vector3.one;
|
clone.gameObject.SetActive(false);
|
m_Properties.Add(clone);
|
}
|
}
|
}
|
|
private void OnEquipPreview()
|
{
|
RealmEquipPreviewWin.selectRealmLevel = realmLevel;
|
WindowCenter.Instance.Open<RealmEquipPreviewWin>();
|
}
|
}
|
}
|