unity3d手机滑动效果
2012-05-01 21:36
836 查看
using UnityEngine; using System.Collections; public class TestUI : MonoBehaviour { public Vector2 scrollPosition = Vector2.zero;
public float scrollVelocity = 0f; public float timeTouchPhaseEnded = 0f; public float inertiaDuration = 0.5f; public Vector2 lastDeltaPos; // Use this for initialization void Start () {} void OnGUI(){ scrollPosition = GUI.BeginScrollView(new Rect(100, 40, 600, 400), scrollPosition, new Rect(0, 0, 500, 1600), false, true); for (int i = 0; i < 32; i++){ if(GUI.Button(new Rect(0, i*50, 400, 50), "Button"+i)){} } GUI.EndScrollView(); } // Update is called once per frame void Update () { if (Input.touchCount > 0) { if (Input.GetTouch(0).phase == TouchPhase.Moved) { scrollPosition.y += Input.GetTouch(0).deltaPosition.y; lastDeltaPos = Input.GetTouch(0).deltaPosition; } else if (Input.GetTouch(0).phase == TouchPhase.Ended) { print ("End:"+lastDeltaPos.y+"|"+Input.GetTouch(0).deltaTime); if (Mathf.Abs(lastDeltaPos.y)> 20.0f) { scrollVelocity = (int)(lastDeltaPos.y * 0.5/ Input.GetTouch(0).deltaTime); print(scrollVelocity); } timeTouchPhaseEnded = Time.time; } } else { if (scrollVelocity != 0.0f) { // slow down float t = (Time.time - timeTouchPhaseEnded)/inertiaDuration; float frameVelocity = Mathf.Lerp(scrollVelocity, 0, t); scrollPosition.y += frameVelocity * Time.deltaTime; if (t >= inertiaDuration) scrollVelocity = 0; } } } }
相关文章推荐
- unity3d手机滑动效果
- flipsnap实现手机屏幕左右拖拽滑动效果的框架
- h5用swiper结合angularjs实现手机浏览器左右滑动切换图片的效果
- 移动端网页JS框架-手机触摸事件框架,日历框架带滑动效果
- 实现手机滑动翻页效果
- 手机页面内容超出屏幕宽度时实现可拖拉滑动效果
- WEB网页 , webkit 内核手机,slider 上下滑动弹性切换效果(不采用任何插件)
- Axure 实现手机滑动效果
- CAGradientLayer(颜色渐变) -- 实现iphone手机屏幕“滑动来解锁”动画效果
- Unity3D制作触屏手机滑动动效果
- Android 高仿华为手机Tab页滑动导航效果
- 【翻译】Unity3D车辆的滑动效果
- 手机浏览器中横向循环滑动效果
- 【请教问题】kanzi如何实现类似安卓手机桌面滑动切换界面效果?
- 手机浏览器中横向循环滑动效果
- 手机网站开发:滑动翻屏效果 jquery触摸屏滑动效果
- Axure制作手机UI原型之界面滑动滚动效果
- h5手机浏览器左右滑动切换图片效果
- 让tab导航在手机移动端有平滑滑动的效果
- iscroll4 捕捉元素开发手机焦点图滑动效果