1
0
forked from cgvr/DeltaVR

shape scanner improvements: add handle, destroy scannable object on completion, correctly detect when new object is generated

This commit is contained in:
2026-01-27 18:38:20 +02:00
parent 77fc43bebd
commit af27bb0230
7 changed files with 299 additions and 30 deletions

View File

@@ -55,8 +55,12 @@ public class ShapeDetectionMinigameController : MonoBehaviour
GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel);
InitializeSpawnedObject(spawnedObject);
// Destroy previous generated object
Destroy(GeneratedModel);
if (GeneratedModel != null)
{
// Destroy previous generated object (first move out of ShapeScanner to trigger OnTriggerExit
GeneratedModel.transform.position = Vector3.zero;
//Destroy(GeneratedModel);
}
GeneratedModel = spawnedObject;
modelGenerationButton.Deactivate();

View File

@@ -42,6 +42,8 @@ public class ShapeScanner : MonoBehaviour
private int rayCount;
private int correctRayStates;
private GameObject currentlyScannableObject;
// Start is called before the first frame update
void Start()
@@ -60,6 +62,22 @@ public class ShapeScanner : MonoBehaviour
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == rayPrefab.scannableTag)
{
currentlyScannableObject = other.gameObject;
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == rayPrefab.scannableTag)
{
currentlyScannableObject = null;
}
}
private void InitializeConfiguration()
{
// Delete all existing rays first
@@ -67,6 +85,11 @@ public class ShapeScanner : MonoBehaviour
{
Destroy(ray);
}
if (currentlyScannableObject != null)
{
currentlyScannableObject.transform.position = Vector3.zero;
Destroy(currentlyScannableObject);
}
ShapeScannerConfiguration configuration = configurations[currentConfiguration];
int rayRowCount = configuration.rows.Count;
@@ -97,8 +120,6 @@ public class ShapeScanner : MonoBehaviour
rayCount = configuration.rows.SelectMany(row => row.cells).Count();
correctRayStates = configuration.rows.SelectMany(row => row.cells).Count(cell => !cell);
UpdateDisplay(calculateCorrectPercentage());
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
}
private float calculateCorrectPercentage()
@@ -117,9 +138,11 @@ public class ShapeScanner : MonoBehaviour
{
currentConfiguration++;
InitializeConfiguration();
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
} else
{
Debug.Log("Shape checker completed");
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
}
}
UpdateDisplay(correctPercentage);