在Unity上实现OnBeginDrag,OnDrag等回调

时间:2019-01-13 09:48:16

标签: android unity3d

我正在尝试使用简单的多维数据集对象在场景上实现摄像机控制器。

我在捕获android上的触摸事件时遇到问题。

最简单的方法是什么?

我已经尝试过https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html

这是我到目前为止所做的:

  • 在主相机上添加了光线投射器
  • 在多维数据集上添加了一个事件触发器
  • 将脚本应用于多维数据集

    EventTrigger trigger = GetComponent<EventTrigger>();
    EventTrigger.Entry entry = new EventTrigger.Entry();
    entry.eventID = EventTriggerType.Drag;
    entry.callback.AddListener((data) => {
       OnDragDelegate((PointerEventData)data); 
    });
    trigger.triggers.Add(entry);
    ...
    public void OnDragDelegate(PointerEventData data)
    

1 个答案:

答案 0 :(得分:1)

我认为最简单的方法是使用DragHandler接口:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">LoGo</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Capabilities</a>
        <div class="dropdown">
          <div class="dropdown-content">
            <div class="row">
              <div class="col-lg-4">
                <h3 class="ml-3">Products</h3>
                <p class="ml-3"><a class="commerce" href="#">Dr.Commerce</a></p>
              </div>
              <div class="col-lg-8 services">
                <h3>Capabilities</h3>
                <ul class="list-inline">
                  <li class="list-inline-item">
                    <img src="./images/twitter-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>

                </ul>
              </div>
            </div>
          </div>
        </div>
      </li>
    </ul>
  </div>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

通过这种方式,它不仅可以在Android中运行,而且还可以在Unity Editor中对其进行测试。