initial upload
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Boo.Lang;
|
||||
using Boo.Lang.Runtime;
|
||||
using UnityEngine;
|
||||
using UnityScript.Lang;
|
||||
|
||||
[Serializable]
|
||||
public class Chat : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
internal sealed class _0024FocusControl_002449 : GenericGenerator<object>
|
||||
{
|
||||
[Serializable]
|
||||
internal sealed class _0024 : GenericGeneratorEnumerator<object>, IEnumerator
|
||||
{
|
||||
public override bool MoveNext()
|
||||
{
|
||||
int result;
|
||||
switch (_state)
|
||||
{
|
||||
default:
|
||||
result = (YieldDefault(2) ? 1 : 0);
|
||||
break;
|
||||
case 2:
|
||||
result = (YieldDefault(3) ? 1 : 0);
|
||||
break;
|
||||
case 3:
|
||||
GUI.FocusControl("Chat input field");
|
||||
YieldDefault(1);
|
||||
goto case 1;
|
||||
case 1:
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
return (byte)result != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator<object> GetEnumerator()
|
||||
{
|
||||
return new _0024();
|
||||
}
|
||||
}
|
||||
|
||||
public GUISkin skin;
|
||||
|
||||
public bool showChat;
|
||||
|
||||
private string inputField;
|
||||
|
||||
private bool display;
|
||||
|
||||
private ArrayList entries;
|
||||
|
||||
private Vector2 scrollPosition;
|
||||
|
||||
private Rect window;
|
||||
|
||||
public Chat()
|
||||
{
|
||||
inputField = string.Empty;
|
||||
display = true;
|
||||
entries = new ArrayList();
|
||||
window = new Rect(50f, 50f, 200f, 300f);
|
||||
}
|
||||
|
||||
public virtual void CloseChatWindow()
|
||||
{
|
||||
showChat = false;
|
||||
inputField = string.Empty;
|
||||
entries = new ArrayList();
|
||||
}
|
||||
|
||||
public virtual IEnumerator FocusControl()
|
||||
{
|
||||
return new _0024FocusControl_002449().GetEnumerator();
|
||||
}
|
||||
|
||||
public virtual void OnGUI()
|
||||
{
|
||||
GUI.skin = skin;
|
||||
if (GUI.Button(new Rect(Screen.width - 100, Screen.height - 30, 90f, 20f), (!showChat) ? "Show Chat" : "Hide Chat"))
|
||||
{
|
||||
if (showChat)
|
||||
{
|
||||
CloseChatWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
showChat = true;
|
||||
StartCoroutine(FocusControl());
|
||||
}
|
||||
}
|
||||
if (showChat)
|
||||
{
|
||||
window = GUI.Window(1, window, GlobalChatWindow, "Chat");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void GlobalChatWindow(int id)
|
||||
{
|
||||
GUIStyle style = GUI.skin.GetStyle("close_button");
|
||||
if (GUI.Button(new Rect(4f, 4f, style.normal.background.width, style.normal.background.height), string.Empty, "close_button"))
|
||||
{
|
||||
CloseChatWindow();
|
||||
}
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
|
||||
IEnumerator enumerator = UnityRuntimeServices.GetEnumerator(entries);
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
object obj = enumerator.Current;
|
||||
if (!(obj is ChatEntry))
|
||||
{
|
||||
obj = RuntimeServices.Coerce(obj, typeof(ChatEntry));
|
||||
}
|
||||
ChatEntry chatEntry = (ChatEntry)obj;
|
||||
GUILayout.BeginHorizontal();
|
||||
if (!chatEntry.mine)
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label(chatEntry.text, "chat_rightaligned");
|
||||
UnityRuntimeServices.Update(enumerator, chatEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label(chatEntry.text, "chat_leftaligned");
|
||||
UnityRuntimeServices.Update(enumerator, chatEntry);
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(3f);
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
if (Event.current.type == EventType.KeyDown && Event.current.character == '\n' && inputField.Length > 0)
|
||||
{
|
||||
ApplyGlobalChatText(inputField, 1);
|
||||
GetComponent<NetworkView>().RPC("ApplyGlobalChatText", RPCMode.Others, inputField, 0);
|
||||
inputField = string.Empty;
|
||||
}
|
||||
GUI.SetNextControlName("Chat input field");
|
||||
inputField = GUILayout.TextField(inputField);
|
||||
GUI.DragWindow();
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
if (Input.GetKeyDown("t"))
|
||||
{
|
||||
showChat = true;
|
||||
StartCoroutine(FocusControl());
|
||||
}
|
||||
}
|
||||
|
||||
[RPC]
|
||||
public virtual void ApplyGlobalChatText(string str, int mine)
|
||||
{
|
||||
ChatEntry chatEntry = new ChatEntry();
|
||||
chatEntry.sender = "Not implemented";
|
||||
chatEntry.text = str;
|
||||
if (mine == 1)
|
||||
{
|
||||
chatEntry.mine = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
chatEntry.mine = false;
|
||||
}
|
||||
entries.Add(chatEntry);
|
||||
if (entries.Count > 50)
|
||||
{
|
||||
entries.RemoveAt(0);
|
||||
}
|
||||
scrollPosition.y = 1000000f;
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user