HoloLens 2 Gait Training
The purpose of this project is to create gait training application.
Loading...
Searching...
No Matches
AvatarSpawner.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.AI;
3using Microsoft.MixedReality.Toolkit.UI;
4
8public class AvatarSpawner : MonoBehaviour
9{
10
12 [SerializeField] private ScrollingObjectCollection m_Scrollview;
13
15 [SerializeField] private GameObject[] m_AvatarPrefabs;
16
18 private int m_AvatarIndex = -1;
19
21 private const int m_NumberOfAvatars = 7;
22
24 private GameObject m_LastAvatar;
25
29 private void Update()
30 {
32 }
33
37 private void SetVisibleCellIndex()
38 {
39 m_AvatarIndex = m_Scrollview.FirstVisibleCellIndex;
40
41 // Prevent accessing out of bound cell number
43 {
44 m_AvatarIndex -= 1;
45 }
46 }
47
51 public void SpawnAvatar()
52 {
53
54 int index = m_AvatarIndex;
55
56 if (index < 0 || index >= m_AvatarPrefabs.Length)
57 {
58 Debug.LogError($"Can't instantiate prefab, unable to find specified index '{index}'.");
59 return;
60 }
61
62 var prefab = m_AvatarPrefabs[index];
63
64 if (!prefab)
65 {
66 Debug.LogError("Can't load avatar prefab.");
67 return;
68 }
69
70 if (m_LastAvatar)
71 {
72 Destroy(m_LastAvatar);
73 }
74
75 var position = Camera.main.transform.position + Camera.main.transform.forward * 3 + new Vector3(0, -0.6f, 0);
76 m_LastAvatar = Instantiate(prefab, position, Quaternion.identity);
77 }
78}
This script is responsible for spawning the avatar in the scene.
Definition: AvatarSpawner.cs:9
GameObject m_LastAvatar
Last avatar.
const int m_NumberOfAvatars
Defines the number of avatars.
int m_AvatarIndex
Avatar index value.
void SpawnAvatar()
Spawn the avatar corresponding to the specified index.
void SetVisibleCellIndex()
Set the current cell index belong to the avatar.
ScrollingObjectCollection m_Scrollview
Reference to the scrollview
GameObject[] m_AvatarPrefabs
Reference to the avatar prefabs.
void Update()
Gets called per each frame