Skip to content

Commit 3e838e2

Browse files
committed
Added Sample chat script to readme
1 parent cf7bb90 commit 3e838e2

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,49 @@ For bug reports or feature requests you want to propose, please use the Issue Tr
5252
* Custom UDP transport support \[[Wiki page](https://github.com/MidLevel/MLAPI/wiki/Custom-Transports)\]
5353
* NetworkProfiler \[[Wiki page](https://github.com/MidLevel/MLAPI/wiki/NetworkProfiler-Editor-Window)\]
5454

55+
## Special thanks
56+
Special thanks to [Gabriel Tofvesson](https://github.com/GabrielTofvesson) for writing the BitWriter, BitReader & ECDH implementation
57+
58+
## Issues and missing features
59+
If there are any issues, bugs or features that are missing. Please open an issue on the GitHub [issues page](https://github.com/MidLevel/MLAPI/issues)
60+
5561
## Example
5662
[Example project](https://github.com/MidLevel/MLAPI-Examples)
5763

5864
The example project has a much lower priority compared to the library itself. If something doesn't exist in the example nor the wiki. Please open an issue on GitHub.
5965

60-
## Special thanks
61-
Special thanks to [Gabriel Tofvesson](https://github.com/GabrielTofvesson) for writing the BitWriter, BitReader & ECDH implementation
62-
6366

64-
65-
## Issues and missing features
66-
If there are any issues, bugs or features that are missing. Please open an issue on the GitHub [issues page](https://github.com/MidLevel/MLAPI/issues)
67+
### Sample Chat
68+
Here is a sample MonoBehaviour showing a chat script where everyone can write and read from.
69+
70+
```csharp
71+
public class Chat : NetworkedBehaviour
72+
{
73+
private NetworkedList<string> ChatMessages = new NetworkedList<string>(new MLAPI.NetworkedVar.NetworkedVarSettings()
74+
{
75+
ReadPermission = MLAPI.NetworkedVar.NetworkedVarPermission.Everyone,
76+
WritePermission = MLAPI.NetworkedVar.NetworkedVarPermission.Everyone,
77+
SendTickrate = 5
78+
}, new List<string>());
79+
80+
private string textField = "";
81+
82+
private void OnGUI()
83+
{
84+
if (isClient)
85+
{
86+
textField = GUILayout.TextField(textField, GUILayout.Width(200));
87+
if (GUILayout.Button("Send") && !string.IsNullOrWhiteSpace(textField))
88+
{
89+
ChatMessages.Add(textField);
90+
textField = "";
91+
}
92+
93+
for (int i = ChatMessages.Count - 1; i >= 0; i--)
94+
{
95+
GUILayout.Label(ChatMessages[i]);
96+
}
97+
}
98+
}
99+
}
100+
```

0 commit comments

Comments
 (0)