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图片滑动效果,Unity3D图片滑动插件
实现一个功能,鼠标向右滑动时响应下一页事件,鼠标向左滑动时响应上一页事件
unity3d手机游戏开发.pdf
unity3d分屏效果,通过3d立体投影仪可以转换为3d立体效果。有3d电影的效果
Unity3D手指滑动屏幕更改相机视角,相机跟随代码。安卓端的相机跟随代码。
unity3d手机开发Android Keycode 最新对照表 本人测试可用!
unity3d手机游戏开发(金玺曾),PDF共392页,完整版本,非试读版本。分卷是csdn限制,每个分卷1个积分,一共需要2个积分。
Unity 3D手机游戏开发 金玺曾.pdf,扫描版很清晰,适合游戏开发者参考。
unity3d判断鼠标左右滑动,响应不同事件
【unity3d】滑块滑动翻页插件3合一(UGUI SuperScroll/PageView/Fscroll),根据需求来选择适合的,基本涵盖了市面上所有滑动的需求了。
Unity源码工程 和 安卓源码,全套完整代码 + 资源 + 详情文本图文操作教程。 包含功能:Unity3d读取手机相册、unity打开手机相机、保存图片等功能。
在Unity3D中模拟Android系统左右划屏切换页面的效果
Unity3d C# 实现滑动条(Slider)的拖拽开始和结束、点击等事件的拓展功能 说明:
Unity3D 手机游戏开发 2D U3D 手机游戏开发 详细,易懂
Unity、3D、特效、刀光、卡通、RPG、VFX、战斗、战斗光影、Unity3D、动作特效、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、...
Unity 3D手机游戏开发( 金玺曾) 介绍了使用Unity3D开发手机游戏的方法
unity3d手机游戏开发 金玺曾 不错的开发教程。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Unity 3D手机游戏开发 金玺曾 经典教材下载地址 超好
Unity3D教程:创建滑动GUI1