text
stringlengths 0
1.11k
|
|---|
{
|
m_originalWallMaterials ??= wall.Renderer.sharedMaterials;
|
wall.Renderer.sharedMaterials = m_altWallMaterials;
|
}
|
else
|
{
|
wall.Renderer.sharedMaterials = m_originalWallMaterials;
|
}
|
}
|
}
|
By using SceneElementsManager.Instance.GetElementsByLabel(OVRSceneManager.Classification.WallFace), it gets elements by label (Wallface) and then swaps on that wall.
|
Note: CEILING is a string and not an enum. This is because it’s part of the Scene API, which is frequently updated. Having that as a string helps with backwards compatibility.
|
A similar flow is followed for the ceiling swap:
|
private async void SwapCeiling(bool toAlt)
|
{
|
await UniTask.WaitUntil(() => SceneElementsManager.Instance.AreAllElementsSpawned());
|
var ceiling = SceneElementsManager.Instance.
|
GetElementsByLabel(OVRSceneManager.Classification.Ceiling).
|
FirstOrDefault()?.
|
Renderer;
|
if (ceiling == null)
|
return;
|
var block = new MaterialPropertyBlock();
|
block.SetFloat(s_visibility, toAlt ? 0 : 1);
|
ceiling.SetPropertyBlock(block);
|
}
|
Enemies spawn
|
In the Spawner class, as defined in /Assets/Discover/DroneRage/Scripts/Enemies/Spawner.cs, enemies are initially spawned outside the room, behind the wall. To do that, there is a need to first figure out the extent of the wall.
|
This is how the room extent is calculated:
|
private void CalculateRoomExtents()
|
{
|
var anchors = SceneElementsManager.Instance.GetElementsByLabel(OVRSceneManager.Classification.WallFace).ToList();
|
if (anchors.Any())
|
{
|
m_roomMinExtent = anchors[0].transform.position;
|
m_roomMaxExtent = anchors[0].transform.position;
|
m_roomSize = Vector3.zero;
|
}
|
foreach (var anchor in anchors)
|
{
|
var anchorTransform = anchor.transform;
|
var position = anchorTransform.position;
|
var scale = anchorTransform.lossyScale;
|
var right = anchorTransform.right * scale.x * 0.5f;
|
var up = anchorTransform.up * scale.y * 0.5f;
|
var wallPoints = new Vector3[]
|
{
|
position - right - up,
|
position - right + up,
|
position + right - up,
|
position + right + up,
|
};
|
foreach (var wp in wallPoints)
|
{
|
Debug.Log($"wall point {wp}");
|
m_roomMinExtent = Vector3.Min(m_roomMinExtent, wp);
|
m_roomMaxExtent = Vector3.Max(m_roomMaxExtent, wp);
|
m_roomSize.y = Mathf.Max(m_roomSize.y, transform.lossyScale.y);
|
}
|
}
|
m_roomSize = m_roomMaxExtent - m_roomMinExtent;
|
Debug.Log("Room Size: " + m_roomSize + " Room Min Extents: " + m_roomMinExtent + " Room Max Extents: " + m_roomMaxExtent);
|
}
|
The first gets the list of all wall faces with the following line:
|
var anchors = SceneElementsManager.Instance.GetElementsByLabel(OVRSceneManager.Classification.WallFace).ToList();
|
Then, it creates a min and max extent.
|
m_roomMinExtent = Vector3.Min(m_roomMinExtent, wp);
|
m_roomMaxExtent = Vector3.Max(m_roomMaxExtent, wp);
|
This essentially gets a bounding box that represents the room and stores that. The following logic finds a point that is outside that bounding box which represents the user’s real-life room.
|
public Vector3 GetClosestSpawnPoint(Vector3 position)
|
{
|
var spawnOffset = position - 0.5f * (m_roomMinExtent + m_roomMaxExtent);
|
spawnOffset.y = 0f;
|
spawnOffset = spawnOffset.normalized;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.