private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Q))
     {
         //var t = Input.GetAccelerationEvent(0);
         Framework.FrameworkUtils.Application.Exit();
     }
     if (networkData.Count > 0)
     {
         var obj = networkData.Dequeue();
         ProtocolProcessor.MessagePump(obj);
     }
     sv.Update();
     if (Input.GetKeyDown(KeyCode.X))
     {
         target = true;
     }
     if (Input.GetKeyUp(KeyCode.X))
     {
         target = false;
     }
     if (Input.GetKeyDown(KeyCode.K))
     {
         sv.Negative = true;
     }
     if (Input.GetKeyUp(KeyCode.K))
     {
         sv.Negative = false;
     }
 }
        private void Start()
        {
            /**
             * GameConsole.Instance.OnCommand += cmd =>
             * {
             *      switch (cmd)
             *      {
             *              case "1":
             *                      cmd = "connect 127.0.0.1 8192";
             *                      break;
             *              case "2":
             *                      cmd = "login kedlly zhaoxionghui";
             *                      break;
             *              case "3":
             *                      cmd = "login uav 123456";
             *                      break;
             *              case "4":
             *                      cmd = "login robot 123456";
             *                      break;
             *              default:
             *                      break;
             *      }
             *
             *      var cmds = cmd.Split(' ', '\t');
             *
             *      if (cmds[0] == "connect")
             *      {
             *              var ip = cmds[1];
             *              var port = int.Parse(cmds[2]);
             *              Debug.Log("try to connect ip: " + ip + " port :" + port);
             *              NetworkManager.Instance.Connect(ip, port);
             *      }
             *      if (cmds[0] == "login")
             *      {
             *              var name = cmds[1];
             *              var password = cmds[2];
             *              var dataObject = new Request_LoginAuth();
             *              dataObject.username = name;
             *              dataObject.password = password;
             *
             *              System.ArraySegment<byte> p = new System.ArraySegment<byte>(buffer);
             *              dataObject.Pack().Serialize(p).Send();
             *
             *              //dataObject.Pack().Serialize().Send();
             *      }
             *      if (cmds[0] == "quality")
             *      {
             *              QualitySettings.SetQualityLevel(int.Parse(cmds[1]));
             *      }
             *      if (cmds[0] == "print")
             *      {
             *              if (cmds[1] == "frameTime")
             *              {
             *                      Debug.Log("deltaTime :"+Time.deltaTime + " fixedDeltaTime "+ Time.fixedDeltaTime);
             *              }
             *      }
             *      if (cmds[0] == "f")
             *      {
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "0123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "1OOOOOOOOOOOOOOO"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "2123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "3KKKKKKKKKKKKKKK"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "4123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "5TTTTTTTTTTTTTTT"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "6123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "7RRRRRRRRRRRRRRR"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "8123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "9MMMMMMMMMMMMMMM"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "a123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "bPPPPPPPPPPPPPPP"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "c123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "d123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "e123456789abcdef"))).Send();
             *              (new System.ArraySegment<byte>(System.Text.Encoding.Default.GetBytes(index + "f123456789abcdef"))).Send();
             *              index++;
             *      }
             * };
             */
            Framework.FrameworkUtils.Application.Console.OnText += delegate(string s)
            {
                Debug.Log(s);
            };

            var pbf2 = new Factory <PostObject>().CreatePool();

            pbf2.Allocate();
            pbf2.Allocate();

//          var pbf = new Factory2();
//          pbf.Allocate();
//          pbf.Allocate();

            Framework.FrameworkUtils.Application.Console.Register('!', "fire", delegate(string[] s)
            {
                Debug.Log(string.Join("/", s));
                if (s.Length == 0)
                {
                    Debug.Log(f.CurrentStateName);
                }
                foreach (var cmd in s.Skip(1))
                {
                    f.PushEvent(cmd);
                    Debug.Log(f.CurrentStateName);
                }
            });

            ProtocolProcessor.Register <NetworkCommunication>();
            NetworkManager.Instance.OnDataReceived += data =>
            {
                var obj = data.Deserialize().Unpack();
                if (obj == null)
                {
                    return;
                }

                ProtocolProcessor.MessagePump(obj);
            };

            byte[] bufferLast  = new byte[512];
            byte[] bufferLast2 = new byte[512];

            NetworkManager.Instance.OnAsDataReceived += data => {
                Debug.Log("thread id:" + System.Threading.Thread.CurrentThread.ManagedThreadId + "type:" + "Count :" + data.Count);
                try {
                    var obj = data.Deserialize().Unpack();
                    if (obj == null)
                    {
                        return;
                    }
                    if (bufferLast != null)
                    {
                        byte[] q = bufferLast;
                        System.Array.Copy(data.Array, data.Offset, q, 0, data.Count);
                    }
                    this.networkData.Enqueue(obj);
                } catch (System.Exception ex) {
                    byte[] q = bufferLast2;
                    byte[] p = bufferLast;
                    System.Array.Copy(data.Array, data.Offset, q, 0, data.Count);

                    print(ex.Message);
                    throw;
                }
            };

            NetworkManager.Instance.OnConnected += (System.Net.Sockets.SocketAsyncEventArgs saea) =>
            {
                if (saea.SocketError == System.Net.Sockets.SocketError.Success)
                {
                    Debug.Log("connection build succeed to Endpoint:" + saea.RemoteEndPoint);
                }
                else
                {
                    Debug.LogErrorFormat("connection build failed to Endpoint: {0} Reason: {1}", saea.RemoteEndPoint, saea.SocketError);
                }
            };
            var p99 = Framework.Library.StateMachine.Parser.FSMXMLParser.LoadFromXML(obj.text);
            var fsm = new FSMExecutor <MainCameraScript>(p99);

            f = Utils.GetStateMachineExecutor(this, obj);
            f = Utils.GetStateMachineExecutor(this, obj);
            var t1 = FCD.Tuple.Create(p99, fsm);
            var t2 = FCD.Tuple.Create(p99, fsm);

            Debug.Log("------------>>>>>" + (t1.Equals(t2)));

            //          var threeMi = typeof(MainCameraScript).GetMethod("threeParam", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
            //          //var df = (Func<MainCameraScript, string, int, bool>)Delegate.CreateDelegate(typeof(Func<MainCameraScript, string, int, bool>), null, threeMi);
            //          var df = (Func< MainCameraScript, bool>)Delegate.CreateDelegate(typeof(Func<MainCameraScript, bool>), threeMi);
            //          Debug.Log("--|||||---->>>>>" + df.Invoke(this));
            //          bool dfValue = (bool)df.DynamicInvoke(cob);
            //          Debug.Log("------------>>>>>" + dfValue);
            GameEventManager.Instance.AddListener(GameEventType.kInput_Keyboard, (o, e) =>
            {
                Debug.Log("-----------------1");
                Debug.Log(o);
                Debug.Log(e);
                Debug.Log("-----------------2");
            });
            GameEventManager.Instance.AddListener(GameEventType.kInput_Keyboard, (o, e) =>
            {
                Debug.Log("-----------------3");
                Debug.Log(o);
                Debug.Log(e);
                Debug.Log("-----------------4");
                GameEventManager.Instance.RemoveTypeAllListener(this.GetType());
            });
            GameEventManager.Instance.AddListener(GameEventType.kInput_Keyboard, (o, e) =>
            {
                Debug.Log("-----------------5");
                Debug.Log(o);
                Debug.Log(e);
                Debug.Log("-----------------6");
            });
            Debug.Log(GameEventType.kInput_Keyboard);
            Debug.Log(GameEventType.kGameEvent_Flag);
            Debug.Log(GameEventType.kInput_Mouse);
            Debug.Log(GameEventType.kOther);
            Debug.Log("~~~~~~~~~~~~~~~~~~");
            for (int i = 0; i < GameEventType.CreationIndex; ++i)
            {
                var it = GameEventType.GetEventTypeByIndex(i);
                Debug.Log(it);
            }
            Debug.Log(SystemEvent.CreationIndex);
            FLThreadPool.Instance.AddTask(() =>
            {
                Debug.Log("~/" + System.Threading.Thread.CurrentThread.ManagedThreadId);
            });            //
        }