Example #1
0
 /// <summary>
 /// Perform certain actions based on the type of `BroadCastMessage` that is
 /// received from the data channel on the ChatBox.
 /// </summary>
 /// <param name="message">BroadCastMessage type, the message and the type of message</param>
 public virtual void ReceiveBroadCastMessage(BroadCastMessage message)
 {
     isEnabled = true;
     scrollView.SetActive(true);
     if (message.speaker == "DEATH")
     {
         InstantiateDeathMessage(message.message);
     }
 }
Example #2
0
    static BroadCastMessage GetMessage(TEnum identity)
    {
        BroadCastMessage message;

        if (!m_Messages.ContainsKey(identity))
        {
            message = new BroadCastMessage();
            m_Messages.Add(identity, message);
        }
        else
        {
            message = (m_Messages[identity] as BroadCastMessage);
            if (message == null)
            {
                throw new Exception("Wrong Message Type Of" + identity);
            }
        }
        return(message);
    }
Example #3
0
    static BroadCastMessage <T, Y, U, I> GetMessage <T, Y, U, I>(TEnum identity)
    {
        BroadCastMessage <T, Y, U, I> message;

        if (!m_Messages.ContainsKey(identity))
        {
            message = new BroadCastMessage <T, Y, U, I>();
            m_Messages.Add(identity, message);
        }
        else
        {
            message = (m_Messages[identity] as BroadCastMessage <T, Y, U, I>);
            if (message == null)
            {
                throw new Exception("Wrong Message Type Of" + identity + "," + typeof(T) + "," + typeof(Y) + "," + typeof(U) + "," + typeof(I));
            }
        }
        return(message);
    }
Example #4
0
        /// <summary>
        /// Will set the death message based on the inputs and broadcasts that message via the
        /// Chatbox's data channel to everyone in the session, but only if you allow this. Enables
        /// the respawn visual component and starts the countdown. After waiting for the `respawnDelay`
        /// time it calls `NetworkInstantiatePrefab` from the NetworkManager to instantiate your
        /// new player and sets all of its needed values at a target respawn point. It will then
        /// destroy the old player based on the photonView.
        /// </summary>
        /// <param name="playerView">PhotonView type, the photonview of the player respawning</param>
        /// <param name="keepItems">bool type, keep the items of the player that is respawning</param>
        /// <param name="lastDamager">Gameobject type, the gameobject of the thing that dealt the last bit of damage</param>
        /// <param name="lastDamageType">string type, the type of damage that was received.</param>
        protected virtual IEnumerator RespawnAction(PhotonView playerView, bool keepItems, GameObject lastDamager = null, string lastDamageType = "")
        {
            GameObject respawnVisual = null;

            if (broadcastDeathMessage == true)
            {
                deathMessage = deathMessage.Replace("{Nickname}", playerView.Owner.NickName);
                if (string.IsNullOrEmpty(lastDamageType))
                {
                    deathMessage = deathMessage.Replace("{DamageType}", "a unknown damage type");
                }
                else
                {
                    deathMessage = deathMessage.Replace("{DamageType}", lastDamageType);
                }
                if (lastDamager != null)
                {
                    if (lastDamager.tag == "Player")
                    {
                        deathMessage = deathMessage.Replace("{Damager}", "themself");
                    }
                    else if (lastDamager.GetComponent <PhotonView>() || lastDamager.transform.GetComponentInParent <PhotonView>())
                    {
                        string playerName;
                        if (lastDamager.GetComponent <PhotonView>())
                        {
                            playerName = lastDamager.GetComponent <PhotonView>().Owner.NickName;
                        }
                        else
                        {
                            playerName = lastDamager.transform.GetComponentInParent <PhotonView>().Owner.NickName;
                        }
                        deathMessage = deathMessage.Replace("{Damager}", playerName);
                    }
                    else
                    {
                        deathMessage = deathMessage.Replace("{Damager}", lastDamager.name.Replace("(Clone)", ""));
                    }
                }
                else
                {
                    deathMessage = deathMessage.Replace("{Damager}", "a unknown damager");
                }
                BroadCastMessage message = new BroadCastMessage(
                    "DEATH",
                    deathMessage
                    );
                NetworkManager.networkManager.GetChabox().BroadcastData(
                    NetworkManager.networkManager.GetChatDataChannel(),
                    message
                    );
            }
            if (visualCountdown != null)
            {
                respawnVisual = Instantiate(visualCountdown) as GameObject;
                respawnVisual.SendMessage("StartCounting", respawnDelay);
            }
            respawnPoint = SelectRespawnPoint(playerView);
            yield return(new WaitForSeconds(respawnDelay));

            if (respawnVisual != null)
            {
                Destroy(respawnVisual);
            }
            PhotonNetwork.Destroy(playerView);
            if (!playerView.GetComponentInChildren <vInventory>() && FindObjectOfType <vInventory>())
            {
                Destroy(FindObjectOfType <vInventory>().gameObject);
            }
            yield return(new WaitForEndOfFrame());

            GameObject newPlayer = NetworkManager.networkManager.NetworkInstantiatePrefab(
                NetworkManager.networkManager.playerPrefab.name,
                respawnPoint.position,
                respawnPoint.rotation,
                0
                );

            FindObjectOfType <vThirdPersonCamera>().target           = (newPlayer.GetComponentInChildren <vLookTarget>()) ? newPlayer.GetComponentInChildren <vLookTarget>().transform : newPlayer.transform;
            newPlayer.GetComponent <vThirdPersonController>().isDead = false;
            if (FindObjectOfType <vGameController>())
            {
                vGameController gc = FindObjectOfType <vGameController>();
                if (gc != null)
                {
                    gc.currentPlayer = newPlayer;
                }
            }
            yield return(new WaitForFixedUpdate());

            if (keepItems == true)
            {
                NetworkManager.networkManager.LoadPlayerData(
                    playerView.Owner.NickName,
                    newPlayer.GetComponent <vThirdPersonController>(),
                    false,
                    true,
                    true
                    );
            }
        }
Example #5
0
        public void Receive(BroadCastMessage message)
        {
            Form1 frm = Application.OpenForms[0] as Form1;

            frm.ShowMsg("Action:" + message.Action + "    Body:" + message.Body);
        }