Clear not used
This commit is contained in:
parent
abc255c1de
commit
dd487e5738
5 changed files with 0 additions and 416 deletions
|
@ -1,160 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Unity.AI.Navigation;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.AI;
|
|
||||||
using UnityEngine.XR.ARFoundation;
|
|
||||||
|
|
||||||
public class NewIndoorNavOld : MonoBehaviour {
|
|
||||||
[SerializeField] private Transform player;
|
|
||||||
[SerializeField] private ARTrackedImageManager m_TrackedImageManager;
|
|
||||||
[SerializeField] private GameObject trackedImagePrefab;
|
|
||||||
[SerializeField] private LineRenderer line;
|
|
||||||
|
|
||||||
private List<NavigationTarget> navigationTargets = new List<NavigationTarget>();
|
|
||||||
private NavMeshSurface navMeshSurface;
|
|
||||||
private NavMeshPath navMeshPath;
|
|
||||||
|
|
||||||
private GameObject navigationBase;
|
|
||||||
|
|
||||||
private string currentImageName = "rear";
|
|
||||||
public int targetNumber = 0;
|
|
||||||
|
|
||||||
private void Start() {
|
|
||||||
navMeshPath = new NavMeshPath();
|
|
||||||
|
|
||||||
// disable screen dimming
|
|
||||||
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update() {
|
|
||||||
if (navigationBase != null && navigationTargets.Count > 0 && navMeshSurface != null) {
|
|
||||||
// Check if there are any tracked images
|
|
||||||
if (m_TrackedImageManager.trackables.count > 0) {
|
|
||||||
// Use a foreach loop to get the first tracked image
|
|
||||||
foreach (var trackedImage in m_TrackedImageManager.trackables) {
|
|
||||||
// currentImageName = trackedImage.referenceImage.name; // Get the name of the tracked image
|
|
||||||
Debug.Log(currentImageName);
|
|
||||||
|
|
||||||
// Determine which navigation target to use based on the tracked image
|
|
||||||
Transform targetTransform = null;
|
|
||||||
|
|
||||||
// if (currentImageName == "QR_testARtracking") {
|
|
||||||
// targetTransform = navigationTargets[0].transform;
|
|
||||||
// } else if (currentImageName == "default") {
|
|
||||||
// targetTransform = navigationTargets[1].transform;
|
|
||||||
// }
|
|
||||||
targetTransform = navigationTargets[targetNumber].transform;
|
|
||||||
|
|
||||||
// If a valid target is found, calculate the path
|
|
||||||
if (targetTransform != null) {
|
|
||||||
NavMesh.CalculatePath(player.position, targetTransform.position, NavMesh.AllAreas, navMeshPath);
|
|
||||||
// Debug.Log($"-----------------------------");
|
|
||||||
// Debug.Log($"NavMesh.CalculatePath debug");
|
|
||||||
// Debug.Log($"targetTransform.position : {targetTransform.position}");
|
|
||||||
// Debug.Log($"NavMesh.AllAreas : {NavMesh.AllAreas}");
|
|
||||||
// Debug.Log($"navMeshPath : {navMeshPath}");
|
|
||||||
// Debug.Log($"-----------------------------");
|
|
||||||
if (navMeshPath.status == NavMeshPathStatus.PathComplete) {
|
|
||||||
line.positionCount = navMeshPath.corners.Length;
|
|
||||||
line.SetPositions(navMeshPath.corners);
|
|
||||||
// Debug.Log($"YAY !!!!!!!!!!!!!!");
|
|
||||||
} else {
|
|
||||||
line.positionCount = 0;
|
|
||||||
}
|
|
||||||
// Debug.Log($"Player Position: {player.position}, Target Position: {targetTransform.position}, Path Status: {navMeshPath.status}");
|
|
||||||
// Debug.Log($"Path Corners Count: {navMeshPath.corners.Length}");
|
|
||||||
// Debug.Log($"Name Pic : {currentImageName}");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// If no valid target is found, clear the line
|
|
||||||
line.positionCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Break after processing the first tracked image
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If no tracked images are available, clear the line
|
|
||||||
line.positionCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void OnEnable() => m_TrackedImageManager.trackablesChanged.AddListener(OnChanged);
|
|
||||||
|
|
||||||
private void OnDisable() => m_TrackedImageManager.trackablesChanged.RemoveListener(OnChanged);
|
|
||||||
|
|
||||||
private void OnChanged(ARTrackablesChangedEventArgs<ARTrackedImage> eventArgs) {
|
|
||||||
foreach (var newImage in eventArgs.added) {
|
|
||||||
navigationBase = GameObject.Instantiate(trackedImagePrefab);
|
|
||||||
navigationTargets.Clear();
|
|
||||||
|
|
||||||
navigationTargets = navigationBase.transform.GetComponentsInChildren<NavigationTarget>().ToList();
|
|
||||||
navMeshSurface = navigationBase.transform.GetComponentInChildren<NavMeshSurface>();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var updatedImage in eventArgs.updated) {
|
|
||||||
// Check if navigationBase is null to avoid null reference exceptions
|
|
||||||
if (navigationBase == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the current position of navigationBase
|
|
||||||
Vector3 currentPosition = navigationBase.transform.position;
|
|
||||||
|
|
||||||
// Debug.Log(currentImageName);
|
|
||||||
|
|
||||||
// Calculate the new position based on the updated image's position
|
|
||||||
Vector3 newPosition = currentPosition;
|
|
||||||
if (currentImageName == "front") {
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(-1.22f, -1f, 13f);
|
|
||||||
} else if (currentImageName == "frontright") {
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(-8.65f, -1f, 6.25f);
|
|
||||||
} else if (currentImageName == "rearright") {
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(18f, -1f, 6.25f);
|
|
||||||
} else if (currentImageName == "frontleft") {
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(9.65f, -1f, 7.28f);
|
|
||||||
} else if (currentImageName == "rearleft") {
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(-17f, -1f, 7.28f);
|
|
||||||
} else if (currentImageName == "rear") {
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(0.78f, -1f, 19.62f);
|
|
||||||
}
|
|
||||||
// Vector3 newPosition = updatedImage.pose.position + new Vector3(-1.22f, -1f, 13f); // invert
|
|
||||||
|
|
||||||
// Check if the new position is significantly different from the current position
|
|
||||||
if (Vector3.Distance(currentPosition, newPosition) > 0.1f) { // Adjust the threshold as needed
|
|
||||||
if (currentImageName == "front") {
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, -updatedImage.pose.rotation.eulerAngles.x, 0));
|
|
||||||
} else if (currentImageName == "frontright" || currentImageName == "rearright") {
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, 90+updatedImage.pose.rotation.eulerAngles.x, 0));
|
|
||||||
} else if (currentImageName == "frontleft" || currentImageName == "rearleft") {
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, 270+updatedImage.pose.rotation.eulerAngles.x, 0));
|
|
||||||
} else if (currentImageName == "rear") {
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, updatedImage.pose.rotation.eulerAngles.x, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var removedImage in eventArgs.removed) {
|
|
||||||
// Handle removed images if necessary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleDropdown(int val){
|
|
||||||
targetNumber = val-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DestroyNavigationBase()
|
|
||||||
{
|
|
||||||
if (navigationBase != null)
|
|
||||||
{
|
|
||||||
Debug.Log("Destroying!!");
|
|
||||||
Destroy(navigationBase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 3899037cd98be5152b76e6c510a0b7e7
|
|
|
@ -1,212 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Unity.AI.Navigation;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.AI;
|
|
||||||
using UnityEngine.XR.ARFoundation;
|
|
||||||
using UnityEngine.XR.ARSubsystems;
|
|
||||||
|
|
||||||
public class NewIndoorNavWorking : MonoBehaviour
|
|
||||||
{
|
|
||||||
[SerializeField] private Transform player;
|
|
||||||
[SerializeField] private ARTrackedImageManager m_TrackedImageManager;
|
|
||||||
[SerializeField] private GameObject trackedImagePrefab;
|
|
||||||
[SerializeField] private LineRenderer line;
|
|
||||||
|
|
||||||
private List<NavigationTarget> navigationTargets = new List<NavigationTarget>();
|
|
||||||
private NavMeshSurface navMeshSurface;
|
|
||||||
private NavMeshPath navMeshPath;
|
|
||||||
|
|
||||||
private GameObject navigationBase;
|
|
||||||
private ARTrackedImage currentTrackedImage;
|
|
||||||
|
|
||||||
private string currentImageName = "front";
|
|
||||||
public static int targetNumber = StoreDataScript.targetNumber;
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
navMeshPath = new NavMeshPath();
|
|
||||||
|
|
||||||
// disable screen dimming
|
|
||||||
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
if (navigationBase != null && navigationTargets.Count > 0 && navMeshSurface != null)
|
|
||||||
{
|
|
||||||
// Check if there are any tracked images
|
|
||||||
if (m_TrackedImageManager.trackables.count > 0)
|
|
||||||
{
|
|
||||||
// Use a foreach loop to get the first tracked image
|
|
||||||
foreach (var trackedImage in m_TrackedImageManager.trackables)
|
|
||||||
{
|
|
||||||
currentImageName = trackedImage.referenceImage.name; // Get the name of the tracked image
|
|
||||||
Debug.Log(currentImageName);
|
|
||||||
|
|
||||||
// Determine which navigation target to use based on the tracked image
|
|
||||||
Transform targetTransform = null;
|
|
||||||
|
|
||||||
targetTransform = navigationTargets[targetNumber].transform;
|
|
||||||
|
|
||||||
// If a valid target is found, calculate the path
|
|
||||||
if (targetTransform != null)
|
|
||||||
{
|
|
||||||
NavMesh.CalculatePath(player.position, targetTransform.position, NavMesh.AllAreas, navMeshPath);
|
|
||||||
if (navMeshPath.status == NavMeshPathStatus.PathComplete)
|
|
||||||
{
|
|
||||||
line.positionCount = navMeshPath.corners.Length;
|
|
||||||
line.SetPositions(navMeshPath.corners);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
line.positionCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If no valid target is found, clear the line
|
|
||||||
line.positionCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Break after processing the first tracked image
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If no tracked images are available, clear the line
|
|
||||||
line.positionCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnEnable() => m_TrackedImageManager.trackablesChanged.AddListener(OnChanged);
|
|
||||||
|
|
||||||
private void OnDisable() => m_TrackedImageManager.trackablesChanged.RemoveListener(OnChanged);
|
|
||||||
|
|
||||||
private void OnChanged(ARTrackablesChangedEventArgs<ARTrackedImage> eventArgs)
|
|
||||||
{
|
|
||||||
Debug.Log("OnChanged event triggered.");
|
|
||||||
Debug.Log(targetNumber);
|
|
||||||
|
|
||||||
// Handle added images
|
|
||||||
foreach (var newImage in eventArgs.added)
|
|
||||||
{
|
|
||||||
string newImageName = newImage.referenceImage.name; // Get the name of the new image
|
|
||||||
Debug.Log($"New Image Added: {newImageName}");
|
|
||||||
|
|
||||||
// Stop using the previous image
|
|
||||||
if (currentTrackedImage != null && currentTrackedImage != newImage)
|
|
||||||
{
|
|
||||||
Debug.Log($"Stopping use of previous image: {currentTrackedImage.referenceImage.name}");
|
|
||||||
// Destroy any associated game objects here
|
|
||||||
if (navigationBase != null)
|
|
||||||
{
|
|
||||||
Destroy(navigationBase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the new image as the current tracked image
|
|
||||||
currentTrackedImage = newImage;
|
|
||||||
currentImageName = newImageName;
|
|
||||||
|
|
||||||
// Instantiate a new navigationBase
|
|
||||||
navigationBase = GameObject.Instantiate(trackedImagePrefab);
|
|
||||||
navigationTargets = navigationBase.transform.GetComponentsInChildren<NavigationTarget>().ToList();
|
|
||||||
navMeshSurface = navigationBase.transform.GetComponentInChildren<NavMeshSurface>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle updated images
|
|
||||||
foreach (var updatedImage in eventArgs.updated)
|
|
||||||
{
|
|
||||||
if (navigationBase == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentImageName = updatedImage.referenceImage.name; // Update currentImageName
|
|
||||||
Debug.Log($"Image Updated: {currentImageName}");
|
|
||||||
|
|
||||||
// Get the current position of navigationBase
|
|
||||||
Vector3 currentPosition = navigationBase.transform.position;
|
|
||||||
|
|
||||||
// Calculate the new position based on the updated image's position
|
|
||||||
Vector3 newPosition = currentPosition;
|
|
||||||
if (currentImageName == "front")
|
|
||||||
{
|
|
||||||
newPosition = updatedImage.transform.position + new Vector3(-1.22f, -1f, 13f);
|
|
||||||
}
|
|
||||||
else if (currentImageName == "frontright")
|
|
||||||
{
|
|
||||||
newPosition = updatedImage.transform.position + new Vector3(-8.65f, -1f, 6.25f);
|
|
||||||
}
|
|
||||||
else if (currentImageName == "rearright")
|
|
||||||
{
|
|
||||||
newPosition = updatedImage.transform.position + new Vector3(18f, -1f, 6.25f);
|
|
||||||
}
|
|
||||||
else if (currentImageName == "frontleft")
|
|
||||||
{
|
|
||||||
newPosition = updatedImage.transform.position + new Vector3(9.65f, -1f, 7.28f);
|
|
||||||
}
|
|
||||||
else if (currentImageName == "rearleft")
|
|
||||||
{
|
|
||||||
newPosition = updatedImage.transform.position + new Vector3(-17f, -1f, 7.28f);
|
|
||||||
}
|
|
||||||
else if (currentImageName == "rear")
|
|
||||||
{
|
|
||||||
newPosition = updatedImage.pose.position + new Vector3(0.78f, -1f, 19.62f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the new position is significantly different from the current position
|
|
||||||
if (Vector3.Distance(currentPosition, newPosition) > 0.1f)
|
|
||||||
{
|
|
||||||
if (currentImageName == "front")
|
|
||||||
{
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, -updatedImage.transform.rotation.eulerAngles.x, 0));
|
|
||||||
}
|
|
||||||
else if (currentImageName == "frontright" || currentImageName == "rearright")
|
|
||||||
{
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, 90 + updatedImage.transform.rotation.eulerAngles.x, 0));
|
|
||||||
}
|
|
||||||
else if (currentImageName == "frontleft" || currentImageName == "rearleft")
|
|
||||||
{
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, 270 + updatedImage.transform.rotation.eulerAngles.x, 0));
|
|
||||||
}
|
|
||||||
else if (currentImageName == "rear")
|
|
||||||
{
|
|
||||||
navigationBase.transform.SetPositionAndRotation(newPosition, Quaternion.Euler(0, updatedImage.pose.rotation.eulerAngles.x, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle removed images if necessary
|
|
||||||
foreach (var removedImage in eventArgs.removed)
|
|
||||||
{
|
|
||||||
Debug.Log($"Image Removed: {removedImage.Value.referenceImage.name}");
|
|
||||||
if (removedImage.Value == currentTrackedImage)
|
|
||||||
{
|
|
||||||
currentTrackedImage = null;
|
|
||||||
currentImageName = "";
|
|
||||||
if (navigationBase != null)
|
|
||||||
{
|
|
||||||
Destroy(navigationBase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleDropdown(int val)
|
|
||||||
{
|
|
||||||
targetNumber = val - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DestroyNavigationBase()
|
|
||||||
{
|
|
||||||
if (navigationBase != null)
|
|
||||||
{
|
|
||||||
Debug.Log("Destroying!!");
|
|
||||||
Destroy(navigationBase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 858d4f870663e952483e9571c969c273
|
|
|
@ -17,46 +17,6 @@ MonoBehaviour:
|
||||||
m_DataStore:
|
m_DataStore:
|
||||||
m_Storage: []
|
m_Storage: []
|
||||||
m_Images:
|
m_Images:
|
||||||
- m_SerializedGuid:
|
|
||||||
m_GuidLow: 5107411274837290523
|
|
||||||
m_GuidHigh: 16336371371156619928
|
|
||||||
m_SerializedTextureGuid:
|
|
||||||
m_GuidLow: 12690622759437445919
|
|
||||||
m_GuidHigh: 6149444014037946985
|
|
||||||
m_Size: {x: 0.1, y: 0.1}
|
|
||||||
m_SpecifySize: 1
|
|
||||||
m_Name: QR_testARtracking
|
|
||||||
m_Texture: {fileID: 0}
|
|
||||||
- m_SerializedGuid:
|
|
||||||
m_GuidLow: 5355688179872852416
|
|
||||||
m_GuidHigh: 5327492942649116594
|
|
||||||
m_SerializedTextureGuid:
|
|
||||||
m_GuidLow: 4083294291408057616
|
|
||||||
m_GuidHigh: 623175960350000761
|
|
||||||
m_Size: {x: 0.1, y: 0.10011124}
|
|
||||||
m_SpecifySize: 1
|
|
||||||
m_Name: default
|
|
||||||
m_Texture: {fileID: 0}
|
|
||||||
- m_SerializedGuid:
|
|
||||||
m_GuidLow: 5578027413733091453
|
|
||||||
m_GuidHigh: 16203960149354137472
|
|
||||||
m_SerializedTextureGuid:
|
|
||||||
m_GuidLow: 11537399107731278249
|
|
||||||
m_GuidHigh: 1319041143359005225
|
|
||||||
m_Size: {x: 0.1, y: 0.1}
|
|
||||||
m_SpecifySize: 1
|
|
||||||
m_Name: QR_test2
|
|
||||||
m_Texture: {fileID: 0}
|
|
||||||
- m_SerializedGuid:
|
|
||||||
m_GuidLow: 5029125541180419855
|
|
||||||
m_GuidHigh: 9893423347044715410
|
|
||||||
m_SerializedTextureGuid:
|
|
||||||
m_GuidLow: 8618102446949219809
|
|
||||||
m_GuidHigh: 11179150519332190090
|
|
||||||
m_Size: {x: 0.1, y: 0.1}
|
|
||||||
m_SpecifySize: 1
|
|
||||||
m_Name: QR_test3
|
|
||||||
m_Texture: {fileID: 0}
|
|
||||||
- m_SerializedGuid:
|
- m_SerializedGuid:
|
||||||
m_GuidLow: 4884491046015554393
|
m_GuidLow: 4884491046015554393
|
||||||
m_GuidHigh: 9877233385657296003
|
m_GuidHigh: 9877233385657296003
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue