Advertisement
ChaosTheosis

InRoomChat

Jan 30th, 2015
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.41 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2. using System.CodeDom.Compiler;
  3. using System.IO;
  4. using Photon;
  5. using System;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8.  
  9. public class InRoomChat : Photon.MonoBehaviour
  10. {
  11.     private bool AlignBottom = true;
  12.     public static readonly string ChatRPC = "Chat";
  13.     public static Rect GuiRect = new Rect(0f, 100f, 300f, 470f);
  14.     public static Rect GuiRect2 = new Rect(30f, 575f, 300f, 25f);
  15.     private string inputLine = string.Empty;
  16.     public bool IsVisible = true;
  17.     public static List<string> messages = new List<string>();
  18.     private Vector2 scrollPos = Vector2.zero;
  19.  
  20.     public void addLINE(string newLine)
  21.     {
  22.         messages.Add(newLine);
  23.     }
  24.  
  25.     public void AddLine(string newLine)
  26.     {
  27.         messages.Add(newLine);
  28.     }
  29.  
  30.     public void OnGUI()
  31.     {
  32.         if (this.IsVisible && (PhotonNetwork.connectionStateDetailed == PeerState.Joined))
  33.         {
  34.             if ((Event.current.type == EventType.KeyDown) && ((Event.current.keyCode == KeyCode.KeypadEnter) || (Event.current.keyCode == KeyCode.Return)))
  35.             {
  36.                 if (!string.IsNullOrEmpty(this.inputLine))
  37.                 {
  38.                     if (!this.inputLine.StartsWith("/"))                
  39.                     {
  40.                         foreach (string name in System.IO.File.ReadAllLines(@"chatname.cfg"))
  41.                         {
  42.                             if (name.StartsWith("chatname="))
  43.                             {
  44.                                 string chatname = name.Replace("chatname=", "");                        
  45.                                 GameObject.Find("MultiplayerManager").GetComponent<FengGameManagerMKII>().photonView.RPC("Chat", PhotonTargets.All, new object[] { this.inputLine, chatname });
  46.                                 break;
  47.                             }
  48.                         }
  49.                     }
  50.                     if (this.inputLine == "\t")
  51.                     {
  52.                         this.inputLine = string.Empty;
  53.                         GUI.FocusControl(string.Empty);
  54.                         return;
  55.                     }                                                                                                              
  56.                    if ((this.inputLine == "/restart") && PhotonNetwork.isMasterClient)
  57.                       {                                
  58.                     GUI.FocusControl(string.Empty);
  59.                     GameObject.Find("MultiplayerManager").GetComponent<FengGameManagerMKII>().restartGame(false);
  60.                     return;
  61.                     }              
  62.                   if (this.inputLine.StartsWith("/kick #"))
  63.                         {
  64.                             int iD = Convert.ToInt32(this.inputLine.Remove(0, 7));
  65.                             if (PhotonNetwork.isMasterClient)
  66.                             {
  67.                                 PhotonNetwork.CloseConnection(PhotonPlayer.Find(iD));                                                            
  68.                     }
  69.                 }
  70.                     this.inputLine = string.Empty;
  71.                     GUI.FocusControl(string.Empty);
  72.                     return;
  73.                 }
  74.                 this.inputLine = "\t";
  75.                 GUI.FocusControl("ChatInput");
  76.             }
  77.             GUI.SetNextControlName(string.Empty);
  78.             GUILayout.BeginArea(GuiRect);
  79.             GUILayout.FlexibleSpace();
  80.             string text = string.Empty;
  81.             if (messages.Count < 10)
  82.             {
  83.                 for (int i = 0; i < messages.Count; i++)
  84.                 {
  85.                     text = text + messages[i] + "\n";
  86.                 }
  87.             }
  88.             else
  89.             {
  90.                 for (int j = messages.Count - 10; j < messages.Count; j++)
  91.                 {
  92.                     text = text + messages[j] + "\n";
  93.                 }
  94.             }
  95.             GUILayout.Label(text, new GUILayoutOption[0]);
  96.             GUILayout.EndArea();
  97.             GUILayout.BeginArea(GuiRect2);
  98.             GUILayout.BeginHorizontal(new GUILayoutOption[0]);
  99.             GUI.SetNextControlName("ChatInput");
  100.             this.inputLine = GUILayout.TextField(this.inputLine, new GUILayoutOption[0]);
  101.             GUILayout.EndHorizontal();
  102.             GUILayout.EndArea();
  103.         }          
  104.     }
  105.    
  106.     public void setPosition()
  107.     {
  108.         if (this.AlignBottom)
  109.         {
  110.             GuiRect = new Rect(0f, (float) (Screen.height - 500), 300f, 470f);
  111.             GuiRect2 = new Rect(30f, (float) ((Screen.height - 300) + 0x113), 300f, 25f);
  112.         }
  113.     }
  114.  
  115.     public void Start()
  116.     {
  117.         this.setPosition();
  118.     }  
  119.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement