最近、Unityで#region、#endregion、#if、#endifなどのようなものを使用して問題が発生しています。ユニティ・プリプロセッサ・ディレクティブ・エラー?
これはどのバージョンのUnityで始まったのか正確には思い出せませんが、新しいプロジェクトを作成するたびにリージョンを使用することはできません。
それは常に構文解析エラーがあると言い、その後、この「エラーCS1027:予想 `#endifの」ディレクティブ」のようなものと言うそのエラーを取得するために
が、これは私が
#if !UNITY_EDITOR
#endif
を置くすべてです
私は文の間のコードが含まれる、またはディレクティブの両側の周りのすべての空のスペースを取り除く場合、それは問題ではありません..私は私が#regionsを使用することができ、別の、古いプロジェクトを持っている
、との#if fの文だけどのように変わったのか、それを修正する方法は本当にわかりません。私は解決策を探していましたが、誰もこの問題を抱えていないようです。モノデコードの設定ですか?ホワイトスペース?無効な文字はどこか?なぜそれが起こっているのか分かりませんし、それが私を怒らせてしまいます。
誰かが何か提案があれば、私はそれらを聞いてみたい!
ありがとうございました!
EDIT: ドラッグアンドドロップスクリプトで#regionsが動作しない場合の例を次に示します(BONUS、FREE DRAG、DROP SCRIPT!LOL)エラーが発生した場合は、リージョンをコメントアウトしてください。 。 そうしなければならなかった。 :(
ユニティコンソールのエラー:
資産/スクリプト/ DragAndDrop.cs(12254):エラーCS1028:予期しないプロセッサディレクティブ(この#endregion #region用なし)(この1つはの終わりに私を指します要約タグ) 資産/スクリプト/ DragAndDrop.cs(14,45):?エラーCS1028:予期しないプロセッサディレクティブ(この#endregion #region用なし) ...など
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// DragAndDrop.
/// This class will be responsible for listening to drag
/// events on the gameobject.
/// It will handle what happens during each drag state.
/// </summary>
public class DragAndDrop : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler{
public RectTransform canvas; // the uGui canvas in your scene
#region DRAG BOOLEANS
public bool canDrag = true; // can this object be dragged?
public bool wasDragged = false; // was this object recently dragged?
public bool isDragging = false; // is object currently being dragged
public bool dragOnSurfaces = true;
#endregion
#region SWIPE
public float comfortZoneVerticalSwipe = 50; // the vertical swipe will have to be inside a 50 pixels horizontal boundary
public float comfortZoneHorizontalSwipe = 50; // the horizontal swipe will have to be inside a 50 pixels vertical boundary
public float minSwipeDistance = 14; // the swipe distance will have to be longer than this for it to be considered a swipe
public float startTime; // when the touch started
public Vector2 startPos; // where the touch started
public float maxSwipeTime; // if the touch lasts longer than this, we consider it not a swipe
#endregion
#region PRIVATE
private GameObject draggingObject;
private RectTransform draggingTransform;
#endregion
#region UNITY CALLBACKS
void Awake(){
canvas = GameObject.Find("Canvas").GetComponent<RectTransform>();
}
#endregion
#region TOUCH EVENTS
public void OnPointerDown(PointerEventData eventData){
if(canDrag){
wasDragged = false;
// make sure object is parent to the canvas or it will disappear when picked up
// I had to do this in word addiction because the letters were parented to tiles
gameObject.transform.SetParent(canvas);
// scale up when touched
gameObject.transform.localScale = new Vector3(2, 2, 2);
}
}
public void OnPointerUp(PointerEventData eventData){
if(canDrag){
// scale back down
gameObject.transform.localScale = new Vector3(1, 1, 1);
}
}
#endregion
#region DRAG EVENTS
public void OnBeginDrag(PointerEventData eventData){
if(canDrag){
// start listening for swipe
startPos = eventData.position;
startTime = Time.time;
// set drag variables
isDragging = true;
wasDragged = true;
// run pick up logic
PickUp(eventData);
}
}
public void OnDrag(PointerEventData eventData){
if(canDrag){
if(draggingObject != null){
Move(eventData);
}
}
}
public void OnEndDrag(PointerEventData eventData){
if(canDrag){
// swipe detection
bool shouldFlick = false;
float swipeTime = Time.time - startTime;
float swipeDist = (eventData.position - startPos).magnitude;
if (swipeTime < maxSwipeTime &&
swipeDist > minSwipeDistance){
shouldFlick = true;
}
// handle swipe/dropping
if (shouldFlick){
Debug.Log("FLICK");
}else{
isDragging = false;
Place();
}
}
}
#endregion
#region EVENT FUNCTIONS
void PickUp(PointerEventData eventData){
draggingObject = gameObject;
Move(eventData);
}
void Move(PointerEventData eventData){
if(dragOnSurfaces && eventData.pointerEnter != null && eventData.pointerEnter.transform as RectTransform != null){
draggingTransform = eventData.pointerEnter.transform as RectTransform;
}
var rt = draggingObject.GetComponent<RectTransform>();
Vector3 globalMousePos;
if(RectTransformUtility.ScreenPointToWorldPointInRectangle(draggingTransform, eventData.position, eventData.pressEventCamera, out globalMousePos)){
rt.position = globalMousePos;
rt.rotation = draggingTransform.rotation;
}
}
void Place(){
Vector2 pos = new Vector2(transform.position.x, transform.position.y);
Collider2D[] cols = Physics2D.OverlapCircleAll(pos, 10);
float closestDistance = 0;
GameObject closest = null;
foreach(Collider2D col in cols){
if(col.tag == "SomeTagToCheckFor"){
Vector2 otherPos = new Vector2(col.transform.position.x, col.transform.position.y);
if(closest == null){
closest = col.gameObject;
closestDistance = Vector2.Distance(pos, otherPos);
} else{
// here we will check to see if any other objects
// are closer than the current closest object
float distance = Vector2.Distance(pos, otherPos);
if(distance < closestDistance){
// this object is closer
closest = col.gameObject;
closestDistance = distance;
}
}
}
}
// snap to the closest object
if(closest != null){
// if something was detected to snap too?
} else{
// return object back?
}
}
#endregion
}
現在のVS構成が「リリース」の場合は、「デバッグ」に切り替えます。 – raven
ねえ、そこに!返信いただきありがとうございます。私はMonodevelopを使用しており、現在はデバッグするように設定されています!アイデアをありがとう。 – JoeyMaru
ねえ、ジョー!はい、コンソールで、私は例を得るために取り組んでいます。あなたが投稿した答えは、私にとっては新しいプロジェクトでもうまくいきます。しかし、奇妙なことは、私はこれらの命令をたくさん使っているということです。私は多くの地域で自分のコードを整理するのが大好きです。以前のプロジェクトでは、まったく動作しませんでしたが、Unity 5.3.2f1でテストするための新しいプロジェクトを作成しました。現在、地域は正常に動作していますか?私は今、いくつかの例をつかんでいます。 – JoeyMaru