forked from cgvr/DeltaVR
on shape scanner completion, door is unlocked, shape scanner initializes empty config, quest marker moves to npc
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -10,6 +11,11 @@ using UnityEngine.XR.Interaction.Toolkit;
|
||||
public class BoolRow
|
||||
{
|
||||
public List<bool> cells = new();
|
||||
|
||||
public BoolRow(List<bool> cells)
|
||||
{
|
||||
this.cells = cells;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -18,11 +24,21 @@ public class ShapeScannerConfiguration
|
||||
public int columns = 6;
|
||||
public float requiredCorrectPercentage = 80.0f;
|
||||
public List<BoolRow> rows = new();
|
||||
public ShapeScannerConfiguration(int columns, float requiredCorrectPercentage, List<BoolRow> rows)
|
||||
{
|
||||
this.columns = columns;
|
||||
this.requiredCorrectPercentage = requiredCorrectPercentage;
|
||||
this.rows = rows;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ShapeScanner : MonoBehaviour
|
||||
{
|
||||
public delegate void OnShapeScannerCompletedDelegate();
|
||||
public event OnShapeScannerCompletedDelegate OnShapeScannerCompleted;
|
||||
|
||||
[Header("Static References")]
|
||||
public List<ShapeScannerConfiguration> configurations = new List<ShapeScannerConfiguration>();
|
||||
public ShapeScannerRay rayPrefab;
|
||||
public Transform raySpawnCorner1;
|
||||
@@ -32,17 +48,28 @@ public class ShapeScanner : MonoBehaviour
|
||||
public TextMeshProUGUI correctPercentageDisplay;
|
||||
public XRInteractionManager interactionManager;
|
||||
|
||||
[Header("Materials")]
|
||||
public Material requiredAndActive;
|
||||
public Material requiredAndPassive;
|
||||
public Material notRequiredAndActive;
|
||||
public Material notRequiredAndPassive;
|
||||
|
||||
[Header("On Completion")]
|
||||
public LineRenderer lineRenderer;
|
||||
public Transform lineStart;
|
||||
public Transform lineEnd;
|
||||
public MeshRenderer activatableRenderer;
|
||||
public Material activatableActiveMaterial;
|
||||
public HingeJoint doorJoint;
|
||||
public Collider doorInvisibleWall;
|
||||
|
||||
private List<ShapeScannerRay> existingRays;
|
||||
private float raySpawnDistanceX;
|
||||
private float raySpawnDistanceZ;
|
||||
private int currentConfiguration;
|
||||
private int rayCount;
|
||||
private int correctRayStates;
|
||||
private bool isCompleted;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -52,27 +79,31 @@ public class ShapeScanner : MonoBehaviour
|
||||
raySpawnDistanceX = raySpawnCorner2.localPosition.x - raySpawnCorner1.localPosition.x;
|
||||
raySpawnDistanceZ = raySpawnCorner2.localPosition.z - raySpawnCorner1.localPosition.z;
|
||||
|
||||
lineRenderer.enabled = false;
|
||||
isCompleted = false;
|
||||
currentConfiguration = 0;
|
||||
InitializeConfiguration();
|
||||
InitializeConfiguration(configurations[0]);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (lineRenderer.enabled)
|
||||
{
|
||||
lineRenderer.SetPosition(0, lineStart.position);
|
||||
lineRenderer.SetPosition(1, lineEnd.position);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeConfiguration()
|
||||
private void InitializeConfiguration(ShapeScannerConfiguration configuration)
|
||||
{
|
||||
// Delete all colliding objects and then all existing rays
|
||||
DestroyCollidingObjects();
|
||||
// Recreate all existing rays
|
||||
foreach (ShapeScannerRay ray in existingRays)
|
||||
{
|
||||
Destroy(ray.gameObject);
|
||||
}
|
||||
existingRays.Clear();
|
||||
|
||||
ShapeScannerConfiguration configuration = configurations[currentConfiguration];
|
||||
int rayRowCount = configuration.rows.Count;
|
||||
for (int i = 0; i < rayRowCount; i++)
|
||||
{
|
||||
@@ -137,21 +168,31 @@ public class ShapeScanner : MonoBehaviour
|
||||
{
|
||||
correctRayStates++;
|
||||
float correctPercentage = calculateCorrectPercentage();
|
||||
UpdateDisplay(correctPercentage);
|
||||
if (isCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (correctPercentage >= configurations[currentConfiguration].requiredCorrectPercentage)
|
||||
{
|
||||
UpdateCurrentConfigurationDisplay(currentConfiguration + 1);
|
||||
if (currentConfiguration + 1 < configurations.Count)
|
||||
{
|
||||
currentConfiguration++;
|
||||
InitializeConfiguration();
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
|
||||
DestroyCollidingObjects();
|
||||
currentConfiguration++;
|
||||
InitializeConfiguration(configurations[currentConfiguration]);
|
||||
} else
|
||||
{
|
||||
Debug.Log("Shape checker completed");
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
|
||||
DestroyCollidingObjects();
|
||||
// Initialize configuration with all rays requiring collision
|
||||
List<BoolRow> rows = Enumerable.Repeat(new BoolRow(Enumerable.Repeat(false, 6).ToList()), 6).ToList();
|
||||
ShapeScannerConfiguration configuration = new ShapeScannerConfiguration(6, 100, rows);
|
||||
InitializeConfiguration(configuration);
|
||||
OnCompleteAll();
|
||||
}
|
||||
}
|
||||
UpdateDisplay(correctPercentage);
|
||||
}
|
||||
|
||||
public void DecrementCorrectRayCount()
|
||||
@@ -169,4 +210,26 @@ public class ShapeScanner : MonoBehaviour
|
||||
{
|
||||
currentConfigurationDisplay.text = confNumber.ToString() + " / " + configurations.Count;
|
||||
}
|
||||
|
||||
private void OnCompleteAll()
|
||||
{
|
||||
isCompleted = true;
|
||||
|
||||
// Change card reader color to green
|
||||
activatableRenderer.material = activatableActiveMaterial;
|
||||
|
||||
// Enable door to be opened
|
||||
JointLimits doorJointLimits = doorJoint.limits;
|
||||
doorJointLimits.min = -90f;
|
||||
doorJointLimits.max = 90f;
|
||||
doorJoint.limits = doorJointLimits;
|
||||
|
||||
// Disable invisible wall
|
||||
doorInvisibleWall.enabled = false;
|
||||
|
||||
// Create line renderer from shape scanner to door card reader
|
||||
lineRenderer.enabled = true;
|
||||
|
||||
OnShapeScannerCompleted?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user