少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-08 aa62264ce70008889d090d7402298e7850350708
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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>();
        }
    }
}