Пример #1
0
        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);
        }
Пример #2
0
        /// 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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        public static ReplicaId ReadReplicaId(this BitReader bs)
        {
            var id = bs.ReadUShort();

            return(ReplicaId.CreateFromExisting(id));
        }
Пример #6
0
 public static void Read(this BitReader bs, ref ReplicaId val) => val = bs.ReadReplicaId();
Пример #7
0
 public static void WriteReplicaId(this IBitWriter bs, ReplicaId id) => bs.WriteUShort(id.Data);
Пример #8
0
 public bool Equals(ReplicaId other)
 {
     return(data == other.data);
 }
Пример #9
0
 public Replica GetReplica(ReplicaId id)
 {
     return(networkScene.GetReplicaById(id));
 }
Пример #10
0
 public Replica GetReplica(ReplicaId id) => _networkScene.GetReplicaById(id);