Unity--触摸ScrollView

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : 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++)
        {
            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;
            }
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue-Unity-WebGL 是一个具有极高可扩展性和灵活性的 Unity3D web 端开发框架,它将 Vue.js 与 Unity Web Player 和 WebGL 等技术相结合,为开发者提供了最佳的解决方案。 Vue-Unity-WebGL 框架具有很高的兼容性和易用性,开发者可以更加灵活地应用该框架来定制自己的项目。由于该框架具备了许多优秀的特性,如自适应布局、多平台支持等,使得开发者可以轻松地实现用户体验和开发效率的提升。此外,Vue-Unity-WebGL 框架不仅提供了可视化开发工具,还提供了完整的运行环境,为开发者提供了优秀的开发体验。 Vue-Unity-WebGL 框架的另一个重要特点是其大量的插件与扩展功能,这些插件和扩展可以为项目的开发和管理提供坚强的技术支持。比如,通过 vue-router 可以控制路由,Vue-Unity-WebGL 可以协作处理组件数据和 Unity3D 渲染等复杂的操作,而 Vuex 则可以使开发者方便地处理应用数据流和组件状态的管理。这些插件和扩展功能极大地提高了 Vue-Unity-WebGL 框架的可扩展性和灵活性,使得开发者可以更加容易地进行定制。 综上所述,Vue-Unity-WebGL 框架是一个快速、可靠且强大的解决方案,这使得开发者能够轻松地编写出高质量的 Unity3D web 应用程序。该框架具有大量的功能,实现可扩展性、灵活性、易用性和可维护性,比其他框架更具有竞争力。在未来的发展中,Vue-Unity-WebGL 框架将会被更多的开发者喜爱和应用,并在技术社区中拥有更广泛的影响力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值