コード例 #1
0
    void DropItem()
    {
        trainManager.Hide();
        draggingItem = false;
        var inputPosition = CurrentTouchPosition;

        RaycastHit2D[] touches = Physics2D.RaycastAll(inputPosition, Vector2.zero, 10f);
        Debug.Log(touches.Length);
        if (touches.Length == 2)
        {
            var hit = touches[1];
            if (hit.transform != null)
            {
                GameObject hitObj = hit.transform.gameObject;
                if (hitObj != null)
                {
                    if (hitObj.tag == "seat" && draggedPassenge.GetComponent <Passenge>().State == Passenge.PassengeState.Standing)
                    {
                        Seat    seat = hitObj.GetComponent <Seat>();
                        Vector2 newPos;
                        if (trainManager.IsSeatEmpty(draggedPassenge.GetComponent <Passenge>(),
                                                     draggedBlock.GetComponent <Block>(), seat, out newPos))
                        {
                            Debug.Log("Yes");
                            trainManager.AddPassenge(draggedPassenge.GetComponent <Passenge>(),
                                                     draggedBlock.GetComponent <Block>(), seat);
                            Vector3 tempNewPos = newPos;
                            tempNewPos.z = -1;
                            draggedPassenge.transform.position = tempNewPos;
                            stationManager.RemovePassenge(draggedPassenge.GetComponent <Passenge>());
                        }
                        else
                        {
                            Debug.Log("No");
                            draggedPassenge.transform.position = originalPosition;
                        }
                    }
                    else if (hitObj.tag == "seat" && draggedPassenge.GetComponent <Passenge>().State == Passenge.PassengeState.Sitting)
                    {
                        Seat    seat = hitObj.GetComponent <Seat>();
                        Vector2 newPos;
                        if (trainManager.TryMovePassenge(draggedPassenge.GetComponent <Passenge>(),
                                                         draggedBlock.GetComponent <Block>(), seat, out newPos))
                        {
                            Vector3 tempNewPos = newPos;
                            tempNewPos.z = -1;
                            draggedPassenge.transform.position = tempNewPos;
                        }
                        else
                        {
                            Debug.Log("No");
                            draggedPassenge.transform.position = originalPosition;
                        }
                    }
                    else if (hitObj.tag == "station" && draggedPassenge.GetComponent <Passenge>().State == Passenge.PassengeState.Sitting)
                    {
                        stationManager.AddPassenge(draggedPassenge.GetComponent <Passenge>());
                        trainManager.RemovePassenge(draggedPassenge.GetComponent <Passenge>());
                    }
                    else
                    {
                        Debug.Log("N1" + hitObj.name + "," + rotateTime);
                        draggedPassenge.transform.position = originalPosition;
                        if (rotateTime > 0)
                        {
                            for (int i = 0; i < rotateTime; i++)
                            {
                                RotatePassenge(false);
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log("N2");
                    draggedPassenge.transform.position = originalPosition;
                }
            }
            else
            {
                draggedPassenge.transform.position = originalPosition;
            }
        }
        else
        {
            draggedPassenge.transform.position = originalPosition;
        }
        rotateTime = 0;
    }