2017-10-20 87 views
-3

我在这个类越来越#endregoin diretive expected为什么我越来越#endregoin diretive预期的错误

using System.Collections; 
    using System.Collections.Generic; 
    using UnityEngine; 

public class MobileInput : MonoBehaviour { 

    private const float DEADZONE = 100.0f; 

    public static MobileInput Instance { set; get; } 

    private bool tap, swipeLeft, swipeLeft, swipeRight, swipeUp, swipeUp, swipeDown; 
    private Vector2 swipeDelta, startTouch; 

    public bool Tap { get { return tap; } } 
    public Vector2 SwipeDelta { get { return swipeDelta; } } 
    public Vector2 SwipeLeft { get { return swipeLeft; } } 
    public Vector2 SwipeRight { get { return swipeRight; } } 
    public Vector2 SwipeUp { get { return swipeUp; } } 
    public Vector2 SwipeDown { get { return swipeDown; } } 

    private void Awake() 
    { 
     Instance = this; 
    } 

    private void Update() 
    { 
     //reseting all the bool 
     tap = swipeLeft = swipeRight = swipeDown = swipeUp = false; 

     //lets check input 

     #region Standalone Inputs 
     if (Input.GetMouseButtonDown(0)) 
     { 
      tap = true; 
      startTouch = Input.mousePosition; 
     } 
     else if (Input.GetMouseBottonUp(0)) 
     { 
      startTouch = swipeDelta = Vector2.zero; 
     } 

     #region Mobile Inputs 
     if (Input.touches.Length != 0) 
     { 
      if (Input.touches[0].phase == TouchPhase.Began) 
      { 
       tap = true; 
       startTouch = Input.mousePosition; 
      } 
      else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) 
      { 
       startTouch = swipeDelta = Vector2.zero; 
      } 

     } 
     #endregion 

     //Calculate 
     swipeDelta = Vector2.zero; 
     if (startTouch != Vector2.zero) 
     { 
      //let's check 
      if (Input.touches.Length != 0) 
      { 
       swipeDelta = Input.touches[0].position - startTouch; 
      } 
      //lets check standalone 
      else if (Input.GetMouseButton(0)) 
      { 
       swipeDelta = (Vector2)Input.mousePosition - startTouch; 
      } 
     } 

     //Check dead zone 
     if (swipeDelta.magnitude > DEADZONE) 
     { 

      // this is a confirmed swip 
      float x = swipeDelta.x; 
      float y = swipeDelta.y; 

      if (Mathf.Abs(x) > Mathf.Abs(y)) 
      { 
       //left 
       if (x < 0) 
        swipeLeft = true; 
       else 
        swipeRight = true; 
      } 
      else 
      { 
       //up or down 
       if (y < 0) 
        swipeDown = true; 
       else 
        swipeUp = true; 

      } 

      startTouch = swipeDelta = Vector2.zero; 
     } 
    } 
} 
+0

@drescherjm C#我在想。可能是BSPL。 – user4581301

+0

@ user4581301它是Unity3d下的c# –

+0

[#endregion指令预期可能重复,但}匹配](https://stackoverflow.com/questions/29444306/endregion-directive-expected-but-the-is-matching) – Taelsin

回答

2

#region Standalone Inputs缺少的#endregion在你的代码进一步下跌。

+2

...此外,使用区域不是一个好习惯...... –

+0

@CamiloTerevinto我很好奇,现在有什么理由?我一直在使用它们来设置一个代码块,这个代码块可以独立于任何包含它们的块(甚至是节省)来折叠。 – Draco18s

+0

@Draco18s我在几年前了解到。理性的是:如果你的代码太长了,需要隐藏在区域中,你需要重构。 –