This repository was archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcomeController.cs
More file actions
52 lines (37 loc) · 1.48 KB
/
Copy pathWelcomeController.cs
File metadata and controls
52 lines (37 loc) · 1.48 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
47
48
49
50
51
52
using Mirror;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace AWelcomes
{
public class WelcomeController : MonoBehaviour
{
public IEnumerable<Message> Messages { get; internal set; }
private Stack<Message> _messageStack;
private float _nextCycle = 0f;
private Message _curMessage;
private Broadcast _broadcast;
private NetworkConnection _connection;
private void Start()
{
WelcomesMod.Instance.Info($"InitWC");
_nextCycle = Time.time;
_messageStack = new Stack<Message>(Messages.Reverse());
WelcomesMod.Instance.Info($"{_messageStack.Count}");
_broadcast = GetComponent<Broadcast>();
_connection = ReferenceHub.GetHub(gameObject).playerStats.connectionToClient;
}
private void Update()
{
if (Time.time < _nextCycle) return; //Not time to update.
if (_messageStack.Count == 0) Destroy(this); //Stack empty
_curMessage = _messageStack.Pop();
WelcomesMod.Instance.Info($"{_nextCycle} - {_curMessage.Content} - {_curMessage.Period}");
_nextCycle = Time.time + _curMessage.Period;
_broadcast.TargetAddElement(_connection, _curMessage.Content, (uint)_curMessage.Period, _curMessage.Monospaced);
}
}
}