/// <summary> /// Network.Destroy equivalent, but works even if offline. /// </summary> static public void RemoteDestroy(GameObject obj) { if (obj == null) { return; } if (isConnected) { NetworkView view = obj.networkView; if (view != null) { // Ignore entries that have already been destroyed foreach (DestroyedEntry de in mDestroyed) { if (de.id == view.viewID) { return; } } // Add a local entry right away so future RemoteDestroy calls get ignored DestroyedEntry ent = new DestroyedEntry(); ent.time = Time.time; ent.id = view.viewID; mDestroyed.Add(ent); // Notify all players that this viewID is being destroyed mInstance.mView.RPC("OnRemoteDestroy", RPCMode.All, view.viewID); // Destroy the object Network.Destroy(view.viewID); } else { Debug.LogError(Tools.GetHierarchy(obj) + " has no NetworkView on it!"); } } else { Destroy(obj); } }
/// <summary> /// RPC notification of a network view ID being destroyed. /// Used to add the destroyed object to all the clients' lists. /// </summary> [RPC] void OnRemoteDestroy(NetworkViewID viewID) { bool alreadyDestroyed = false; // Check to see if this viewID has already been destroyed foreach (DestroyedEntry de in mDestroyed) { if (de.id == viewID) { // Match (happens on the same PC that sent out the request) alreadyDestroyed = true; break; } } float time = Time.time; // Remove stale entries for (int i = mDestroyed.Count; i > 0;) { DestroyedEntry de = mDestroyed[--i]; if (de.time + 5f < time) { mDestroyed.RemoveAt(i); } } // Add a new entry if (!alreadyDestroyed) { DestroyedEntry de = new DestroyedEntry(); de.time = time; de.id = viewID; mDestroyed.Add(de); } // Remove all other RPC calls stored on this view Network.RemoveRPCs(viewID); }
void OnRemoteDestroy(NetworkViewID viewID) { bool alreadyDestroyed = false; // Check to see if this viewID has already been destroyed foreach (DestroyedEntry de in mDestroyed) { if (de.id == viewID) { // Match (happens on the same PC that sent out the request) alreadyDestroyed = true; break; } } float time = Time.time; // Remove stale entries for (int i = mDestroyed.Count; i > 0; ) { DestroyedEntry de = mDestroyed[--i]; if (de.time + 5f < time) mDestroyed.RemoveAt(i); } // Add a new entry if (!alreadyDestroyed) { DestroyedEntry de = new DestroyedEntry(); de.time = time; de.id = viewID; mDestroyed.Add(de); } // Remove all other RPC calls stored on this view Network.RemoveRPCs(viewID); }
/// <summary> /// Network.Destroy equivalent, but works even if offline. /// </summary> public static void RemoteDestroy(GameObject obj) { if (obj == null) return; if (isConnected) { NetworkView view = obj.networkView; if (view != null) { // Ignore entries that have already been destroyed foreach (DestroyedEntry de in mDestroyed) if (de.id == view.viewID) return; // Add a local entry right away so future RemoteDestroy calls get ignored DestroyedEntry ent = new DestroyedEntry(); ent.time = Time.time; ent.id = view.viewID; mDestroyed.Add(ent); // Notify all players that this viewID is being destroyed mInstance.mView.RPC("OnRemoteDestroy", RPCMode.All, view.viewID); // Destroy the object Network.Destroy(view.viewID); } else { Debug.LogError(Tools.GetHierarchy(obj) + " has no NetworkView on it!"); } } else Destroy(obj); }