Пример #1
0
 // 取消注册
 public static void unRegister(string router, UTodoServerClient client)
 {
     if (observers.ContainsKey(router))
     {
         observers[router].Remove(client);
     }
 }
Пример #2
0
        public static void route(string route, UTodoJsonObject jsonObject, UTodoServerClient client)
        {
            string[] routes     = route.Split('.');
            string   type       = routes[0];
            string   typeName   = routes[1];
            string   methodName = routes[2];

            routeType(type, typeName, methodName, jsonObject, client);
        }
Пример #3
0
        public static void ReadMessage(string content, UTodoServerClient client)   // 包含路由和数据 和客户端定制相同的规则
        {
            // "type.classname.methodname|data" 数据格式
            string[]        routeAndData = content.Split('|');
            string          route        = routeAndData[0];
            string          data         = routeAndData[1].Replace("<EOF>", "");
            UTodoJsonObject jsonObject   = JsonUtility.FromJson <UTodoJsonObject>(data);

            UTodoRouter.route(route, jsonObject, client);
        }
Пример #4
0
 // 注册
 public static void register(string router, UTodoServerClient client)
 {
     if (observers.ContainsKey(router))
     {
         observers[router].Add(client);
     }
     else
     {
         observers.Add(router, new List <UTodoServerClient>()
         {
             client
         });
     }
 }
Пример #5
0
 public void Remove(UTodoServerClient client)
 {
     clients.Remove(client);
 }
Пример #6
0
 public void Add(UTodoServerClient client)
 {
     clients.Add(client);
 }
Пример #7
0
 private static void on(string typeName, string methodName, UTodoServerClient client)
 {
     Debug.Log("client on : " + typeName + "." + methodName);
     UTodoObserver.register(typeName + "." + methodName, client);
 }
Пример #8
0
        private static void routeType(string type, string typeName, string methodName, UTodoJsonObject jsonObject, UTodoServerClient client)
        {
            switch (type)
            {
            case "request":     // 要求即时返回数据
                request(typeName, methodName, jsonObject);
                break;

            case "notify":      // 无需返回数据
                notify(typeName, methodName, jsonObject);
                break;

            case "on":          // 客户端监听服务器事件
                on(typeName, methodName, client);
                break;
            }
        }