Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TwitchChatter;
- public class networking : MonoBehaviour
- {
- public SortedList<string, sync> players = new SortedList<string, sync>();
- public SortedList<string, sync> netobjs = new SortedList<string, sync>();
- //3 channels - chat/data/world (has start and stop gaps and requests)
- public string chatchan = "NeverdauntRL", datachan = "NeverdauntRLdata", worldchan = "NeverdauntRLworld";
- void Start()
- {
- // Add a chat listener.
- TwitchChatClient.singleton.AddChatListener(OnChatMessage);
- // Set your credentials. If you're not planning on sending messages,
- //// you can remove these lines.
- togsave.isOn = PlayerPrefs.GetInt("save", 1) == 1;
- //// Join some channels.
- //TwitchChatClient.singleton.JoinChannel("SomeChannelName");
- if (togsave.isOn)
- {
- oauth.text = PlayerPrefs.GetString("oauth", "");
- username.text = PlayerPrefs.GetString("user", "");
- }
- }
- public UnityEngine.UI.InputField infi;
- public GameObject loginpan;
- public UnityEngine.UI.InputField username, oauth;
- public UnityEngine.UI.Toggle togsave;
- public void Login()
- {
- if (togsave.isOn)
- {
- PlayerPrefs.SetString("user", username.text);
- PlayerPrefs.SetString("oauth", oauth.text);
- PlayerPrefs.SetInt("save", 1);
- }
- else
- {
- PlayerPrefs.SetString("user", "");
- PlayerPrefs.SetString("oauth", "");
- PlayerPrefs.SetInt("save", 0);
- }
- PlayerPrefs.Save();
- loginpan.SetActive(false);
- TwitchChatClient.singleton.userName = username.text;
- TwitchChatClient.singleton.oAuthPassword = oauth.text;
- infi.Select();
- infi.ActivateInputField();
- TwitchChatClient.singleton.JoinChannel(chatchan);
- // TwitchChatClient.singleton.JoinChannel(worldchan);
- // TwitchChatClient.singleton.JoinChannel(datachan);
- // If you set your credentials and you'd like to receive whispers,
- // call EnableWhispers to allow for sending/receiving whispers.
- // TwitchChatClient.singleton.EnableWhispers();
- // Then, add any whisper listeners you'd like.
- // TwitchChatClient.singleton.AddWhisperListener(OnWhisper);
- }
- //void Chat()
- //{
- // // If you set your credentials, send some messages.
- // TwitchChatClient.singleton.SendMessage("SomeChannelName", "Kappa Message sent by Twitch Chatter! Kappa");
- //}
- //void Whisper()
- //{
- // // If you set your credentials and enabled whispers with EnableWhispers(), send some whispers.
- // TwitchChatClient.singleton.SendWhisper("SomeUserName", "PogChamp Sending a whisper through Twitch Chatter! PogChamp");
- //}
- void Cleanup()
- {
- // When you're done, leave the channels and remove the chat listeners.
- TwitchChatClient.singleton.LeaveChannel(chatchan);
- TwitchChatClient.singleton.RemoveChatListener(OnChatMessage);
- // Also remove any whisper listeners you've added.
- // TwitchChatClient.singleton.RemoveWhisperListener(OnWhisper);
- }
- // You'd define your chat message callback like this:
- public void OnChatMessage(ref TwitchChatMessage msg)
- {
- // Do something with the message here.
- if (msg.channelName == datachan)
- {
- string[] ii = msg.chatMessagePlainText.Split(' ');
- switch (ii[0])
- {
- case "m":
- //move
- break;
- }
- if (msg.userName == chatchan)
- {
- //this is a athoritive msg
- }
- else
- {
- }
- }
- else if (msg.channelName == worldchan)
- {
- }
- else if (msg.channelName == chatchan)
- {
- }
- }
- // You'd define your whisper callback like this:
- public void OnWhisper(ref TwitchChatMessage msg)
- {
- // Do something with the whisper here.
- }
- }
- ====================================================================================================
- ====================================================================================================
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public class submitcommand : MonoBehaviour
- {
- UnityEngine.UI.InputField infi;
- void Start()
- {
- infi = GetComponent<UnityEngine.UI.InputField>();
- }
- public void cmd(string i)
- {
- if (i != "")
- {
- // print(i);
- infi.text = "";
- infi.Select();
- infi.ActivateInputField();
- string[] ii = i.ToLower().Split(' ');
- switch (ii[0])
- {
- case "say":
- print(i);
- TwitchChatClient.singleton.SendMess(TwitchChatClient.singleton.net.chatchan, i.Remove(0, 4));
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement