Exemplo n.º 1
0
    public void GenerateHelp()
    {
        UIChatMessage newMessage = Instantiate(chatMessagePrefab);

        newMessage.GetComponent <RectTransform>().SetParent(contentPanel.GetComponent <RectTransform>(), false);

        newMessage.MessageText.color = Color.yellow;
        newMessage.MessageText.text  = "Help content here.\n<b>/help</b> to view this info again.\n<b>/team</b> to change your message target to team chat\n<b>/all</b> to change your message target to all chat\nTo call some other function, add it to the <b><i>Commands</i></b> list on the Unity Inspector and tie it to some function.\nBecause this Chat Entry has <b>Rich Text</b> support, you can do\n<size=24>a lot</size> of <size=33><color=orange>f</color><color=red>a</color><color=lime>n</color><color=cyan>c</color><color=fuchsia>y</color> formatting</size> here as well.";
        messagesOnUI.Add(newMessage);

        //this will try to hide the chat after 10 seconds. If a new message comes in, the timeLastChatEntryHappened will be updated so still we should have DELAY_BEFORE_HIDING_CHAT seconds before it hides
        Debug.Log("Going to invoke TryToHideChat in " + DELAY_BEFORE_HIDING_CHAT + " seconds. @(" + (Time.time + DELAY_BEFORE_HIDING_CHAT) + ")");
        Invoke("TryToHideChat", DELAY_BEFORE_HIDING_CHAT);
        timeLastChatEntryHappened = Time.time;

        //frequently the last message is not properly scrolled into view due to some internals of Unity UI, putting a brief delay ensures proper scrolling
        Invoke("ScrollToBottom", 0.15f);
    }
Exemplo n.º 2
0
    //Uncomment this only if you are going to maintain a local cache of players and are using a custom NetworkManager. See below for more information
    //[Command]
    //public void CmdOnPlayerConnectOrDisconnect()
    //{
    //    cachedPlayers = new List<PlayerController>(GameObject.FindObjectsOfType<PlayerController>());
    //}

    /* If you want to maintain the player list within this ChatSystem (which is much better in terms of performance)
     * you will need to create a new NetworkManager class, for example:
     * public class DefaultNetworkManager : NetworkManager
     * {
     *  public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
     *  {
     *      //we want to do the normal stuff first so our player should be initialized
     *      base.OnServerAddPlayer(conn, playerControllerId);
     *      chatSystem.CmdOnPlayerConnectOrDisconnect();
     *  }
     *
     *  public override void OnClientDisconnect(NetworkConnection conn)
     *  {
     *      //we do want to do our stuff before the standard things so we still have the player object
     *      chatSystem.CmdOnPlayerConnectOrDisconnect();
     *      base.OnClientDisconnect(conn);
     *  }
     * }
     *
     * Then in the editor, set this script as the NetworkManager script.
     * After you have done that, uncomment the lines relating the cachedPlayers in this script
     * and it should be working.
     */

    private void CreatePrefabAndAddToScreen(ChatEntry message)
    {
        UIChatMessage newMessage = Instantiate(chatMessagePrefab);

        newMessage.GetComponent <RectTransform>().SetParent(contentPanel.GetComponent <RectTransform>(), false);

        newMessage.MessageText.text  = "<color=\"" + GetHexValueForColor(chatChannels.Find(channel => channel.Channel == message.Channel).color) + "\">" + "(" + chatChannels.Find(channel => channel.Channel == message.Channel).Name + ") " + message.SenderName + ":</color> ";
        newMessage.MessageText.color = Color.white;
        newMessage.MessageText.text += message.Message;
        messagesOnUI.Add(newMessage);

        //this will try to hide the chat after 10 seconds. If a new message comes in, the timeLastChatEntryHappened will be updated so still we should have DELAY_BEFORE_HIDING_CHAT seconds before it hides
        Debug.Log("Going to invoke TryToHideChat in " + DELAY_BEFORE_HIDING_CHAT + " seconds. @(" + (Time.time + DELAY_BEFORE_HIDING_CHAT) + ")");
        Invoke("TryToHideChat", DELAY_BEFORE_HIDING_CHAT);
        timeLastChatEntryHappened = Time.time;

        //frequently the last message is not properly scrolled into view due to some internals of Unity UI, putting a brief delay ensures proper scrolling
        Invoke("ScrollToBottom", 0.15f);
    }