Replica ConstructReplica(ushort prefabIdx, ReplicaId replicaId) { GameObject prefab; if (!networkPrefabLookup.TryGetClientPrefabForIndex(prefabIdx, out prefab)) { throw new Exception($"Prefab for index {prefabIdx} not found!"); } _replicasInConstruction.Add(replicaId); var newGameObject = GameObject.Instantiate(prefab, client.ReplicaParentTransform); var replica = newGameObject.GetComponent <Replica>(); if (replica == null) { throw new Exception("Replica component missing on " + prefab); } replica.client = client; replica.Id = replicaId; _replicasInConstruction.Remove(replicaId); networkScene.AddReplica(replica); return(replica); }
/// Scan a newly loaded Scene for scene Replicas. public void ProcessSceneReplicasInScene(Scene scene) { var sceneReplicas = ReplicaUtils.GatherSceneReplicas(scene); foreach (var replica in sceneReplicas) { replica.Id = ReplicaId.CreateFromExisting(replica.sceneIdx); replica.server = _server; _networkScene.AddReplica(replica); } }
public void ProcessSceneReplicasInScene(Scene scene) { #if UNITY_EDITOR ProcessSceneReplicasInSceneInternal(scene); #endif var sceneReplicas = ReplicaUtils.GatherSceneReplicas(scene); foreach (var replica in sceneReplicas) { replica.Id = ReplicaId.CreateFromExisting(replica.sceneIdx); networkScene.AddReplica(replica); } }
Replica InstantiateReplicaImpl(GameObject newInstance) { var newReplica = newInstance.GetComponent <Replica>(); if (newReplica == null) { return(null); } newReplica.server = _server; newReplica.Id = ReplicaId.Create(this); Assert.IsTrue(newReplica.Id != ReplicaId.Invalid); newReplica.TakeOwnership(); // Wait for one frame until Start is called before replicating to clients _replicasInConstruction[newReplica.Id] = newReplica; return(newReplica); }
public static ReplicaId ReadReplicaId(this BitReader bs) { var id = bs.ReadUShort(); return(ReplicaId.CreateFromExisting(id)); }
public static void Read(this BitReader bs, ref ReplicaId val) => val = bs.ReadReplicaId();
public static void WriteReplicaId(this IBitWriter bs, ReplicaId id) => bs.WriteUShort(id.Data);
public bool Equals(ReplicaId other) { return(data == other.data); }
public Replica GetReplica(ReplicaId id) { return(networkScene.GetReplicaById(id)); }
public Replica GetReplica(ReplicaId id) => _networkScene.GetReplicaById(id);