GetPlayerWithID
How do I use Get Player With I D
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
557 | PhotonPlayer target = this.GetPlayerWithID(targetActorNr); | 1 |
663 | PhotonPlayer player = this.GetPlayerWithID(actorID); | 2 |
790 | private PhotonPlayer GetPlayerWithID(int number) | 3 |
File name: NetworkingPeer.cs
Copy
530 // joins a room and sets your current username as custom actorproperty (will broadcast that)
536 private void ReadoutProperties(Hashtable gameProperties, Hashtable pActorProperties, int targetActorNr)
537 {
538 // Debug.LogWarning("ReadoutProperties gameProperties: " + gameProperties.ToStringFull() + " pActorProperties: " + pActorProperties.ToStringFull() + " targetActorNr: " + targetActorNr);
539 // read game properties and cache them locally
540 if (this.mCurrentGame != null && gameProperties != null)
541 {
542 this.mCurrentGame.CacheProperties(gameProperties);
543 SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, gameProperties);
544 if (PhotonNetwork.automaticallySyncScene)
545 {
546 this.LoadLevelIfSynced(); // will load new scene if sceneName was changed
547 }
548 }
549
550 if (pActorProperties != null && pActorProperties.Count > 0)
551 {
552 if (targetActorNr > 0)
553 {
554 // we have a single entry in the pActorProperties with one
555 // user's name
556 // targets MUST exist before you set properties
557 PhotonPlayer target = this.GetPlayerWithID(targetActorNr);
558 if (target != null)
559 {
560 Hashtable props = this.GetActorPropertiesForActorNr(pActorProperties, targetActorNr);
561 target.InternalCacheProperties(props);
562 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
563 }
564 }
565 else
566 {
567 // in this case, we've got a key-value pair per actor (each
568 // value is a hashtable with the actor's properties then)
569 int actorNr;
570 Hashtable props;
571 string newName;
572 PhotonPlayer target;
573
574 foreach (object key in pActorProperties.Keys)
575 {
576 actorNr = (int)key;
577 props = (Hashtable)pActorProperties[key];
578 newName = (string)props[ActorProperties.PlayerName];
579
580 target = this.GetPlayerWithID(actorNr);
581 if (target == null)
582 {
583 target = new PhotonPlayer(false, actorNr, newName);
584 this.AddNewPlayer(actorNr, target);
585 }
586
587 target.InternalCacheProperties(props);
588 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
589 }
590 }
591 }
592 }
File name: NetworkingPeer.cs
Copy
650 private void HandleEventLeave(int actorID)
651 {
652 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
653 Debug.Log("HandleEventLeave for player ID: " + actorID);
654
655
656 // actorNr is fetched out of event above
657 if (actorID < 0 || !this.mActors.ContainsKey(actorID))
658 {
659 Debug.LogError(String.Format("Received event Leave for unknown player ID: {0}", actorID));
660 return;
661 }
662
663 PhotonPlayer player = this.GetPlayerWithID(actorID);
664 if (player == null)
665 {
666 Debug.LogError("HandleEventLeave for player ID: " + actorID + " has no PhotonPlayer!");
667 }
668
669 // having a new master before calling destroy for the leaving player is important!
670 // so we elect a new masterclient and ignore the leaving player (who is still in playerlists).
671 this.CheckMasterClient(actorID);
672
673
674 // destroy objects & buffered messages
675 if (this.mCurrentGame != null && this.mCurrentGame.autoCleanUp)
676 {
677 this.DestroyPlayerObjects(actorID, true);
678 }
679
680 RemovePlayer(actorID, player);
681
682 // finally, send notification (the playerList and masterclient are now updated)
683 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerDisconnected, player);
684 }
File name: NetworkingPeer.cs
Copy
790 private PhotonPlayer GetPlayerWithID(int number)
791 {
792 if (this.mActors != null && this.mActors.ContainsKey(number))
793 {
794 return this.mActors[number];
795 }
796
797 return null;
798 }
GetPlayerWithID 135 lượt xem
Gõ tìm kiếm nhanh...