-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPlayerSpawns.cs
More file actions
46 lines (39 loc) · 1.5 KB
/
PlayerSpawns.cs
File metadata and controls
46 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Meta Platforms, Inc. and affiliates.
// Use of the material below is subject to the terms of the MIT License
// https://github.com/oculus-samples/Unity-Decommissioned/tree/main/Assets/Decommissioned/LICENSE
using System.Linq;
using Meta.Decommissioned.Game;
using Meta.Decommissioned.Game.MiniGames;
using Meta.Decommissioned.Lobby;
using Meta.Utilities;
using Meta.XR.Samples;
using Unity.Netcode;
using UnityEngine;
namespace Meta.Decommissioned.Player
{
/// <summary>
/// Multiton that stores a player's current position, as well as their "Main Spawn", a position they can be returned
/// to from anywhere.
/// </summary>
[MetaCodeSample("Decommissioned")]
public class PlayerSpawns : Multiton<PlayerSpawns>
{
private int m_mainSpawnIndex = -1;
private GamePosition m_mainSpawn;
public bool EnableLogging;
public GamePosition MainSpawn => m_mainSpawn == null
? LocationManager.Instance?.GetGamePositionByIndex(MiniGameRoom.None, m_mainSpawnIndex)
: m_mainSpawn;
public static PlayerSpawns GetByPlayerObject(NetworkObject player) =>
Instances.FirstOrDefault(p => p.gameObject == player.gameObject);
public void SetMainSpawn(GamePosition position)
{
m_mainSpawn = position;
m_mainSpawnIndex = position.PositionIndex;
if (EnableLogging)
{
Debug.Log("Setting main spawn to " + m_mainSpawnIndex);
}
}
}
}