public void Init(ChatApi chatApi) { this.chatApi = chatApi; // Gui component. chatbox = this.gameObject.AddComponent<Chatbox>() as Chatbox; chatbox.CloseChatWindow(); // The messaging actor messenger = ActorSystem.instance.Find("Messenger") as Messenger; // Parses the chat language used by the gui and calls messenger // Feel free to provide your own implementation, this is mostly a starting point. // Supported syntax is documented in the source chatCommands = new ChatCommands(messenger, chatbox); chatCommands.SetChatApi(chatApi); // Setup callacks so we get notified when we join/leave channels and receive messages Messenger.ChannelJoined channelCallback = ChannelJoined; messenger.OnChannelJoined(channelCallback); Messenger.ChannelLeft channelLeftCallback = ChannelLeft; messenger.OnChannelLeft(channelLeftCallback); Messenger.MessageReceived messageCallback = MessageReceived; messenger.OnMessageReceived(messageCallback); Messenger.InviteReceived inviteCallback = InviteReceived; messenger.OnInviteReceived(inviteCallback); // Send this whenever you want a list of subscribed channels, and the optional // subscriber list if you have set the subscribers flag. We do it on an interval // so that you get notified when new players join a group you are in. // For matchmaking you probably want this value lower so it appears more // responsive. For mmo type games it could be somewhat higher. InvokeRepeating("UpdateChatStatus", 0.01f, 5.0F); }
void Start() { canvas = gameObject.GetComponent<Canvas>() as Canvas; canvas.enabled = false; scrollbar = GameObject.Find("chat_scrollbar"); contentHolder = GameObject.Find("chat_text"); messageTemplate = transform.Find("msg_template").gameObject; messageTemplate.SetActive(false); groupContainer = GameObject.Find("group_container"); groupMemberContainer = GameObject.Find("group_member_container"); groupMemberTemplate = GameObject.Find("group_member"); groupMemberTemplate.SetActive(false); groupContainer.SetActive(false); chatInput = GameObject.Find("chat_input").GetComponent<InputField>() as InputField; playerId = GameEntityManager.GetPlayerEntity().GetEntityId(); characterId = GameEntityManager.GetPlayerEntity().GetCharacterId(); messenger = ActorSystem.instance.Find("Messenger") as Messenger; chatCommandHandler = new ChatCommandHandler(messenger, this, playerId); Messenger.ChannelJoined channelCallback = ChannelJoined; messenger.OnChannelJoined(channelCallback); Messenger.ChannelLeft channelLeftCallback = ChannelLeft; messenger.OnChannelLeft(channelLeftCallback); Messenger.MessageReceived messageCallback = MessageReceived; messenger.OnMessageReceived(messageCallback); Messenger.InviteReceived inviteCallback = InviteReceived; messenger.OnInviteReceived(inviteCallback); foreach (string channel in autojoinChannels) { messenger.JoinChannel(channel); } InvokeRepeating("UpdateChatStatus", 0.01f, 2.0F); }