forked from QianMo/Unity-Design-Pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventQueuePatternExample.cs
More file actions
52 lines (46 loc) · 1.8 KB
/
Copy pathEventQueuePatternExample.cs
File metadata and controls
52 lines (46 loc) · 1.8 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
//-------------------------------------------------------------------------------------
// EventQueuePatternExample.cs
// Reference :https://github.com/GandhiGames/message_queue
// http://gandhigames.co.uk/message-queue/
//-------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
namespace EventQueuePatternExample
{
public class EventQueuePatternExample : MonoBehaviour
{
private Dictionary<MessagePriority, string> priorityLookup = new Dictionary<MessagePriority, string>();
void Start()
{
//添加优先级
priorityLookup.Add(MessagePriority.Low, "Low");
priorityLookup.Add(MessagePriority.Medium, "Medium");
priorityLookup.Add(MessagePriority.High, "High");
}
void Update()
{
//按钮响应
if (Input.GetMouseButtonDown(0))
{
//随机选取优先级
MessagePriority priority = MessagePriority.High;
float random = UnityEngine.Random.value;
if (random < 0.333f)
{
priority = MessagePriority.Low;
}
else if (random < 0.666f)
{
priority = MessagePriority.Medium;
}
//随机选取显示时间
float showTime = UnityEngine.Random.Range(1f, 5f);
//加入事件到队列
EventQueueManager.Instance.AddEventToQueue(new MessageEvent(priorityLookup[priority] + " priority message shown at "
+ System.DateTime.Now + " for " + showTime + " seconds", Time.time + showTime, priority));
}
}
}
}