public override void Uninitialize()
 {
     RockerHandler = null;
     PressHandler  = null;
     RotateHandler = null;
     McuInput.DestroyInstance();
     //
 }
Пример #2
0
        // Update is called once per frame
        void Update()
        {
            // McuInput.GetInstance().ConnectStateCallbackLoop();

            if (McuInput.GetInstance().GetKey(MCUKeyCode.Up))
            {
                UpKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.Down))
            {
                DownKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.Left))
            {
                LeftKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.Right))
            {
                RightKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.Sure))
            {
                SureKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.LeftUp))
            {
                LeftUpKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.LeftDown))
            {
                LeftDownKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.RightUp))
            {
                RightUpKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            if (McuInput.GetInstance().GetKey(MCUKeyCode.RightDown))
            {
                RightDownKey.GetComponent <MeshRenderer>().material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
            }

            int tmp = McuInput.GetInstance().GetRotation();

            if (tmp != 0)
            {
                RotateCube.transform.RotateAround(Vector3.up, (3.1415926f / 180.0f) * tmp);
            }
        }
 //刷新按键检查
 private void RefreshPressCheck()
 {
     if (PCControl)
     {
         if (refreshPressState == PressState.Ready)
         {
             if (UnityEngine.Input.GetKey(KeyCode.R))
             {
                 refreshPressState = PressState.OnPress;
             }
         }
         else if (refreshPressState == PressState.OnPress)
         {
             if (!UnityEngine.Input.GetKey(KeyCode.R))
             {
                 refreshPressState = PressState.OnClick;
                 if (RefreshHandler != null)
                 {
                     RefreshHandler((int)PressEvent.PressClick);
                 }
             }
         }
         else if (refreshPressState == PressState.OnClick && !UnityEngine.Input.GetKey(KeyCode.R))
         {
             refreshPressState = PressState.Ready;
         }
     }
     else
     {
         if (refreshPressState == PressState.Ready)
         {
             if (McuInput.GetInstance().GetKey(MCUKeyCode.IN2))
             {
                 refreshPressState = PressState.OnPress;
             }
         }
         else if (refreshPressState == PressState.OnPress)
         {
             if (!McuInput.GetInstance().GetKey(MCUKeyCode.IN2))
             {
                 if (RefreshHandler != null)
                 {
                     RefreshHandler((int)PressEvent.PressClick);
                 }
                 refreshPressState = PressState.OnClick;
             }
         }
         else if (refreshPressState == PressState.OnClick && !McuInput.GetInstance().GetKey(MCUKeyCode.IN2))
         {
             //重置
             refreshPressState = PressState.Ready;
         }
     }
 }
Пример #4
0
        public void LrightBar1CtrlButton()
        {
            mode1++;
            if (mode1 == 16)
            {
                mode1 = 0;
            }
            McuInput.GetInstance().SetLightBar(1, mode1);
            Text text = button1.GetComponentInChildren(typeof(Text)) as Text;

            text.text = "模式" + mode1.ToString("D");
        }
