• 大小: 30KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 其他
  • 标签: Win7  TouchInput  Unity  NGUI  

资源简介

这是一个完整的例子项目,里面含有NGUI3.8.2和TouchScript6.7及如何匹配这两个插件的代码。Unity的版本是UnitySetup64-5.1.0f3。绝对是汗水的成果。

资源截图

代码片段和文件信息

using UnityEngine;
using System.Collections;
using Touchscript;
using Touchscript.Gestures;

public class TouchscriptNGUI : MonoBehaviour
{

    UICamera uiCamera;

    void Start()
    {
        uiCamera = Gameobject.FindobjectOfType(typeof(UICamera)) as UICamera;

        // Disable standard NGUI inputs
        uiCamera.useMouse = false;
        uiCamera.useTouch = false;

        TouchManager.Instance.TouchesBegan += TouchManagerBegan;
        TouchManager.Instance.TouchesMoved += TouchManagerMoved;
        TouchManager.Instance.TouchesEnded += TouchManagerEnded;
        TouchManager.Instance.TouchesCancelled += TouchManagerCancelled;
    }

    private void TouchManagerBegan(object sender TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender eventArgs TouchPhase.Began);
    }
    private void TouchManagerMoved(object sender TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender eventArgs TouchPhase.Moved);
    }
    private void TouchManagerEnded(object sender TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender eventArgs TouchPhase.Ended);
    }
    private void TouchManagerCancelled(object sender TouchEventArgs eventArgs)
    {
        TouchManagerChanged(sender eventArgs TouchPhase.Canceled);
    }
    private void TouchManagerChanged(object sender TouchEventArgs eventArgs TouchPhase touchPhase)
    {
        Touchscript.TouchManager gesture = sender as Touchscript.TouchManager;

        foreach (Touchscript.ITouch touchPoint in eventArgs.Touches)
        {
            UICamera.currentTouchID = uiCamera.allowMultiTouch ? touchPoint.Id : 1;
            UICamera.currentTouch = UICamera.GetTouch(UICamera.currentTouchID);

            bool pressed = (touchPhase == TouchPhase.Began) || UICamera.currentTouch.touchBegan;
            bool unpressed = (touchPhase == TouchPhase.Canceled) || (touchPhase == TouchPhase.Ended);
            UICamera.currentTouch.touchBegan = false;

            if (pressed)
            {
                UICamera.currentTouch.delta = Vector2.zero;
            }
            else
            {
                UICamera.currentTouch.delta = touchPoint.PreviousPosition - touchPoint.Position;
            }

            UICamera.currentTouch.pos = touchPoint.Position;
            UICamera.hoveredobject = UICamera.Raycast(UICamera.currentTouch.pos) ? UICamera.lastHit.collider.gameobject : UICamera.fallThrough;
            if (UICamera.hoveredobject == null) UICamera.hoveredobject = UICamera.genericEventHandler;
            UICamera.currentTouch.current = UICamera.hoveredobject;
            UICamera.lastTouchPosition = UICamera.currentTouch.pos;

            // We don‘t want to update the last camera while there is a touch happening
            if (pressed) UICamera.currentTouch.pressedCam = UICamera.currentCamera;
            else if (UICamera.currentTouch.pressed != null) UICamera.currentCamera = UICamera.currentTouch.pressedCam;

            // Double-tap support
            

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-10-07 06:51  TouchscriptNGUI-master\
     文件         162  2014-10-07 06:51  TouchscriptNGUI-master\.gitignore
     目录           0  2014-10-07 06:51  TouchscriptNGUI-master\Assets\
     文件         107  2014-10-07 06:51  TouchscriptNGUI-master\Assets\NGUI.meta
     文件         107  2014-10-07 06:51  TouchscriptNGUI-master\Assets\Touchscript.meta
     文件         107  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI.meta
     目录           0  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\
     文件       18080  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\Control - Simple Button.prefab
     文件          95  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\Control - Simple Button.prefab.meta
     文件        3496  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\TouchscriptNGUI.cs
     文件         178  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\TouchscriptNGUI.cs.meta
     文件       45956  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\TouchscriptNGUI.unity
     文件          90  2014-10-07 06:51  TouchscriptNGUI-master\Assets\TouchscriptNGUI\TouchscriptNGUI.unity.meta
     目录           0  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\
     文件        4125  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\AudioManager.asset
     文件        4280  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\DynamicsManager.asset
     文件        4764  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\EditorBuildSettings.asset
     文件        4184  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\EditorSettings.asset
     文件        4112  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\GraphicsSettings.asset
     文件        5252  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\InputManager.asset
     文件        9100  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\NavMeshlayers.asset
     文件        4112  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\NetworkManager.asset
     文件        4300  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\Physics2DSettings.asset
     文件       27544  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\ProjectSettings.asset
     文件        4852  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\QualitySettings.asset
     文件        5676  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\TagManager.asset
     文件        4112  2014-10-07 06:51  TouchscriptNGUI-master\ProjectSettings\TimeManager.asset
     文件         202  2014-10-07 06:51  TouchscriptNGUI-master\README.md
     文件         674  2015-07-28 11:02  说明.txt

评论

共有 条评论