微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Unity3d自动隐藏顶部工具栏

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

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<RectTransform>();
    }
	
	// 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;
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