- Home /
Question by
centilmen50 · Feb 05, 2014 at 12:05 AM ·
scriptingproblem
Pressing the enter key to chat script writing TextField How can I activate?
Pressing enter my chat script to write TextField How can I activate?
DontDestroyOnLoad(this);
var mySkin : GUISkin;
private var gameNameType = "UnityChat"; // leave this alone. then we will see all other builds of this example
var myGameName : String = "thylaxene's Chat";
var gameDesc : String = "Very Basic Chat App";
var userName : String;
private var timeoutHostList = 0.0;
private var lastHostListRequest = -1000.0;
private var hostListRefreshTimeout = 10.0;
public var serverPort = 25002;
private var natCapable : ConnectionTesterStatus;
private var filterNATHosts = false;
private var doneProbingPublicIP = false;
private var hideTest = true;
private var windowRect = Rect (-110,40,100,50);
private var windowRectT = Rect (100,290,200,300);
var scrollViewVector : Vector2;
private var outputText : String = "";
private var yourInputText : String = "";
// Enable this if not running a client on the server machine
//MasterServer.dedicatedServer = true;
function OnFailedToConnectToMasterServer(info: NetworkConnectionError) {
Debug.Log(info);
}
function OnFailedToConnect(info: NetworkConnectionError) {
Debug.Log(info);
}
function OnDisconnectedFromServer (info: NetworkDisconnection) {
Debug.Log(info);
}
function OnServerInitialized () {
networkView.RPC ("SendMessage", RPCMode.AllBuffered, (userName + " Baglandi"));
}
function OnConnectedToServer () {
networkView.RPC ("SendMessage", RPCMode.All, (userName + " Baglandi"));
}
function OnGUI () {
GUI.skin = mySkin;
windowRect = GUILayout.Window (0, windowRect, MakeWindow, "Giris Kontrolu");
windowRectT = GUILayout.Window (1, windowRectT, MakeTranscriptWindow, "Chat Alani");
}
function Awake () {
// Start connection test
natCapable = Network.TestConnection();
// What kind of IP does this machine have? TestConnection also indicates this in the
// test results
if (Network.HavePublicAddress())
Debug.Log("This machine has a public IP address");
else
Debug.Log("This machine has a private IP address");
}
function MakeTranscriptWindow () {
GUILayout.Label ("Mesajlar:");
scrollViewVector = GUILayout.BeginScrollView (scrollViewVector);
GUILayout.TextArea (outputText);
GUILayout.EndScrollView();
GUILayout.Label("Mesajin: ");
yourInputText = GUILayout.TextField (yourInputText);
if (GUILayout.Button ("Gonder")) {
networkView.RPC ("SendMessage", RPCMode.All, yourInputText);
yourInputText = "";
}
GUI.DragWindow (Rect (0,0,1000,1000));
}
// this is where the magic is. when this function is called via networkView.RPC
// everyone's chat log is updated
@RPC
function SendMessage (text : String) {
outputText += (text + "\n");
}
function Update() {
if(Input.GetKeyDown(KeyCode.Escape))
mert = !SendMessage;
if(Input.GetKeyDown(KeyCode.Return))
networkView.RPC ("SendMessage", RPCMode.All, yourInputText);
}
function MakeWindow (id : int) {
GUILayout.BeginHorizontal ();
GUILayout.Label ("Adiniz:");
userName = GUILayout.TextField (userName);
GUILayout.EndHorizontal ();
hideTest = GUILayout.Toggle(hideTest, "Ellesme");
if (!hideTest) {
// Start/Poll the connection test, report the results in a label and react to the results accordingly
natCapable = Network.TestConnection();
if (natCapable == -2)
GUILayout.Label("Problem determining NAT capabilities");
else if (natCapable == -1)
GUILayout.Label("Undetermined NAT capabilities");
else if (natCapable == 0) {
GUILayout.Label("Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, impossible to run a server.");
filterNATHosts = true;
Network.useNat = false;
}
else if (natCapable == 1) {
if (doneProbingPublicIP)
GUILayout.Label("Non-connectable public IP address (port "+ serverPort +" blocked), NAT punchthrough can circumvent the firewall.");
else
GUILayout.Label("NAT punchthrough capable. Enabling NAT punchthrough functionality.");
// NAT functionality is enabled in case a server is started, clients enable this based on if the host requires it
Network.useNat = true;
} else if (natCapable == 2) {
GUILayout.Label("Directly connectable public IP address.");
Network.useNat = false;
} else if (natCapable == 3) {
GUILayout.Label("Non-connectble public IP address (port " + serverPort +" blocked), running a server is impossible.");
Network.useNat = false;
if (!doneProbingPublicIP) {
natCapable = Network.TestConnectionNAT();
doneProbingPublicIP = true;
}
}
else if (natCapable == 4) {
GUILayout.Label("Public IP address but server not initialized, it must be started to check server accessibility.");
Network.useNat = false;
}
if (GUILayout.Button ("Retest connection")) {
Debug.Log("Redoing connection test");
doneProbingPublicIP = false;
natCapable = Network.TestConnection(true);
}
}
if (Network.peerType == NetworkPeerType.Disconnected) {
GUILayout.BeginHorizontal();
GUILayout.Space(10);
// Start a new server
if (GUILayout.Button ("Chat'e Baglan")) {
Network.InitializeServer(32, serverPort);
MasterServer.RegisterHost(gameNameType, myGameName, gameDesc);
}
// Refresh hosts
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(5);
var data : HostData[] = MasterServer.PollHostList();
for (var element in data) {
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !(filterNATHosts && element.useNat) ) {
var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
GUILayout.Label(name);
GUILayout.Space(5);
var hostInfo;
hostInfo = "[";
for (var host in element.ip) {
hostInfo = hostInfo + host + ":" + element.port + " ";
}
hostInfo = hostInfo + "]";
//GUILayout.Label("[" + element.ip + ":" + element.port + "]");
GUILayout.Label(hostInfo);
GUILayout.Space(5);
GUILayout.Label(element.comment);
GUILayout.Space(5);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Giris Yap")) {
// Enable NAT functionality based on what the hosts if configured to do
Network.useNat = element.useNat;
if (Network.useNat)
print("Using Nat punchthrough to connect");
else
print("Connecting directly to host");
Network.Connect(element.ip, element.port);
}
}
GUILayout.EndHorizontal();
}
} else {
GUILayout.FlexibleSpace();
}
GUI.DragWindow (Rect (0,0,1000,1000));
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Raycast Destroys player. 1 Answer
GUI cale and position according to the actual screen resolution. 1 Answer
GUI.HorizontalSlider not working 2 Answers
How To Make GUI Buttons Load/Quit 1 Answer