// Token: 0x06005900 RID: 22784 RVA: 0x001EDA00 File Offset: 0x001EBE00 private ObjectInstantiator.PrefabInfo _AddPrefab(string path, GameObject prefab) { GameObject gameObject = AssetManagement.Instantiate <GameObject>(prefab); if (gameObject == null) { Debug.LogError("Could not instantiate prefab " + path, base.gameObject); return(null); } int viewCount = VRC.Network.CountSubIDs(gameObject, true); int idCount = (from c in VRC.Network.GetAllComponents <Component>(gameObject, true) where c is INetworkID select c).Count <Component>(); UnityEngine.Object.Destroy(gameObject); prefab.SetActive(false); ObjectInstantiator.PrefabInfo prefabInfo = new ObjectInstantiator.PrefabInfo { obj = prefab, name = path, viewCount = viewCount, idCount = idCount }; this.prefabCache.Add(path, prefabInfo); return(prefabInfo); }
// Token: 0x060058F8 RID: 22776 RVA: 0x001ED1C4 File Offset: 0x001EB5C4 public GameObject InstantiateObject(VRC_EventHandler.VrcBroadcastType broadcast, string prefabName, Vector3 position, Quaternion rotation) { if (VRC.Network.SceneEventHandler == null) { Debug.LogError("Could not instantiate " + prefabName + ": Instantiator is not initialized", base.gameObject); return(null); } if (!VRC_EventDispatcherRFC.IsValidExecutor(VRC.Network.LocalPlayer, broadcast, base.gameObject)) { Debug.LogError("Could not instantiate " + prefabName + ": Client is not a valid remote for " + broadcast.ToString(), base.gameObject); return(null); } VRC_EventHandler.VrcTargetType vrcTargetType; switch (broadcast) { case VRC_EventHandler.VrcBroadcastType.Always: case VRC_EventHandler.VrcBroadcastType.Master: case VRC_EventHandler.VrcBroadcastType.Owner: vrcTargetType = VRC_EventHandler.VrcTargetType.AllBuffered; break; case VRC_EventHandler.VrcBroadcastType.Local: vrcTargetType = VRC_EventHandler.VrcTargetType.Local; break; default: Debug.LogError("Could not instantiate " + prefabName + ": Instantiation cannot be unbuffered.", base.gameObject); return(null); } if (broadcast > VRC_EventHandler.VrcBroadcastType.Owner) { Debug.LogError("Could not instantiate " + prefabName + ": Instantiation cannot be unbuffered.", base.gameObject); return(null); } ObjectInstantiator.PrefabInfo prefabInfo = this._FetchPrefab(prefabName); if (prefabInfo == null) { Debug.LogError("Could not instantiate " + prefabName + ": Could not locate prefab", base.gameObject); return(null); } int num = Math.Max(1, prefabInfo.viewCount); int[] array = VRC.Network.AllocateSubIDs(num); if (array == null) { Debug.LogError("Could not instantiate " + prefabName + ": could not allocate IDs.", base.gameObject); return(null); } byte[] array2 = new byte[2 + 4 * num + 28]; int num2 = 0; Protocol.Serialize(position.x, array2, ref num2); Protocol.Serialize(position.y, array2, ref num2); Protocol.Serialize(position.z, array2, ref num2); Protocol.Serialize(rotation.x, array2, ref num2); Protocol.Serialize(rotation.y, array2, ref num2); Protocol.Serialize(rotation.z, array2, ref num2); Protocol.Serialize(rotation.w, array2, ref num2); Protocol.Serialize((short)num, array2, ref num2); foreach (int value in array) { Protocol.Serialize(value, array2, ref num2); } int?num3 = this.MakeID(); if (num3 == null) { Debug.LogError("Could not instantiate " + prefabName + ": Ran out of IDs", base.gameObject); VRC.Network.UnAllocateSubIDs(array); return(null); } this.spawnedObjects.Add(num3.Value, new ObjectInstantiator.ObjectInfo { data = array2, gameObject = null, prefabName = prefabName, localId = num3.Value }); this.DebugPrint("Instantiating " + prefabName, new object[] { base.gameObject }); VRC.Network.RPC(vrcTargetType, base.gameObject, "_InstantiateObject", new object[] { prefabName, array2, num3.Value }); VRC.Network.RPC((vrcTargetType != VRC_EventHandler.VrcTargetType.Local) ? VRC_EventHandler.VrcTargetType.All : VRC_EventHandler.VrcTargetType.Local, base.gameObject, "_SendOnSpawn", new object[] { num3.Value }); return(this.spawnedObjects[num3.Value].gameObject); }
private void _InstantiateObject(string prefabName, byte[] data, int localID, VRC.Player instantiator) { int num = 0; float x; Protocol.Deserialize(out x, data, ref num); float y; Protocol.Deserialize(out y, data, ref num); float z; Protocol.Deserialize(out z, data, ref num); Vector3 pos = new Vector3(x, y, z); Protocol.Deserialize(out x, data, ref num); Protocol.Deserialize(out y, data, ref num); Protocol.Deserialize(out z, data, ref num); float w; Protocol.Deserialize(out w, data, ref num); Quaternion rot = new Quaternion(x, y, z, w); short num2; Protocol.Deserialize(out num2, data, ref num); int[] array = new int[(int)num2]; for (short num3 = 0; num3 < num2; num3 += 1) { int num4; Protocol.Deserialize(out num4, data, ref num); array[(int)num3] = num4; } ObjectInstantiator.PrefabInfo prefabInfo = this._FetchPrefab(prefabName); if (prefabInfo == null) { Debug.LogError("Could not instantiate " + prefabName + ": Could not find prefab", base.gameObject); VRC.Network.UnAllocateSubIDs(array); return; } GameObject gameObject = AssetManagement.Instantiate <GameObject>(prefabInfo.obj, pos, rot); if (gameObject == null) { Debug.LogError("Could not instantiate " + prefabName + ": Could not instantiate prefab", base.gameObject); VRC.Network.UnAllocateSubIDs(array); return; } gameObject.SetActive(true); ObjectInstantiatorHandle orAddComponent = gameObject.GetOrAddComponent <ObjectInstantiatorHandle>(); orAddComponent.Instantiator = this; orAddComponent.LocalID = new int?(localID); PhotonView orAddComponent2 = gameObject.GetOrAddComponent <PhotonView>(); orAddComponent2.synchronization = ViewSynchronization.Off; orAddComponent2.ownershipTransfer = OwnershipOption.Takeover; if (!VRC.Network.AssignSubIDs(gameObject, array, true)) { Debug.LogError("Could not instantiate " + prefabName + ": Could not assign IDs", base.gameObject); UnityEngine.Object.Destroy(gameObject); return; } gameObject.name = string.Concat(new object[] { prefabInfo.name, " (Dynamic Clone ", localID, ":", orAddComponent2.viewID, ")" }); Debug.LogFormat("Instantiated a {0} with Local ID {1} and View ID {2}", new object[] { prefabInfo.name, localID, orAddComponent2.viewID }); if (!this.spawnedObjects.ContainsKey(localID)) { this.spawnedObjects.Add(localID, new ObjectInstantiator.ObjectInfo { data = data, gameObject = null, prefabName = prefabName }); } VRC.Network.ProtectFromCleanup(gameObject, true); this.spawnedObjects[localID].objectPath = VRC.Network.GetGameObjectPath(gameObject); this.spawnedObjects[localID].gameObject = gameObject; VRC.Network.SetOwner(instantiator, gameObject, VRC.Network.OwnershipModificationType.Request, true); }