-
Notifications
You must be signed in to change notification settings - Fork 0
/
InventorySlot.cs
49 lines (44 loc) · 1.37 KB
/
InventorySlot.cs
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
using UnityEngine;
using System.Collections;
//! This object is used in arrays by the inventory manager to hold item names and amounts.
public class InventorySlot : MonoBehaviour
{
public int amountInSlot;
public string typeInSlot = "nothing";
public int networkWaitTime;
public bool pendingNetworkUpdate;
private Coroutine networkCoroutine;
private bool networkCoroutineBusy;
//! Returns true if this inventory slot requires network updates in multiplayer games.
private bool ShouldDoNetworkUpdate()
{
return gameObject.tag != "Player" &&
PlayerPrefsX.GetPersistentBool("multiplayer") == true &&
pendingNetworkUpdate == true &&
networkCoroutineBusy == false;
}
//! Called once per frame by unity engine.
public void Update()
{
if (ShouldDoNetworkUpdate())
{
networkCoroutine = StartCoroutine(WaitForServer());
}
}
//! Delays overwriting of values by the server while the database is being updated.
private IEnumerator WaitForServer()
{
networkCoroutineBusy = true;
if (networkWaitTime < 30)
{
networkWaitTime++;
yield return new WaitForSeconds(1);
}
else
{
pendingNetworkUpdate = false;
networkWaitTime = 0;
}
networkCoroutineBusy = false;
}
}