本文是解释鹰大的多人联网实例example1思路,由于自己理解的问题,不足地方请斧正。。。
------------------------------------------华丽的分割线--------------------------------------------
主线流程
1. awake 【设计游戏窗口 获取玩家名字】
function Awake(){
//开辟聊天的窗口
window = Rect(Screen.width/2-width/2, Screen.height-height+5, width, height);
//We get the name from the masterserver example, if you entered your name there ;).
//**********************************************masterserver不了解;[14.3.30
playerName = PlayerPrefs.GetString("playerName", "");
if(!playerName || playerName==""){
playerName = "RandomName"+Random.Range(1,999);
}
}
2. ongui 【判断是否显示聊天窗口 创建聊天窗口 处理回车[获取输入焦点]】
function OnGUI ()
{
//显示聊天窗口时【连接到服务器的客户端,初始化后的服务器】才绘制聊天窗口
if(!showChat){
return;
}
GUI.skin = skin;
//当前处理的事件如果是按键按下 并且按下的按键是回车键 并且未有输入值【没输入时按回车键】
if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length <= 0)
{
//如果上次释放屏幕到现在超过0.25秒
if(lastUnfocusTime+0.25<Time.time){
usingChat=true;
//5号窗口【聊天窗口】锁定为活动窗口
GUI.FocusWindow(5);
//焦点放到输入框
GUI.FocusControl("Chat input field");
}
}
//创建5号弹出窗口【聊天窗口】 标题为空
window = GUI.Window (5, window, GlobalChatWindow, "");
}
3. 创建聊天窗口 【创建滚动条 滚动条中从对话表中逐句读取对话处理回车[传出对话]以及鼠标左键[失焦并停止对话显示]效果】
//创建窗口的函数
function GlobalChatWindow (id