-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatLog.cs
More file actions
93 lines (81 loc) · 2.86 KB
/
ChatLog.cs
File metadata and controls
93 lines (81 loc) · 2.86 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using UnityEngine;
using System.Collections.Generic;
public class ChatLog : MonoBehaviour
{
public int maxLines = 10;
public Font font;
private List<string> chatLog = new List<string>();
private List<GUIText> guiTexts = new List<GUIText>();
void Update()
{
List<GUIText> removeList = new List<GUIText>();
for (int i = 0; i < guiTexts.Count - 1; i++)
{
GUIText guiTxt1 = guiTexts[i];
GUIText guiTxt2 = guiTexts[i + 1];
if (guiTxt1.Y + guiTxt1.Height > guiTxt2.Y)
{
guiTxt1.Y = guiTxt2.Y - guiTxt1.Height;
}
if (guiTxt1.Y + guiTxt1.Height < 0)
{
removeList.Add(guiTxt1);
}
}
foreach (GUIText guiText in removeList)
{
guiTexts.Remove(guiText);
}
foreach (GUIText guiText in guiTexts)
{
guiText.Y -= 2;
guiText.Opacity -= 0.00392f;
}
}
void OnGUI()
{
GUIStyle myStyle = new GUIStyle();
myStyle.font = font;
myStyle.fontSize = 50;
for (int i = 0; i < guiTexts.Count; i++)
{
GUI.color = new Color(1, 1, 1, guiTexts[i].Opacity);
myStyle.normal.textColor = Color.gray;
GUI.Label(new Rect(guiTexts[i].X, guiTexts[i].Y + 2, guiTexts[i].Width, guiTexts[i].Height), guiTexts[i].Text, myStyle);
GUI.Label(new Rect(guiTexts[i].X + 2, guiTexts[i].Y, guiTexts[i].Width, guiTexts[i].Height), guiTexts[i].Text, myStyle);
GUI.Label(new Rect(guiTexts[i].X + 2, guiTexts[i].Y + 4, guiTexts[i].Width, guiTexts[i].Height), guiTexts[i].Text, myStyle);
GUI.Label(new Rect(guiTexts[i].X + 4, guiTexts[i].Y + 2, guiTexts[i].Width, guiTexts[i].Height), guiTexts[i].Text, myStyle);
myStyle.normal.textColor = Color.white;
GUI.Label(new Rect(guiTexts[i].X + 2, guiTexts[i].Y + 2, guiTexts[i].Width, guiTexts[i].Height), guiTexts[i].Text, myStyle);
}
}
public void Write(string text)
{
chatLog.Add(text);
if (chatLog.Count >= maxLines)
chatLog.RemoveAt(0);
GUIStyle myStyle = new GUIStyle();
myStyle.font = font;
myStyle.fontSize = 50;
Vector2 size = myStyle.CalcSize(new GUIContent(text));
guiTexts.Add(new GUIText(text, 0, Screen.height - 40, size.x, size.y, 1.0f));
}
public class GUIText
{
public string Text;
public float X;
public float Y;
public float Width;
public float Height;
public float Opacity;
public GUIText(string text, float x, float y, float width, float height, float opacity)
{
Text = text;
X = x;
Y = y;
Width = width;
Height = height;
Opacity = opacity;
}
}
}