// The following is specific to OVR integration, which requires manual instantiation // due to its use of the local and remote avatars. // Otherwise we could simply use PhotonNetwork.Instantiate public override void OnJoinedRoom( ) { GameObject localAvatar = Instantiate(Resources.Load("LocalAvatar")) as GameObject; PhotonView photonView = localAvatar.GetComponent <PhotonView>(); if (PhotonNetwork.AllocateViewID(photonView)) { // Instantiate our local camera // Note: stagger spawn pos based on player count. // Note: give each player a color. //PhotonNetwork.Instantiate ( "OVRCameraRig", Vector3.zero, Quaternion.identity, 0, null ); // Tell the other games to instantiate our remote avatar RaiseEventOptions raiseEventOptions = new RaiseEventOptions { CachingOption = EventCaching.AddToRoomCache, Receivers = ReceiverGroup.Others }; SendOptions sendOptions = new SendOptions { Reliability = true }; PhotonNetwork.RaiseEvent(InstantiateVrAvatarEventCode, photonView.ViewID, raiseEventOptions, sendOptions); } else { Debug.LogError("Failed to allocate a ViewId."); Destroy(localAvatar); } }
void SpawnPlayer(int i) { GameObject piece = IsFirstPlayer ? Instantiate(YellowPlayer, Positions[i].transform.position, PieceRotation) : Instantiate(RedPlayer, Positions[i].transform.position, PieceRotation); PhotonView view = piece.GetComponent <PhotonView>(); if (PhotonNetwork.AllocateViewID(view)) { object[] data = new object[] { MyFlippedCoordinates.PositionRelativeToBoard(piece.transform.position, Board), piece.transform.rotation, view.ViewID, IsFirstPlayer }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache, }; SendOptions sendOptions = new SendOptions { Reliability = true }; PhotonNetwork.RaiseEvent((byte)RaiseEventCodes.PlayerSpawnEventCode, data, raiseEventOptions, sendOptions); } }
public Poolable Get(bool _instantiateViewID = false) { Poolable poolable; if (models.Count == 0) { poolable = Instantiate(modelGameObject, transform).GetComponent <Poolable>(); } else { poolable = models.First(); models.Remove(models.First()); } poolable.gameObject.SetActive(true); poolable.transform.SetParent(null); if (_instantiateViewID) { PhotonNetwork.AllocateViewID(poolable.GetComponent <PhotonView>()); } return(poolable); }
private void Awake() { GameManager.Instance.onStartGame += SetGameStarted; timeText.text = gameTime.ToString(); //allocate an id (target) for the photonView, otherwise we would need to instantiate the object over the network. PhotonNetwork.AllocateViewID(); }
public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer) { Debug.Log(newPlayer.NickName + " is member of " + PhotonNetwork.CurrentRoom.PlayerCount); UIManager.toStatic.ActivatePanel(UIManager.toStatic.PKGamePanel.name); GameObject player = Instantiate(PKManager.toStatic.playerPrefab); PhotonView photonView = player.GetComponent <PhotonView>(); if (PhotonNetwork.AllocateViewID(photonView)) { object[] data = new object[] { player.transform.position, player.transform.rotation, photonView.ViewID }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache }; SendOptions sendOptions = new SendOptions { Reliability = true }; //PhotonNetwork.RaiseEvent(CustomManualInstantiationEventCode, data, raiseEventOptions, sendOptions); } player.GetComponent <PlayerSetup>().Initialize(newPlayer.ActorNumber, newPlayer.NickName); playerListGameObjects.Add(newPlayer.ActorNumber, player); }
private void ManualInstantiation(int index, Vector3 position) { GameObject prefab = PrefabsToInstantiate[index]; GameObject player = Instantiate(prefab, position, Quaternion.identity); PhotonView photonView = player.GetComponent <PhotonView>(); if (PhotonNetwork.AllocateViewID(photonView)) { object[] data = { index, player.transform.position, photonView.ViewID }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache }; PhotonNetwork.RaiseEvent(manualInstantiationEventCode, data, raiseEventOptions, SendOptions.SendReliable); if (CharacterInstantiated != null) { CharacterInstantiated(player); } } else { Debug.LogError("Failed to allocate a ViewId."); Destroy(player); } }
void StartRound() { if (!_initialized) { return; } CleanUp(); _state = GameState.Gameplay; _currentRound++; if (!IsMaster) { return; } var level = _LevelCollection.GetRandomItem(11); var gameModeIndex = _GameModeCollection.GetRandomItemIndex(13); if (PhotonNetwork.offlineMode) { //PhotonNetwork.LoadLevel(level); SceneManager.LoadScene(level); StartCoroutine(FinalizeSetupRound(gameModeIndex, PhotonNetwork.AllocateViewID())); } else { var viewId = PhotonNetwork.AllocateViewID(); photonView.RPC("SetupRound", PhotonTargets.All, level, gameModeIndex, viewId, PhotonNetwork.player); } }
// Object spawning methods public int SetupLocalPlayer() { MPLogger.Log("Setting up local player"); MPLogger.Log($"{HeroController.instance.col2d.GetType().ToString()}"); GameObject local = new GameObject("NetworkPlayerSender"); DontDestroyOnLoad(local); PhotonView view = local.AddComponent <PhotonView>(); NetworkPlayer player = local.AddComponent <NetworkPlayer>(); view.ownershipTransfer = OwnershipOption.Takeover; view.synchronization = ViewSynchronization.UnreliableOnChange; view.viewID = PhotonNetwork.AllocateViewID(); view.TransferOwnership(PhotonNetwork.player); view.ObservedComponents = new List <Component> { player }; RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache }; PhotonNetwork.RaiseEvent(NetworkCallbacks.OnSetupLocalPlayer, view.viewID, true, options); localPlayer = player; needsToSetupPlayer = false; return(view.viewID); }
public void refindGameManager() { if (this.fGameManager == null) { this.log("Lost the game manager, trying to find."); this.fGameManager = GameObject.Find("MultiplayerManager").GetComponent <FengGameManagerMKII>(); if (this.fGameManager == null) { this.log("Could not find game manager, trying to instantiate."); this.fGameManager = new GameObject().AddComponent <FengGameManagerMKII>(); if (this.lastViewId > 0) { this.fGameManager.photonView.viewID = this.lastViewId; } else { this.fGameManager.photonView.viewID = PhotonNetwork.AllocateViewID(); } } else { this.lastViewId = fGameManager.photonView.viewID; } if (this.modUI == null) { GameObject go = new GameObject(); go.name = "ModUI"; GameObject.DontDestroyOnLoad(go); this.modUI = go.GetComponent <ModUI>(); } } }
public void OnSceneLoad() { if (SceneManager.GetActiveScene().name.Equals("GameNetwork")) { if (PhotonNetwork.isMasterClient) { int id1 = PhotonNetwork.AllocateViewID(); gameObject.AddComponent <PhotonView>().viewID = id1; //gameObject.GetComponent<PhotonView>().ObservedComponents = new List<Component> {this}; //gameObject.GetComponent<PhotonView>().synchronization = ViewSynchronization.UnreliableOnChange; } else { ready = false; gameObject.AddComponent <PhotonView>().viewID = 1001; //gameObject.GetComponent<PhotonView>().ObservedComponents = new List<Component> {this}; //gameObject.GetComponent<PhotonView>().synchronization = ViewSynchronization.UnreliableOnChange; } if (!PhotonNetwork.isMasterClient) { PhotonView photonView = gameObject.GetComponent <PhotonView>(); //photonView.RPC("SendDBwork", PhotonTargets.MasterClient); } } else { if (gameObject.GetComponent <PhotonView>() != null) { Destroy(gameObject.GetComponent <PhotonView>()); } } }
public void DestoryPlayer() { if (PhotonNetwork.AllocateViewID(photonView)) { object[] data = new object[] { photonView.ViewID }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache }; SendOptions sendOptions = new SendOptions { Reliability = true }; PhotonNetwork.RaiseEvent(1, data, raiseEventOptions, sendOptions); } else { Debug.LogErrorFormat("Failed to allocate a ViewId."); Destroy(player); } }
public void CreatePlayer() { GameObject player = Instantiate(PlayerPrefab); PhotonView photonView = player.GetComponent <PhotonView>(); if (PhotonNetwork.AllocateViewID(photonView)) { object[] data = new object[] { photonView.ViewID }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache }; SendOptions sendOptions = new SendOptions { Reliability = true }; PhotonNetwork.RaiseEvent(1, data, raiseEventOptions, sendOptions); } else { Debug.LogError("Failed to allocate a ViewID"); Destroy(player); } }
public void ChangeLocalPlayer(int i) { if (connectcount < 30) { Hashtable hashtable = new Hashtable(); hashtable.Add(PhotonPlayerProperty.name, i.ToString()); hashtable.Add(PhotonPlayerProperty.guildName, LoginFengKAI.player.guildname); hashtable.Add(PhotonPlayerProperty.kills, 0); hashtable.Add(PhotonPlayerProperty.max_dmg, 0); hashtable.Add(PhotonPlayerProperty.total_dmg, 0); hashtable.Add(PhotonPlayerProperty.deaths, 0); hashtable.Add(PhotonPlayerProperty.dead, true); hashtable.Add(PhotonPlayerProperty.isTitan, 0); hashtable.Add(PhotonPlayerProperty.RCteam, 0); hashtable.Add(PhotonPlayerProperty.currentLevel, string.Empty); PhotonNetwork.AllocateViewID(); PhotonNetwork.player.SetCustomProperties(hashtable); connectcount++; } else { Reconnect(i); connectcount = 0; } }
private void SpawnPlayer() { // object playerSelectionNumber; //if (PhotonNetwork.player.CustomProperties.TryGetValue(.PLAYER_SELECTION_NUMBER, out playerSelectionNumber)) //{ // Debug.Log("Player selection number is " + (int)playerSelectionNumber); int playerNumber = PhotonNetwork.playerList.Length; // int randomSpawnPoint = Random.Range(0, spawnPositions.Length - 1); Vector3 instantiatePosition = spawnPositions[playerNumber].position; GameObject playerGameobject = Instantiate(playerPrefabs[0], instantiatePosition, Quaternion.identity); PhotonView _photonView = playerGameobject.GetComponent <PhotonView>(); int viewID = PhotonNetwork.AllocateViewID(); _photonView.viewID = viewID; object[] data = new object[] { playerGameobject.transform.position - Plane.transform.position, playerGameobject.transform.rotation, _photonView.viewID, 0 }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache }; bool reliable = true; PhotonNetwork.RaiseEvent((byte)RaiseEventCodes.PlayerSpawnEventCode, data, reliable, raiseEventOptions); }
private void SpawnPlayer() { object playerSelectionNumber; // TODO: Check what is keyword out in C# // TODO: Check what is type object in C# // TODO: Check Quartenion.Identity if (PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue(MultiplayerARSpinnerTopGame.PLAYER_SELECTION_NUMBER, out playerSelectionNumber)) { int randomSpawnPoint = Random.Range(0, spawnPositions.Length - 1); Vector3 instantiatePosition = spawnPositions[randomSpawnPoint].position; // Instantiate player locally using random placement and prefab based on spinner ID GameObject playerGameObject = Instantiate( playerPrefabs[(int)playerSelectionNumber], instantiatePosition, Quaternion.identity ); // Get the PhotonView of object (attached to all spinner prefabs) PhotonView _photonView = playerGameObject.GetComponent <PhotonView> (); if (PhotonNetwork.AllocateViewID(_photonView)) { BrodcastLocation(playerGameObject, _photonView, playerSelectionNumber); } else { Debug.Log("failed to allocate a viewID"); Destroy(playerGameObject); } } }
public override void OnJoinedRoom() { int id = PhotonNetwork.AllocateViewID(); NetworkPlayerManager.Instance.personalID = id; NetworkPlayerManager.Instance.photonView.RPC("SpawnNetworkPlayer", PhotonTargets.OthersBuffered, Vector3.zero, Quaternion.identity, id); }
/* Constructs a player object in game. */ public static GameObject ConstructModule(GameObject prefab, PhotonPlayer owner, Vector2 position, float rotation) { GameObject module = InstantiateModuleWithName(prefab, position, rotation, prefab.name); module.SetActive(false); AddRigidbody(module, new RandomModuleRigidbodyInfo()); ISetup setupScript = prefab.GetComponent <ISetup> (); if (setupScript == null) { Debug.LogErrorFormat("Prefab module '{0}' does not have a setup script of type ISetup", prefab.name); return(null); } ModuleController controller = setupScript.AddController(module); PhotonView view = AddViewForComponent(controller, PhotonNetwork.AllocateViewID()); controller.info = module.GetComponent <ModuleInfo> (); controller.info.Setup(owner, view); module.SetActive(true); return(module); }
public GameObject ManualBuildSyncToken(InstantiationData dataToSend) { var go = PrefabPoolManager.Instance.Instantiate("TransmissionToken", Vector3.zero, Quaternion.identity);//Instantiate(transmissionTokenPrefab); var pView = go.GetComponent <PhotonView>(); if (PhotonNetwork.AllocateViewID(photonView)) { var raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others, CachingOption = EventCaching.AddToRoomCache }; var sendOptions = new SendOptions { Reliability = true }; dataToSend.Add("viewID", photonView.ViewID.ToString()); PhotonNetwork.RaiseEvent( (byte)RaiseEvnetCode.CustomManualInstantiationEventCode, dataToSend.ToData(), raiseEventOptions, sendOptions); return(go); } Debug.LogError("Failed to allocate a ViewId."); Destroy(go); return(null); }
private void InstanciarObjeto() { GameObject instancia = Instantiate(objetoAInstanciar, new Vector3(pv.gameObject.transform.position.x, pv.gameObject.transform.position.y + 2, pv.gameObject.transform.position.z), Quaternion.identity); PhotonNetwork.AllocateViewID(instancia.GetPhotonView()); print(string.Concat("Se ha instanciado de forma automática el objeto ", instancia.name, "con ViewID", instancia.GetPhotonView().ViewID)); }
void CreateLocalAvatar() { avatarViewId = PhotonNetwork.AllocateViewID(); CreateAvatar("LocalAvatar", avatarViewId); photonView.RPC("OnCreateAvatarRPC", PhotonTargets.Others, avatarViewId); }
//public void Initialize(bool empty = false) //{ // cache = new Dictionary<string, List<GameObject>>(); // if (empty) // { // keys = new string[] { "" }; // return; // } // for (int i = 0; i < keys.Length; i++) // { // string currentKey = keys[i]; // List<GameObject> local = new List<GameObject>(); // Expand(currentKey, local, defaultCount); // cache.Add(currentKey, local); // } //} public GameObject NetworkEnable(string name, Vector3 position, Quaternion rotation, int group = 0, object[] data = null, bool isSceneObject = false) { if (IN_GAME_MAIN_CAMERA.GameType != GameType.MultiPlayer) { Debug.LogError($"PoolObject.NetworkEnable(): Failed to NetworkEnable prefab, because GameType is not Multiplayer."); return(null); } GameObject go = PickObject(name); PhotonView pv = go.GetComponent <PhotonView>(); if (pv == null) { throw new System.Exception($"PoolObject.NetworkEnable(): Prefab \"{name}\" has not PhotonView component."); } PhotonView[] photonViews = go.GetPhotonViewsInChildren(); int[] viewIDs = new int[photonViews.Length]; for (int i = 0; i < viewIDs.Length; i++) { viewIDs[i] = PhotonNetwork.AllocateViewID(PhotonNetwork.player.ID); } PhotonNetwork.networkingPeer.SendInstantiate(name, position, rotation, group, viewIDs, data, isSceneObject); return(NetworkInstantiate(name, position, rotation, viewIDs[0], viewIDs, (short)(PhotonNetwork.networkingPeer.currentLevelPrefix > 0 ? PhotonNetwork.networkingPeer.currentLevelPrefix : 0), group, data)); #region Old version //for (int i = 0; i < photonViews.Length; i++) //{ // photonViews[i].viewID = viewIDs[i]; // photonViews[i].prefix = prefix; // photonViews[i].instantiationId = instantiationId; //} //if (go.transform != null) //{ // go.transform.position = position; // go.transform.rotation = rotation; //} //peer.StoreInstantiationData(instantiationId, data); //go.SetActive(true); //peer.RemoveInstantiationData(instantiationId); //if (peer.instantiatedObjects.ContainsKey(instantiationId)) //{ // GameObject gameobj = peer.instantiatedObjects[instantiationId]; // string str2 = string.Empty; // if (gameobj != null) // { // foreach (PhotonView view in gameobj.GetPhotonViewsInChildren()) // { // if (view != null) // { // str2 = str2 + view.ToString() + ", "; // } // } // } // object[] args = new object[] { gameobj, instantiationId, peer.instantiatedObjects.Count, go, str2, PhotonNetwork.lastUsedViewSubId, PhotonNetwork.lastUsedViewSubIdStatic, NetworkingPeer.photonViewList.Count }; // Debug.LogError(string.Format("DoInstantiate re-defines a GameObject. Destroying old entry! New: '{0}' (instantiationID: {1}) Old: {3}. PhotonViews on old: {4}. instantiatedObjects.Count: {2}. PhotonNetwork.lastUsedViewSubId: {5} PhotonNetwork.lastUsedViewSubIdStatic: {6} photonViewList.Count {7}.)", args)); // peer.RemoveInstantiatedGO(go, true); //} //peer.instantiatedObjects.Add(instantiationId, go); //return go; #endregion }
/// <summary> /// Will create the scripts needed to sync the local players position, rotation and animation to others /// </summary> void AddEssentialComponentsToPlayer() { GameObject playerBody = Player.main.transform.Find("body").gameObject; // Because we can't use PhotonNetwork.Instantiate(), we need to allocate a view ID manually int id = PhotonNetwork.AllocateViewID(); localPlayerView = playerBody.AddComponent <PhotonView>(); localPlayerView.viewID = id; localPlayerView.TransferOwnership(PhotonNetwork.player); localPlayerView.synchronization = ViewSynchronization.UnreliableOnChange; localPlayerView.ownershipTransfer = OwnershipOption.Takeover; // We can sync this ID to other players using PhotonPlayer.CustomProperties Hashtable playerProps = new Hashtable(); playerProps.Add("ObjectID", id); PhotonNetwork.player.SetCustomProperties(playerProps); // Using a custom class rather than PhotonTransformView and PhotonAnimatorView NetPlayerSync positionSync = playerBody.AddComponent <NetPlayerSync>(); positionSync.animator = playerBody.transform.Find("player_view").GetComponent <Animator>(); localPlayerView.ObservedComponents = new List <Component>(); //localPlayerView.ObservedComponents.Add(transView); localPlayerView.ObservedComponents.Add(positionSync); }
void ChangeProjectile(object[] received) { int id2 = PhotonNetwork.AllocateViewID(); object[] data = received; myView.RPC("ProjectileType", PhotonTargets.AllBuffered, (string)data[0], id2, (int)data[1]); }
public void Initialize() { if (!PhotonNetwork.AllocateViewID(_photonView)) { return; } object[] data = { _view.Position, _view.Rotation, _photonView.ViewID, _playerType, _ai, _ownerActor }; var sendOptions = new SendOptions { Reliability = true }; var raiseEventOptions = new RaiseEventOptions { CachingOption = EventCaching.AddToRoomCache }; raiseEventOptions.Receivers = ReceiverGroup.Others; PhotonNetwork.RaiseEvent(Constants.CarInstantiateEventCode, data, raiseEventOptions, sendOptions); }
void MulaiPlayer() { int id1 = PhotonNetwork.AllocateViewID(); Vector3 posisiRandom = new Vector3(Random.Range(-radiusPlayer, radiusPlayer), 0f, Random.Range(-radiusPlayer, radiusPlayer)); pv.RPC("SpawnPlayer", PhotonTargets.All, posisiRandom, transform.rotation, id1); pv.RPC("KirimPesan", PhotonTargets.All, "<color=cyan>" + PhotonNetwork.player.NickName + " Bergabung </color>\n"); }
/// <summary> /// 生成所有野怪实例 /// </summary> void SpawnMonsterObjects() { //手动分配PhotonViewID int viewId = PhotonNetwork.AllocateViewID(); int viewIdModel = PhotonNetwork.AllocateViewID(); photonView.RPC("SpawnMonsterObjectsRPC", PhotonTargets.All, WorldObj.Nationality.monster, 50000, WorldObj.SoldierType.Griffin, 80, viewId, viewIdModel); }
public void CreateAvatar(AvatarType avatarType, Vector3 spawnPosition) { int idModel = PhotonNetwork.AllocateViewID(); int idWeapon = PhotonNetwork.AllocateViewID(); photonView.RPC("CreateModel", PhotonTargets.All, avatarType, idModel, idWeapon); photonView.RPC("InitAvatar", PhotonTargets.All, spawnPosition, avatarType); }
public void StartGame() { if (PhotonNetwork.isMasterClient) { PhotonNetwork.room.IsOpen = false; photonView.RPC("StartGameSync", PhotonTargets.All, PhotonNetwork.AllocateViewID()); } }
void StartTurn() { if (turn == Turn.local) { int id1 = PhotonNetwork.AllocateViewID(); photonView.RPC("NetworkSpawn", PhotonTargets.All, id1); } }
void PreObjectActivate(InstantiationData i) { var g = i.GameObject; if (g == null) { Debug.LogError("Prefab not found at prefabPath=[" + i.PrefabPath + "]"); } PhotonView[] pvs = g.GetComponents <PhotonView>(); foreach (PhotonView pv in pvs) { pv.enabled = false; } PhotonView[] photonViews = g.GetComponents <PhotonView>(); if (photonViews.Length < 1) { throw new Exception("No PhotonViews found on prefab at prefabPath=[" + i.PrefabPath + "]"); } if (i.ViewIds != null) //set appropriate view ids for the components in this object { if (photonViews.Length < i.ViewIds.Length) { Debug.LogWarning("Received more viewIds for object instantiation than there were photonViews"); } else { for (int ind = 0; ind < i.ViewIds.Length; ind++) { if (photonViews.Length > i.ViewIds.Length) { Debug.LogError("Can't assign null viewId to photon view"); } else { PhotonView pv = photonViews[ind]; pv.ownerId = i.OwnerId; pv.viewID = i.ViewIds[ind]; pv.enabled = true; } } } } else if (i.OwnerId == PhotonNetwork.player.ID) //no view ids provided, create them for ourself { for (int ind = 0; ind < photonViews.Length; ind++) { PhotonView pv = photonViews[ind]; pv.ownerId = i.OwnerId; pv.viewID = PhotonNetwork.AllocateViewID(); pv.enabled = true; } } }