按住图片两秒,弹出保存框之类的实现(NGUI)

来源:互联网 发布:mac vim不保存退出 编辑:程序博客网 时间:2024/05/20 19:33

移动端可能会有这样的需求,类似IOS的保存图片 ,这里我就简单的写下实现的代码,可能还有有更好的实现思路,望告知。
先贴

using UnityEngine;using System.Collections;public class contorl : MonoBehaviour {    private bool m_isOpen = true;    // Use this for initialization    void Start () {        this.gameObject.AddComponent<UIEventListener>().onPress = OnStartTimeCount;    }    // Update is called once per frame    void Update () {    }    private void OnStartTimeCount(GameObject go,bool isPress)    {        m_isOpen = isPress;        StopAllCoroutines();        StartCoroutine("TimeGo");        Debug.Log("结束----------------" + isPress);    }    IEnumerator TimeGo()    {        yield return new WaitForSeconds(2);        if (m_isOpen)            Debug.Log("弹保存框");    }}

这里我是简单的实现功能,并灭有真的弹出框(这个是UI),
这里主要是利用 OnPress方法的第二个参数 , 当按下的时候这个参数是true,当抬起的时候会变为true,这样我们就可以利用携程来实现,两秒 和按下的两个条件全部符合,来触发弹框了

这里 我的代码是绑定在一个按钮上的de 给按钮动态的绑定,EventIistener

0 0
原创粉丝点击