Пример #5
0
        //protected void AddNotifyListener()
        //{
        //    NotificationCenter.GetInstance().AddHandler(HandleLightBarOnLine, NotificationConst.light_bar_online);
        //}

        //protected void HandleLightBarOnLine(object name, object sender, object[] args)
        //{
        //    Debug.Log("HandleLightBarOnLine");
        //}
        public void LrightBar0CtrlButton()
        {
            mode0++;
            if (mode0 == 16)
            {
                mode0 = 0;
            }
            McuInput.GetInstance().SetLightBar(0, mode0);
            Text text = button0.GetComponentInChildren(typeof(Text)) as Text;

            text.text = "模式" + mode0.ToString("D");
        }
        public override bool Initialize()
        {
            currentRotationAngle = 0;
            recordRotationAngle  = 0;
            rockerState          = RockerState.RockerMoveMiddle;
            startPressState      = PressState.Ready;
            refreshPressState    = PressState.Ready;
            longPressTime        = 2.0f;

#if UNITY_EDITOR
            PCControl = true;
#else
            //启动串口
            McuInput.GetInstance();
            PCControl = false;
#endif
            return(true);
        }
        //确定按键检查
        private void MachinePressCheck()
        {
            if (PCControl)
            {
                if (startPressState == PressState.Ready)
                {
                    if (UnityEngine.Input.GetKey(KeyCode.Return))
                    {
                        startPressState   = PressState.OnPress;
                        longPressStarTime = Time.time;
                        //
                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.PressBegin);
                        }
                    }
                }
                else if (startPressState == PressState.OnPress)
                {
                    if (Time.time - longPressStarTime > longPressTime)
                    {
                        startPressState   = PressState.OnClick;
                        longPressStarTime = Time.time;
                        //
                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.LongPress);
                        }
                    }
                    else if (!UnityEngine.Input.GetKey(KeyCode.Return))
                    {
                        startPressState   = PressState.OnClick;
                        longPressStarTime = Time.time;
                        //
                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.PressEnd);
                        }
                        //
                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.PressClick);
                        }
                    }
                }
                else if (startPressState == PressState.OnClick && !UnityEngine.Input.GetKey(KeyCode.Return))
                {
                    //重置
                    startPressState = PressState.Ready;
                }
            }
            else
            {
                if (startPressState == PressState.Ready)
                {
                    if (McuInput.GetInstance().GetKey(MCUKeyCode.IN3))
                    {
                        startPressState   = PressState.OnPress;
                        longPressStarTime = Time.time;

                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.PressBegin);
                        }
                    }
                }
                else if (startPressState == PressState.OnPress)
                {
                    if (Time.time - longPressStarTime > longPressTime)
                    {
                        startPressState   = PressState.OnClick;
                        longPressStarTime = Time.time;

                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.LongPress);
                        }
                    }
                    else if (!McuInput.GetInstance().GetKey(MCUKeyCode.IN3))
                    {
                        startPressState   = PressState.OnClick;
                        longPressStarTime = Time.time;

                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.PressEnd);
                        }

                        if (PressHandler != null)
                        {
                            PressHandler((int)PressEvent.PressClick);
                        }
                    }
                }
                else if (startPressState == PressState.OnClick && !McuInput.GetInstance().GetKey(MCUKeyCode.IN3))
                {
                    startPressState = PressState.Ready;
                }
            }
        }
        //摇杆检查
        private void MachineInputCheck()
        {
            if (PCControl)
            {
                if (UnityEngine.Input.GetKey(KeyCode.Q))
                {
                    if (rockerState != RockerState.RockerMoveForwardLeft)
                    {
                        rockerState = RockerState.RockerMoveForwardLeft;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.E))
                {
                    if (rockerState != RockerState.RockerMoveForwardRight)
                    {
                        rockerState = RockerState.RockerMoveForwardRight;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.W))
                {
                    if (rockerState != RockerState.RockerMoveForward)
                    {
                        rockerState = RockerState.RockerMoveForward;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.Z))
                {
                    if (rockerState != RockerState.RockerMoveBackLeft)
                    {
                        rockerState = RockerState.RockerMoveBackLeft;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.C))
                {
                    if (rockerState != RockerState.RockerMoveBackRight)
                    {
                        rockerState = RockerState.RockerMoveBackRight;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.S))
                {
                    if (rockerState != RockerState.RockerMoveBack)
                    {
                        rockerState = RockerState.RockerMoveBack;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.A))
                {
                    if (rockerState != RockerState.RockerMoveLeft)
                    {
                        rockerState = RockerState.RockerMoveLeft;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (UnityEngine.Input.GetKey(KeyCode.D))
                {
                    if (rockerState != RockerState.RockerMoveRight)
                    {
                        rockerState = RockerState.RockerMoveRight;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (!UnityEngine.Input.GetKey(KeyCode.Q) && !UnityEngine.Input.GetKey(KeyCode.W) && !UnityEngine.Input.GetKey(KeyCode.E) && !UnityEngine.Input.GetKey(KeyCode.A) && !UnityEngine.Input.GetKey(KeyCode.D) && !UnityEngine.Input.GetKey(KeyCode.Z) && !UnityEngine.Input.GetKey(KeyCode.X) && !UnityEngine.Input.GetKey(KeyCode.C))
                {
                    if (rockerState != RockerState.RockerMoveMiddle)
                    {
                        rockerState = RockerState.RockerMoveMiddle;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                //旋转
                if (UnityEngine.Input.GetKey(KeyCode.LeftArrow))
                {
                    currentRotationAngle = 5f;
                }
                else if (UnityEngine.Input.GetKey(KeyCode.RightArrow))
                {
                    currentRotationAngle = -5f;
                }
                else
                {
                    currentRotationAngle = 0f;
                }
                if (recordRotationAngle != currentRotationAngle)
                {
                    recordRotationAngle = currentRotationAngle;
                    if (RotateHandler != null)
                    {
                        RotateHandler(recordRotationAngle);
                    }
                }
            }
            else
            {
                if (McuInput.GetInstance().GetKey(MCUKeyCode.LeftUp))
                {
                    if (rockerState != RockerState.RockerMoveForwardLeft)
                    {
                        rockerState = RockerState.RockerMoveForwardLeft;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.RightUp))
                {
                    if (rockerState != RockerState.RockerMoveForwardRight)
                    {
                        rockerState = RockerState.RockerMoveForwardRight;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.Up))
                {
                    if (rockerState != RockerState.RockerMoveForward)
                    {
                        rockerState = RockerState.RockerMoveForward;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.LeftDown))
                {
                    if (rockerState != RockerState.RockerMoveBackLeft)
                    {
                        rockerState = RockerState.RockerMoveBackLeft;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.RightDown))
                {
                    if (rockerState != RockerState.RockerMoveBackRight)
                    {
                        rockerState = RockerState.RockerMoveBackRight;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.Down))
                {
                    if (rockerState != RockerState.RockerMoveBack)
                    {
                        rockerState = RockerState.RockerMoveBack;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.Left))
                {
                    if (rockerState != RockerState.RockerMoveLeft)
                    {
                        rockerState = RockerState.RockerMoveLeft;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (McuInput.GetInstance().GetKey(MCUKeyCode.Right))
                {
                    if (rockerState != RockerState.RockerMoveRight)
                    {
                        rockerState = RockerState.RockerMoveRight;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }
                else if (!McuInput.GetInstance().GetKey(MCUKeyCode.Up) && !McuInput.GetInstance().GetKey(MCUKeyCode.Down) && !McuInput.GetInstance().GetKey(MCUKeyCode.Left) && !McuInput.GetInstance().GetKey(MCUKeyCode.Right) && !McuInput.GetInstance().GetKey(MCUKeyCode.LeftUp) && !McuInput.GetInstance().GetKey(MCUKeyCode.RightUp) && !McuInput.GetInstance().GetKey(MCUKeyCode.LeftDown) && !McuInput.GetInstance().GetKey(MCUKeyCode.RightDown))
                {
                    if (rockerState != RockerState.RockerMoveMiddle)
                    {
                        rockerState = RockerState.RockerMoveMiddle;
                        if (RockerHandler != null)
                        {
                            RockerHandler((int)rockerState);
                        }
                    }
                }

                onceRotationAngle     = -McuInput.GetInstance().GetRotation();
                currentRotationAngle += onceRotationAngle;
                //
                if (recordRotationAngle != 0 && onceRotationAngle == 0)
                {
                    recordRotationAngle = onceRotationAngle;
                    if (RotateHandler != null)
                    {
                        RotateHandler(recordRotationAngle);
                    }
                    return;
                }
                if (currentRotationAngle > 7.2f || currentRotationAngle < -7.2f)
                {
                    recordRotationAngle  = currentRotationAngle;
                    currentRotationAngle = 0;
                    if (RotateHandler != null)
                    {
                        RotateHandler(recordRotationAngle);
                    }
                }
            }
        }