少年修仙传客户端代码仓库
hch
2024-12-16 9377811d0ba27047e1e5ec2348a28eba1033d59d
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class TipExchangesWidget : MonoBehaviour
    {
        [SerializeField] Text m_Title;
        [SerializeField] ScrollRect m_Scroller;
        [SerializeField] Button m_Goto;
 
        int jumpId = 0;
 
        string windowName;
        List<TipExchangeItemBehaviour> items = new List<TipExchangeItemBehaviour>();
 
        private void Awake()
        {
            m_Goto.AddListener(OnGoto);
        }
 
        public void Display(int itemId)
        {
            var config = ItemExchangeConfig.Get(itemId);
            m_Title.text = config.title;
            jumpId = config.jump;
            CreateItemBehaviour(config.items.Length);
            for (var i = 0; i < items.Count; i++)
            {
                var behaviour = items[i];
                if (i < config.items.Length)
                {
                    var id = config.items[i];
                    behaviour.SetActive(true);
                    behaviour.Display(id);
                    behaviour.SetListener(()=> 
                    {
                        if (!string.IsNullOrEmpty(windowName))
                        {
                            WindowCenter.Instance.CloseImmediately(windowName);
                        }
                    });
                }
                else
                {
                    behaviour.SetActive(false);
                }
            }
 
            m_Scroller.verticalNormalizedPosition = 1f;
            m_Scroller.AddMissingComponent<RayAccepter>();
        }
 
        public void Bind(string windowName)
        {
            this.windowName = windowName;
        }
 
        private void OnGoto()
        {
            if (!string.IsNullOrEmpty(windowName))
            {
                WindowCenter.Instance.Close(windowName);
                WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)jumpId);
            }
        }
 
        private void CreateItemBehaviour(int count)
        {
            var nowCount = items.Count;
            var need = count - nowCount;
            for (var i = 0; i < need; i++)
            {
                var instance = UIUtility.CreateWidget("TipExchangeItem", "TipExchangeItem");
 
                instance.transform.SetParentEx(m_Scroller.content, Vector3.zero, Quaternion.identity, Vector3.one);
                var item = instance.GetComponent<TipExchangeItemBehaviour>();
                items.Add(item);
            }
        }
    }
}