修复自动吸附的Bug
This commit is contained in:
parent
d685b9af8d
commit
7bcf223b2a
|
@ -1649,7 +1649,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 8124e469eb4c87f46ad8cb8a995694a6, type: 3}
|
m_Script: {fileID: 11500000, guid: 8124e469eb4c87f46ad8cb8a995694a6, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
oriObjectPrefab: {fileID: 5015601091524974045, guid: 8dc9719f2b7eb2f4ea642a026d7effa9, type: 3}
|
oriObjectPrefab: {fileID: 5920286553495436801, guid: 1d4e4bb2ce1ec2e43b45ba5872d750fc, type: 3}
|
||||||
isOnUPos: 0
|
isOnUPos: 0
|
||||||
currentUPosItem: {fileID: 0}
|
currentUPosItem: {fileID: 0}
|
||||||
uPosManger: {fileID: 606617863}
|
uPosManger: {fileID: 606617863}
|
||||||
|
@ -2406,6 +2406,8 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: b73da4762bf986646bd42484bee07dc3, type: 3}
|
m_Script: {fileID: 11500000, guid: b73da4762bf986646bd42484bee07dc3, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
isopen: 0
|
||||||
|
TextMeshProUGUI: {fileID: 0}
|
||||||
--- !u!33 &925365234363722706
|
--- !u!33 &925365234363722706
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -26,13 +26,10 @@ public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler,
|
||||||
|
|
||||||
//public DragTest1 currentDevice;
|
//public DragTest1 currentDevice;
|
||||||
|
|
||||||
public bool isOnUPos = false;
|
|
||||||
|
|
||||||
public UPosItem currentUPosItem;
|
public UPosItem currentUPosItem;
|
||||||
public UPosManger uPosManger;
|
public UPosManger uPosManger;
|
||||||
|
|
||||||
|
|
||||||
public GameObject cube;
|
|
||||||
|
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
|
@ -48,7 +45,6 @@ public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler,
|
||||||
OnRay(target.gameObject);
|
OnRay(target.gameObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
Debug.Log(cube.GetComponent<MeshRenderer>().bounds.size.x);
|
|
||||||
}
|
}
|
||||||
public void OnBeginDrag(PointerEventData eventData)
|
public void OnBeginDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
|
@ -74,10 +70,10 @@ public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler,
|
||||||
public void OnEndDrag(PointerEventData eventData)
|
public void OnEndDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
EndDragAction?.Invoke(targetObject);
|
EndDragAction?.Invoke(targetObject);
|
||||||
if (!isOnUPos)
|
//if (!isOnUPos)
|
||||||
{
|
//{
|
||||||
Destroy(targetObject.gameObject);
|
// Destroy(targetObject.gameObject);
|
||||||
}
|
//}
|
||||||
CountUPos();
|
CountUPos();
|
||||||
currentUPosItem = null;
|
currentUPosItem = null;
|
||||||
targetObject = null;
|
targetObject = null;
|
||||||
|
@ -90,6 +86,11 @@ public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler,
|
||||||
private void CountUPos()
|
private void CountUPos()
|
||||||
{
|
{
|
||||||
if (targetObject == null) return;
|
if (targetObject == null) return;
|
||||||
|
if (currentUPosItem == null)
|
||||||
|
{
|
||||||
|
Destroy(targetObject.gameObject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
int index = uPosManger.CountUPos(targetObject.volume, currentUPosItem.ID);
|
int index = uPosManger.CountUPos(targetObject.volume, currentUPosItem.ID);
|
||||||
if (!CountUPos(targetObject, index))
|
if (!CountUPos(targetObject, index))
|
||||||
Destroy(targetObject.gameObject);
|
Destroy(targetObject.gameObject);
|
||||||
|
@ -121,6 +122,7 @@ public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler,
|
||||||
private void OnRay(GameObject target)
|
private void OnRay(GameObject target)
|
||||||
{
|
{
|
||||||
target.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 5));
|
target.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 5));
|
||||||
|
currentUPosItem = null;
|
||||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||||
RaycastHit hitInfo;
|
RaycastHit hitInfo;
|
||||||
if (Physics.Raycast(ray, out hitInfo))
|
if (Physics.Raycast(ray, out hitInfo))
|
||||||
|
@ -130,16 +132,19 @@ public class DragController : MonoBehaviour, IBeginDragHandler, IEndDragHandler,
|
||||||
currentUPosItem = hitInfo.collider.GetComponent<UPosItem>();
|
currentUPosItem = hitInfo.collider.GetComponent<UPosItem>();
|
||||||
if (!EventSystem.current.IsPointerOverGameObject())
|
if (!EventSystem.current.IsPointerOverGameObject())
|
||||||
{
|
{
|
||||||
if (!currentUPosItem.isOccupied)
|
if (currentUPosItem != null && !currentUPosItem.isOccupied)
|
||||||
{
|
{
|
||||||
target.transform.position = hitInfo.point;
|
target.transform.position = hitInfo.point;
|
||||||
isOnUPos = true;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isOnUPos = false;
|
currentUPosItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue