Exemplo n.º 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;
            }
        });
    }
Exemplo n.º 2
0
	private void BindEvent()
	{
		Button[] buttons = new Button[] { buttonA, buttonB, buttonC, buttonD, buttonE };
		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, GenerateSimpleData());
				}
			}
		});
		buttonCheck.onClick.AddListener(() => { Debug.Log(scrollSystem.GetDataCount(GetSelectedPrefabNames().ToArray())); });
		buttonCheckExcept.onClick.AddListener(() => { Debug.Log(scrollSystem.GetDataCountExcept(GetSelectedPrefabNames().ToArray())); });
		buttonAddChat.onClick.AddListener(() =>
		{
			AddChat(inputField_ChatContent.text);
		});

		buttonAddChatJump.onClick.AddListener(() =>
		{
			AddChat(inputField_ChatContent.text);
			scrollSystem.Jump(1);
		});
		buttonDeleteAll.onClick.AddListener(() =>
		{
			createdDatas.Clear();
			scrollSystem.Clear();
		});
		buttonCreateDeleteAndAdd.onClick.AddListener(() =>
		{
			createdDatas.Clear();
			scrollSystem.Clear();
			foreach (var simpleData in deleteAndAddDatas)
			{
				createdDatas.Add(simpleData);
				scrollSystem.Add("D", simpleData);
			}
		});
		buttonJumpWithoutAnimation.onClick.AddListener(() => { scrollSystem.Jump(1, false); });
		buttonReverse.onClick.AddListener(() => { createdDatas.Reverse(); scrollSystem.Reverse(); });
		buttonRemoveFirst.onClick.AddListener(() =>
			{
				if (createdDatas.Count > 0)
				{
					var removedData = createdDatas[0];
					createdDatas.Remove(removedData);
					scrollSystem.Remove(removedData);
				}
			}
		);
		buttonRemoveLast.onClick.AddListener(() =>
			{
				if (createdDatas.Count > 0)
				{
					var removedData = createdDatas[createdDatas.Count - 1];
					createdDatas.Remove(removedData);
					scrollSystem.Remove(removedData);
				}
			}
		);
		ButtonRefresh.onClick.AddListener(() => { scrollSystem.Refresh(); });
		ButtonChangeData.onClick.AddListener(() => { createdDatas.ForEach(temp => { temp.index++; Debug.Log("added to index:" + temp.index); }); });
		buttonJumpData.onClick.AddListener(() =>
		{
			if (int.TryParse(inputField_JumpDataIndex.text, out int result))
			{
				scrollSystem.Jump(result, true);
			}
		});
		buttonLastOne.onClick.AddListener(() =>
		{
			if (int.TryParse(inputField_JumpDataIndex.text, out int result))
			{
				if (result > 0)
				{
					result--;
					inputField_JumpDataIndex.text = result.ToString();
					scrollSystem.Jump(result, true);
				}
			}
		});
		buttonNextOne.onClick.AddListener(() =>
		{
			if (int.TryParse(inputField_JumpDataIndex.text, out int result))
			{
				if (result + 1 < scrollSystem.GetDataCount())
				{
					result++;
					inputField_JumpDataIndex.text = result.ToString();
					scrollSystem.Jump(result, true);
				}
			}
		});
		sliderJumpProgress.onValueChanged.AddListener(progress =>
		{
			textJumpProgress.text = progress.ToString("0.00");
			scrollSystem.Jump(progress);
		});
		buttonJumpBegin.onClick.AddListener(() =>
		{
			scrollSystem.Jump(0, !Input.GetKey(KeyCode.S));
		});
		buttonJumpEnd.onClick.AddListener(() =>
		{
			scrollSystem.Jump(1, !Input.GetKey(KeyCode.S));
		});
		ButtonIsFirstVisible.onClick.AddListener(() =>
		{
			Debug.Log("IsFirstVIsible:"+ scrollSystem.IsFirstVisible().ToString());
		});
		ButtonIsLastVisible.onClick.AddListener(() =>
		{
			Debug.Log("IsLastVIsible:" + scrollSystem.IsLastVisible().ToString());
		});
		ButtonEnableMovement.onClick.AddListener(()=> {
			scrollSystem.EnableMovement();
		});
		ButtonDisableMovement.onClick.AddListener(() => {
			scrollSystem.DisableMovement();
		});
	}