コード例 #1
0
        /// <summary>
        /// Spawns a new child gameobject for the passed in player.
        /// </summary>
        /// <param name="target_player">KeyValuePair<int, Photon.Realtime.Player> type, the connected player dictionary</param>
        protected virtual void SpawnChild(KeyValuePair <int, Photon.Realtime.Player> target_player)
        {
            if (string.IsNullOrEmpty(teamName) || teamName == logic.GetUserTeamName(target_player.Value.UserId))
            {
                if (debugging == true)
                {
                    Debug.Log("Spawning local player object: " + target_player.Value.NickName);
                }
                GameObject newChild = null;
                if (target_player.Value.IsMasterClient == true)
                {
                    newChild = Instantiate(ownerPlayer);
                }
                else
                {
                    newChild = Instantiate(otherPlayer);
                }
                newChild.transform.SetParent(parentObj);
                newChild.transform.localScale = new Vector3(1, 1, 1);
                newChild.transform.position   = Vector3.zero;

                if (newChild.GetComponent <PlayerListObject>())
                {
                    newChild.GetComponent <PlayerListObject>().SetPlayerContents(target_player.Value);
                    newChild.GetComponent <PlayerListObject>().SetReadyState(logic.PlayerIsReady(target_player.Value.UserId));
                }
                if (allocateViewIds == true)
                {
                    if (newChild.GetComponent <PhotonView>())
                    {
                        if (logic.GetPlayerVoiceView(target_player.Value.UserId) == 999999 && PhotonNetwork.IsMasterClient == true)
                        {
                            logic.SendUpdateVoiceView(target_player.Value.UserId, PhotonNetwork.AllocateViewID(target_player.Value.ActorNumber));
                        }
                        else if (logic.GetPlayerVoiceView(target_player.Value.UserId) != 999999)
                        {
                            newChild.GetComponent <PhotonView>().ViewID            = logic.GetPlayerVoiceView(target_player.Value.UserId);
                            newChild.GetComponent <PhotonView>().OwnershipTransfer = OwnershipOption.Takeover;
                            newChild.GetComponent <PhotonView>().TransferOwnership(target_player.Value);
                        }
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Sets this component values with the `InstantiationData` for this component. Also
 /// adds the `RecievedPhotonEvent` function to the Photon's `EventReceived` delegate
 /// so it will be called anytime a PhotonEvent is received.
 /// </summary>
 protected virtual void Start()
 {
     logic = NetworkManager.networkManager.GetComponentInChildren <UICoreLogic>();
     if (GetComponent <PhotonView>())
     {
         object[] data = GetComponent <PhotonView>().InstantiationData;
         if (data != null)
         {
             foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
             {
                 if (player.UserId == (string)data[0])
                 {
                     SetPlayerContents(player);
                     SetReadyState(logic.PlayerIsReady(player.UserId));
                 }
             }
             Transform parentToSet = StaticMethods.FindTargetChild((int[])data[1], logic.transform);
             transform.SetParent(parentToSet);
             transform.localScale = new Vector3(1, 1, 1);
             transform.position   = Vector3.zero;
         }
     }
     PhotonNetwork.NetworkingClient.EventReceived += RecievedPhotonEvent;
 }