• 聊天室代码


    private var chatWindow = Rect(350,50,200,300);
    private var scrollPosition : Vector2;
    private var inputField = "";
    private var entries = ArrayList();

    class ChatEntry
    {
       var text = "";
       var sender = "";
    }

    function OnGUI()
    {
      chatWindow = GUI.Window(1,chatWindow,ChatWindowGUI,"Chat");
    }

    function ChatWindowGUI(id: int)
    {
       scrollPosition = GUILayout.BeginScrollView(scrollPosition);
      // GUILayout.Label("Test");
       for(var entry:ChatEntry in entries)
       {
         GUILayout.Label(entry.sender+":"+entry.text);
       }
       GUILayout.EndScrollView();
      
       if(Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length >0)
       {
         ApplyTextLocal(inputField);
         networkView.RPC("ApplyTextGlobal",RPCMode.Others,inputField);
         inputField = "";
       }
      
       inputField = GUILayout.TextField(inputField);
      
       GUI.DragWindow();
    }

    function ApplyTextLocal(newText : String)
    {
       var entry = new ChatEntry();
       entry.text = newText;
       entry.sender = "Me";
      
       entries.Add(entry);
       scrollPosition.y = 10000;
    }

    @RPC
    function ApplyTextGlobal(newText : String,msg :NetworkMessageInfo)
    {
       var entry = new ChatEntry();
       entry.text = newText;
       entry.sender = msg.sender.ToString();;
      
       entries.Add(entry);
       scrollPosition.y = 10000;
    }

  • 相关阅读:
    MC9S12 硬件设计
    ESD
    选用与使用稳压二极管的介绍
    MOSFET 栅极电阻作用及其选型
    orcad常用库文件介绍
    开关电源和LDO的区别
    续流二极管的作用及选型
    为什么大电容滤低频小电容滤高频的问题
    Java常用API——时间类
    Idea问题:“marketplace plugins are not loaded”解决方案
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2144743.html
Copyright © 2020-2023  润新知