public void AddObjectToSynch(StormancerNetworkIdentity ni) { Debug.Log("sending registration request"); var dto = new ReplicatorDTO(); dto.PrefabId = ni.PrefabId; dto.ClientId = ClientProvider.GetClientId(); RemoteScene.Scene.RpcTask<ReplicatorDTO, ReplicatorDTO>("RegisterObject", dto).ContinueWith(response => { Debug.Log("received registration"); dto = response.Result; ni.Id = dto.Id; ni.MasterId = ClientProvider.GetClientId(); MastersObjects.TryAdd(dto.Id, ni); if (SlaveObjects.ContainsKey(dto.Id) && UseDebugGhost == false) { StormancerNetworkIdentity trash; SlaveObjects.TryRemove(dto.Id, out trash); MainThread.Post(() => { Destroy(trash.gameObject); }); } else if (SlaveObjects.ContainsKey(dto.Id) == false && UseDebugGhost == true) { MainThread.Post(() => { var synchedGO = Instantiate(Prefabs[dto.PrefabId]); var collider = synchedGO.GetComponent<Collider>(); if (collider != null) { collider.enabled = false; } var slave = synchedGO.GetComponent<StormancerNetworkIdentity>(); slave.Id = dto.Id; slave.PrefabId = dto.PrefabId; slave.MasterId = dto.ClientId; SlaveObjects.TryAdd(dto.Id, slave); }); } }); }
public void RemoveSynchObject(StormancerNetworkIdentity ni) { Debug.Log("removing object"); var dto = new ReplicatorDTO(); dto.Id = ni.Id; dto.ClientId = ClientProvider.GetClientId(); ; RemoteScene.Scene.Send<ReplicatorDTO>("RemoveObject", dto); MastersObjects.TryRemove(ni.Id, out ni); }
public Task OnRequestObjects(RequestContext<IScenePeer> ctx) { List<ReplicatorDTO> dtos = new List<ReplicatorDTO>(); foreach(StormancerNetworkIdentity ni in LocalObjectToSync) { ReplicatorDTO dto = new ReplicatorDTO(); dto.Id = ni.Id; dto.PrefabId = ni.PrefabId; dto.ClientId = ClientProvider.GetClientId(); ; dtos.Add(dto); } ctx.SendValue<List<ReplicatorDTO>>(dtos); Debug.Log("receiving objects for new player. Sent " + dtos.Count + " objects."); return TaskHelper.FromResult(true); }