您当前的位置: 首页 >  unity

程序员正茂

暂无认证

  • 4浏览

    0关注

    283博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity3d自动隐藏顶部工具栏

程序员正茂 发布时间:2019-09-23 20:44:40 ,浏览量:4

将以下脚本挂载到工具栏面板上即可。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(RectTransform))]
public class AutoHideToolbar : MonoBehaviour {

    bool isShow = true;
    private RectTransform rectTr;
	// Use this for initialization
	void Start () {
        rectTr = GetComponent();
    }
	
	// Update is called once per frame
	void Update () {
        if (Input.mousePosition.y > Screen.height - rectTr.sizeDelta.y)
        {
            if (isShow == false)
            {
                StartCoroutine(ShowToolBar(true));
                isShow = true;
            }
        }
        else
        {
            if (isShow == true)
            {
                
                StartCoroutine(ShowToolBar(false));
                isShow = false;
            }
        }
    }

    IEnumerator ShowToolBar(bool show)
    {
        int count = 20;
        float step = rectTr.sizeDelta.y / (float)count;
        step = isShow ? step : -step;

        for (int i = 0; i < count; i++)
        {
            rectTr.anchoredPosition = new Vector2(rectTr.anchoredPosition.x, rectTr.anchoredPosition.y+ step);
            yield return null;
        }
    }
}

关注
打赏
1660743125
查看更多评论
立即登录/注册

微信扫码登录

0.0366s