public void NetworkInstantiate(ulong ownerId, ulong startNetworkId, string name, Vector3 position, Quaternion rotation, int callbackId = 0)
{
lock (networkedBehaviorsMutex)
{
if (networkedBehaviors.ContainsKey(startNetworkId))
return;
SimpleNetworkedMonoBehavior[] netBehaviors = null;
GameObject o = Instance.PullObject((ownerId != OwningNetWorker.Me.NetworkId ? name + "(Remote)" : name), name);
netBehaviors = GetAllSimpleMonoBehaviors(o);
if (netBehaviors.Length == 0)
{
Debug.LogError("Instantiating on the network is only for objects that derive from BaseNetworkedMonoBehavior, " +
"if object does not need to be serialized consider using a RPC with GameObject.Instantiate");
return;
}
GameObject tmp = (Instantiate(o, position, rotation) as GameObject);
netBehaviors = GetAllSimpleMonoBehaviors(tmp);
while (ObjectCounter < startNetworkId + (ulong)netBehaviors.Length - 1)
{
GenerateUniqueId();
}
for (int i = 0; i < netBehaviors.Length; i++)
netBehaviors[i].Setup(OwningNetWorker, OwningNetWorker.Uniqueidentifier == ownerId, startNetworkId + (ulong)i, ownerId);
if (ownerId == OwningNetWorker.Me.NetworkId)
Networking.RunInstantiateCallback(callbackId, netBehaviors[0].GetComponent<SimpleNetworkedMonoBehavior>());
}
}