using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class Chu_fang : MonoBehaviour
{
[Header("运动类别")]
public Button[] _arr_button;
private float number;
//scroll 生长Content
public GameObject content;
//取反bool
private bool min_zu;
private bool you_yang;
private bool la_shen;
private bool kang_zu;
private bool pen_di;
private float number1;
private float number2;
private float number3;
private float number4;
private float number5;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < _arr_button.Length; i++)
{
int temp=i;
_arr_button[temp].onClick.AddListener(delegate () { Yun_dongleibie(_arr_button[temp].transform); });
}
}
// Update is called once per frame
void Update()
{
}
void Yun_dongleibie(Transform tran)
{
switch (tran.name)
{
case "民族传统教育":
if (min_zu == false)
{
//背景
tran.GetChild(1).gameObject.SetActive(true);
//要增加的 Y值
number1 += tran.GetChild(1).GetChild(1).childCount * 50;
//下方列表
for (int i = 1; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y - number1, 0.1f);
}
}
else
{
tran.GetChild(1).gameObject.SetActive(false);
//向上移动
for (int i = 1; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y +number1, 0.1f);
}
//Content 变化
number1 -= tran.GetChild(1).GetChild(1).childCount * 50;
}
min_zu = !min_zu;
break;
case "有氧运动":
if (you_yang == false)
{
tran.GetChild(1).gameObject.SetActive(true);
number2 += tran.GetChild(1).GetChild(1).childCount * 50;
for (int i = 2; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y - number2, 0.1f);
}
}
else
{
tran.GetChild(1).gameObject.SetActive(false);
for (int i = 2; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y + number2, 0.1f);
}
number2 -= tran.GetChild(1).GetChild(1).childCount * 50;
}
you_yang = !you_yang;
break;
case "拉伸运动":
if (la_shen == false)
{
tran.GetChild(1).gameObject.SetActive(true);
number3 += tran.GetChild(1).GetChild(1).childCount * 50;
for (int i = 3; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y - number3, 0.1f);
}
}
else
{
tran.GetChild(1).gameObject.SetActive(false);
for (int i = 3; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y + number3, 0.1f);
}
number3 -= tran.GetChild(1).GetChild(1).childCount * 50;
}
la_shen = !la_shen;
break;
case "抗阻运动":
if (kang_zu == false)
{
tran.GetChild(1).gameObject.SetActive(true);
number4 += tran.GetChild(1).GetChild(1).childCount * 50;
for (int i = 4; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y - number4, 0.1f);
}
}
else
{
tran.GetChild(1).gameObject.SetActive(false);
for (int i = 4; i < _arr_button.Length; i++)
{
_arr_button[i].transform.DOLocalMoveY(_arr_button[i].transform.localPosition.y + number4, 0.1f);
}
number4 -= tran.GetChild(1).GetChild(1).childCount * 50;
}
kang_zu = !kang_zu;
break;
case "盆底肌收缩":
if (pen_di == false)
{
tran.GetChild(1).gameObject.SetActive(true);
number5 += tran.GetChild(1).GetChild(1).childCount * 50;
}
else
{
tran.GetChild(1).gameObject.SetActive(false);
number5 -= tran.GetChild(1).GetChild(1).childCount * 50;
}
pen_di = !pen_di;
break;
default:
break;
}
//content 内容汇总 300为初始 content height
content.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 300 + number1 + number2 + number3 + number4 + number5);
}
}