Skip to content

Commit 77e05ee

Browse files
committed
Added object visibility documentation
1 parent 7623b13 commit 77e05ee

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

docs/_data/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- networkedvar
1616
- scene-management
1717
- object-ownership
18+
- object-visibility
1819
- ways-to-syncronize
1920

2021
- title: Core Components
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Object Visibility
3+
permalink: /wiki/object-visibility/
4+
---
5+
6+
Starting with MLAPI version 6.0.0, clients have no explicit knowledge of all objects or clients that are connected to the server.
7+
This allows you to only show a subset of objects to any client and any given time. To allow this, a visibility API was introduced
8+
to the NetworkedObject component and consists of 4 parts.
9+
10+
11+
The first part is a callback that gets invoked when new clients connect or when the object is about to get spawned. It askes whether the object should be shown to a specific client, if you do not register this callback, it will default to true, meaning visible.
12+
13+
```csharp
14+
NetworkedObject netObject = GetComponent<NetworkedObject>();
15+
netObject.CheckObjectVisibility = ((clientId) => {
16+
// return true to show the object, return false to hide it
17+
18+
19+
if (Vector3.Distance(NetworkingManager.Singleton.ConnectedClients[clientId].PlayerObject.position, transform.position) > 5)
20+
{
21+
// Only show the object to players that are within 5 meters. Note that this has to be rechecked by your own code
22+
// If you want it to update as the client and objects distance change.
23+
// This callback is usually only called once per client
24+
return true;
25+
}
26+
else
27+
{
28+
// Dont show this object
29+
return false;
30+
}
31+
});
32+
```
33+
34+
To change the visibility during the game, you can use the following API's
35+
36+
```csharp
37+
NetworkedObject netObject = GetComponent<NetworkedObject>();
38+
netObject.NetworkShow(clientIdToShowTo);
39+
```
40+
and
41+
```csharp
42+
NetworkedObject netObject = GetComponent<NetworkedObject>();
43+
netObject.NetworkHide(clientIdToHideFrom);
44+
```

docs/_includes/docs_nav.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h4 class="panel-title">
1313
{% for item in section.docs %}
1414
{% assign item_url = item | prepend:"/wiki/" | append:"/" %}
1515
{% assign p = site.docs | where:"url", item_url | first %}
16-
<a class="list-group-item {% if item_url == page.url %}active{% endif %}" href="{{ p.url | prepend: site.baseurl }}">{{ p.title }}</a>
16+
<a class="list-group-item list-group-item-action {% if item_url == page.url %}active{% endif %}" href="{{ p.url | prepend: site.baseurl }}">{{ p.title }}</a>
1717
{% endfor %}
1818
</div>
1919
</div>

docs/_includes/footer.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<div class="container">
33

44
<p class="text-center">
5-
{{ site.title }} {{ site.time | date: '%Y' }} |
6-
Website powered by <a href="https://github.com/aksakalli/jekyll-doc-theme">Jekyll Doc Theme</a>
5+
{{ site.title }} {{ site.time | date: '%Y' }} | Copyright © Albin Corén {{ site.time | date: '%Y' }} All Rights Reverse Engineered
76
</p>
87
<!-- <p class="text-muted">Place sticky footer content here.</p> -->
98
</div>

docs/_pages/features.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
</tr>
258258
<tr>
259259
<td>Area Of Interest</td>
260-
<td><i class="fa fa-minus" aria-hidden="true" style="color:blue"></i></td>
260+
<td><i class="fa fa-check" aria-hidden="true" style="color:green"></i></td>
261261
<td><i class="fa fa-check" aria-hidden="true" style="color:green"></i></td>
262262
<td><i class="fa fa-check" aria-hidden="true" style="color:green"></i></td>
263263
</tr>

0 commit comments

Comments
 (0)