Exemple #1
0
    void Start()
    {
        Button[] buttons = new Button[] { buttonA, buttonB, buttonC, buttonD };

        for (int i = 0; i < buttons.Length; i++)
        {
            var    curButton  = buttons[i];
            var    index      = i;
            Action readAction = () =>
            {
                curButton.transform.Find("Mark").gameObject.SetActive(prefabSelected[index]);
            };
            curButton.onClick.AddListener(() => {
                prefabSelected[index] = !prefabSelected[index];
                readAction();
            });
            readAction();
        }

        buttonAdd.onClick.AddListener(() =>
        {
            foreach (var aName in GetSelectedPrefabNames())
            {
                for (int i = 0; i < GetInputFieldCount(); i++)
                {
                    scrollSystem.Add(aName, new SimpleData {
                        index = global_index++
                    });
                }
            }
        });

        buttonCheck.onClick.AddListener(() =>
        {
            Debug.Log(scrollSystem.GetCount(GetSelectedPrefabNames().ToArray()));
        });

        buttonCheckExcept.onClick.AddListener(() =>
        {
            Debug.Log(scrollSystem.GetCountExcept(GetSelectedPrefabNames().ToArray()));
        });

        buttonAddChat.onClick.AddListener(AddChat);
        buttonAddChatJump.onClick.AddListener(AddChatJump);

        buttonDeleteAll.onClick.AddListener(DeleteAll);
        buttonCreateDeleteAndAdd.onClick.AddListener(DeleteAndAdd);
        buttonJumpWithoutAnimation.onClick.AddListener(() =>
        {
            scrollSystem.Jump(1, false);
        });
        buttonReverse.onClick.AddListener(() =>
        {
            scrollSystem.Reverse();
        });

        scrollSystem.SetItemInitDelegate((prefabName, root) =>
        {
            switch (prefabName)
            {
            case "B":
                root.GetComponent <ItemB>().Init(scrollSystem);
                break;

            case "C":
                root.GetComponent <ItemC>().Init(scrollSystem);
                break;
            }
        });

        scrollSystem.SetItemContentDelegate((prefabName, root, data) =>
        {
            switch (prefabName)
            {
            case "A":
                {
                    root.GetComponent <ItemA>().UpdateInfo(data as SimpleData);
                }
                break;

            case "B":
                {
                    root.GetComponent <ItemB>().UpdateInfo(data as SimpleData);
                }
                break;

            case "C":
                {
                    root.GetComponent <ItemC>().UpdateInfo(data as SimpleData);
                }
                break;

            case "D":
                {
                    root.GetComponent <ItemD>().UpdateInfo(data as SimpleData);
                }
                break;

            case "Chat":
                {
                    root.GetComponent <ItemChat>().UpdateInfo(data as ChatData);
                }
                break;
            }
        });
    }