阻塞觸摸我們正在建立類似的一個例子「小貓 - 配售的AR虛擬對象」,如下所示:探戈/團結 - UI在屏幕上不
https://developers.google.com/tango/apis/unity/unity-howto-placing-objects。
基本上當你觸摸屏幕時,一隻小貓出現在現實世界的飛機(地板)上。
在我們的應用程序中,我們有一個側面菜單,有幾個按鈕,每個都顯示不同的遊戲對象。除了有UI的地方,我們希望檢測屏幕上的任何位置。我們希望UI在Tango中阻止觸摸,並且只允許在沒有UI元素的情況下在屏幕區域實例化相關遊戲對象。
觸摸特定代碼是在這裏:
void Update() {
if (Input.touchCount == 1) {
// Trigger placepictureframe function when single touch ended.
Touch t = Input.GetTouch(0);
if (t.phase == TouchPhase.Ended) {
PlacePictureFrame(t.position);
}
}
}
(該PlacePictureFrame()
地方在觸摸位置的圖像幀的對象。)
我不能找到具有觸摸和UI結合的任何探戈例子。我已經嘗試過一種名爲LeanTouch的資產來阻止UI元素背後的觸動,但它似乎並不適用於Tango。請幫忙!
我已經採用的方法5試圖從該:
How to detect events on UI and GameObjects with the new EventSystem API
,雖然它確實增加一個PhysicsRaycaster
到TangoARCamera
(其被標記爲MainCamera
),則OnPointerDown
方法沒有產生調試日誌無論在哪裏你觸摸屏幕。探戈是一個特例,所以這不是一個重複的問題。請看下圖:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class PictureFrameUIController : MonoBehaviour, IPointerClickHandler {
public GameObject m_pictureFrame;
private TangoPointCloud m_pointCloud;
void Start() {
m_pointCloud = FindObjectOfType<TangoPointCloud>();
addPhysicsRaycaster();
}
void addPhysicsRaycaster() {
PhysicsRaycaster physicsRaycaster = GameObject.FindObjectOfType<PhysicsRaycaster>();
if (physicsRaycaster == null) {
Camera.main.gameObject.AddComponent<PhysicsRaycaster>();
}
}
public void OnPointerClick(PointerEventData eventData) {
Debug.Log("Clicked: " + eventData.pointerCurrentRaycast.gameObject.name);
PlacePictureFrame(eventData.pointerCurrentRaycast.screenPosition);
}
//void Update() {
// if (Input.touchCount == 1) {
// // Trigger placepictureframe function when single touch ended.
// Touch t = Input.GetTouch(0);
// if (t.phase == TouchPhase.Ended) {
// PlacePictureFrame(t.position);
// }
// }
//}
void PlacePictureFrame(Vector2 touchPosition) {
// Find the plane.
Camera cam = Camera.main;
Vector3 planeCenter;
Plane plane;
if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane)) {
Debug.Log("cannot find plane.");
return;
}
// Place picture frame on the surface, and make it always face the camera.
if (Vector3.Angle(plane.normal, Vector3.up) > 60.0f && Vector3.Angle(plane.normal, Vector3.up) < 140.0f) {
Vector3 forward = plane.normal;
// Vector3 right = Vector3.Cross(plane.normal, cam.transform.forward).normalized;
// Vector3 forward = Vector3.Cross(right, plane.normal).normalized;
Instantiate(m_pictureFrame, planeCenter, Quaternion.LookRotation(forward, Vector3.up));
} else {
Debug.Log("surface is not steep enough for picture frame to be placed on.");
}
}
public void DeleteAllFrames() {
GameObject[] frames = GameObject.FindGameObjectsWithTag("Frame");
if (frames == null) {
return;
}
foreach (GameObject frame in frames) {
Destroy(frame);
}
}
}
這是重複的。如果該解決方案確實不適用於您,那麼您應該在該解決方案中嘗試瞭解您的問題。請使用該解決方案嘗試更新您的問題。也包括課程。 – Programmer
我做到了。沒有答案,因爲你已經標記爲重複。您的解決方案與Tango無關。 – fiixed
同樣,你應該用那個「沒用」的代碼更新你的問題。您從*方法5 *嘗試的代碼。該代碼應附加到您檢測點擊的GameObject上。你必須展示該代碼,以便人們可以幫助你。 – Programmer