Tanoda
AssignUsersHelper.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class AssignUsersHelper : MonoBehaviour
8{
9 public GameObject userPrefab;
10 public GameObject ScrollViewContent;
11
12 void Start()
13 {
14 StartCoroutine(NetworkManager.instance.GetAllUserWOAdmin((users) =>
15 {
16 foreach (var wsUser in users.users)
17 {
18 var newgo = Instantiate(userPrefab, userPrefab.transform.parent);
19 newgo.transform.GetChild(1).GetComponent<Text>().text = wsUser.name;
20 newgo.transform.GetChild(2).GetComponent<Text>().text = wsUser.id.ToString();
21 newgo.SetActive(true);
22 }
23 }));
24 }
25
26 public void ApplyChanges()
27 {
28 var courseId = NetworkManager.instance.selectedLevel.id;
29 var UserIds = new List<int>();
30 for (int i = 1; i < ScrollViewContent.transform.childCount - 1; i++)
31 {
32 var child = ScrollViewContent.transform.GetChild(i);
33 if (child.transform.GetChild(0).GetComponent<Toggle>().isOn)
34 {
35 UserIds.Add(Convert.ToInt32(child.transform.GetChild(2).GetComponent<Text>()));
36 }
37 }
38
39 StartCoroutine(NetworkManager.instance.AddUsersToCourse(UserIds.ToArray(), courseId, () =>
40 {
41 Debug.Log("AddUsersToCourse: Applied!");
42 }));
43
44 }
45
46
47}
GameObject ScrollViewContent