下拉列表ugi

 

 

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);
    }
}

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值