예제 #1
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         Debug.Log("***  E pressed!  ***");
         // if(OnEPressed != null) { OnEPressed(this, EventArgs.Empty); }
         // use the ? null conditional operator added in C# 6 to trim the above line down
         OnEPressed?.Invoke(this, EventArgs.Empty);
     }
     else if (Input.GetKeyDown(KeyCode.Return))
     {
         Debug.Log("***  Return Pressed!  ***");
         returnCounter++;
         OnReturnPressed?.Invoke(this, new OnReturnPressedEventArgs {
             returnPressedCount = returnCounter
         });
     }
     else if (Input.GetKeyDown(KeyCode.D))
     {
         Debug.Log("***  D Pressed!  ***");
         OnDelegateFloatEvent?.Invoke(6.9f);
     }
     else if (Input.GetKeyDown(KeyCode.A))
     {
         Debug.Log("***  A Pressed!  ***");
         OnActionEventSimple?.Invoke();
     }
     else if (Input.GetKeyDown(KeyCode.C))
     {
         Debug.Log("***  C Pressed!  ***");
         returnCounter++;
         OnActionEventCustom?.Invoke(true, 13, new OnReturnPressedEventArgs {
             returnPressedCount = returnCounter
         });
     }
     else if (Input.GetKeyDown(KeyCode.U))
     {
         Debug.Log("***  U Pressed!  ***");
         OnUnityEvent?.Invoke();
     }
 }
예제 #2
0
 private void OnKeyPressed(object sender, KeyEventArgs e)
 {
     if (started)
     {
         if (stop == 0)
         {
             if (e.Code == Keyboard.Key.W)
             {
                 if (!up)
                 {
                     _updateY += -1;
                     up        = true;
                 }
             }
             else if (e.Code == Keyboard.Key.S)
             {
                 if (!down)
                 {
                     _updateY += 1;
                     down      = true;
                 }
             }
             else if (e.Code == Keyboard.Key.A)
             {
                 if (!left)
                 {
                     _updateX += -1;
                     left      = true;
                 }
             }
             else if (e.Code == Keyboard.Key.D)
             {
                 if (!right)
                 {
                     _updateX += 1;
                     right     = true;
                 }
             }
             else if (e.Code == Keyboard.Key.R)
             {
                 roundOver = !roundOver;
             }
         }
         if (roundOver)
         {
             if (e.Code == Keyboard.Key.E)
             {
                 if (stop == 0)
                 {
                     stop     = 2;
                     _updateX = 0;
                     _updateY = 0;
                     up       = false;
                     down     = false;
                     left     = false;
                     right    = false;
                     OnEPressed?.Invoke();
                 }
                 else if (stop == 2)
                 {
                     stop = 0;
                     OnEPressed?.Invoke();
                 }
             }
             else if (e.Code == Keyboard.Key.Escape)
             {
                 if (stop == 0)
                 {
                     stop     = 1;
                     _updateX = 0;
                     _updateY = 0;
                     up       = false;
                     down     = false;
                     left     = false;
                     right    = false;
                     OnEscapePressed?.Invoke();
                 }
                 else if (stop == 1)
                 {
                     stop = 0;
                     OnEscapePressed?.Invoke();
                 }
                 else if (stop == 2)
                 {
                     stop = 0;
                     OnEPressed?.Invoke();
                 }
             }
         }
         else if (!roundOver)
         {
             if (e.Code == Keyboard.Key.Space)
             {
                 if (stop == 0)
                 {
                     stop     = 3;
                     _updateX = 0;
                     _updateY = 0;
                     up       = false;
                     down     = false;
                     left     = false;
                     right    = false;
                     OnSpacePressed?.Invoke();
                 }
                 else if (stop == 3)
                 {
                     stop = 0;
                     OnSpacePressed?.Invoke();
                 }
             }
         }
     }
 }