Exemple #1
0
 public void GenerateGuid()
 {
     // Bug: manual changes to byte field are picked up and saved by Unity, but the below changes are not.
     // Can't call editor stuff apparently, because it all fails silently.
     _id = Guid.RandomGuid();
     Debug.Log("Creating new id for '" + name + "', " + GetInstanceID() + ", " + _id);
 }
 public ReplicatedObject(
     GameObject gameObject,
     ObjectMessageRouter messageHandler,
     IReplicationConstructor replicationConstructor,
     IReadOnlyList <ISpawnable> spawnables)
 {
     GlobalObjectId         = new Guid();
     GameObject             = gameObject;
     MessageHandler         = messageHandler;
     ReplicationConstructor = replicationConstructor;
     Spawnables             = spawnables;
     GameObjectNetworkInfo  = gameObject.GetComponent <GameObjectNetworkInfo>() ?? gameObject.AddComponent <GameObjectNetworkInfo>();
 }
Exemple #3
0
        public ReplicatedObject AddExistingInstance(ObjectRole role, ConnectionId hostConnectionId,
                                                    GameObject instance, ObjectId objectId, Guid globalId)
        {
            IPooledObject <ReplicatedObject> replicatedObject;

            if (!_instances.TryGetValue(objectId, out replicatedObject))
            {
                replicatedObject = new UnmanagedObject <ReplicatedObject>(_replicationDecorator(instance, this));
                Instantiate(replicatedObject, null, role, objectId, hostConnectionId);
                replicatedObject.Instance.IsPreExisting = true;
                replicatedObject.Instance.GlobalObjectId.CopyFrom(globalId);
            }

            return(replicatedObject.Instance);
        }