Exemple #1
0
        // while dragging, transform the selected handles
        public void OnDrag(PointerEventData eventData)
        {
            Vector3 dragPos = Camera.main.ScreenToWorldPoint(eventData.position);

            dragPos.z = 0;

            Vector3 dragDelta = (dragStart - dragPos);

            dragDelta.z = 0;

            Vector3 newPos;

            // alter positions based on the original position plus the drag delta
            for (int i = 0; i < VertHandler.selectedHandles.Count; i++)
            {
                newPos = beforeDragPositions[i] - dragDelta;

                Mesh    m           = LevelPlacer.generatedLevel.moveArea.meshFilter.mesh;
                Vector3 localOldPos = LevelPlacer.generatedLevel.moveArea.transform.InverseTransformPoint(VertHandler.selectedHandles[i].transform.position);
                Vector3 localnewPos = LevelPlacer.generatedLevel.moveArea.transform.InverseTransformPoint(newPos);

                // check if the desired position is not crossing the triangle and if its not inside the mesh
                if (!VertHelper.IsInsideMesh(m, localOldPos, localnewPos) && VertHelper.IsHandlerPositionValid(localOldPos, localnewPos))
                {
                    // update the selection triangle verts
                    if (VertHandler.selectionTriangleVerts.Any(x => x == localOldPos))
                    {
                        // get all vector entries that are equal to this position and replace them with the newest position
                        List <int> indexes = Enumerable.Range(0, VertHandler.selectionTriangleVerts.Count).Where(k => VertHandler.selectionTriangleVerts[k] == localOldPos).ToList();

                        foreach (int ind in indexes)
                        {
                            VertHandler.selectionTriangleVerts[ind] = localnewPos;
                        }
                    }
                    VertHandler.selectedHandles[i].transform.position = newPos;
                }
            }

            if (VertHandler.quickDragHandle != null && VertHandler.selectedHandles.Count == 0)
            {
                newPos = quickDragBefore - dragDelta;
                Mesh    m           = LevelPlacer.generatedLevel.moveArea.meshFilter.mesh;
                Vector3 localOldPos = LevelPlacer.generatedLevel.moveArea.transform.InverseTransformPoint(transform.position);
                Vector3 localnewPos = LevelPlacer.generatedLevel.moveArea.transform.InverseTransformPoint(newPos);

                // check if the desired position is not crossing the triangle and if its not inside the mesh
                if (!VertHelper.IsInsideMesh(m, localOldPos, localnewPos) && VertHelper.IsHandlerPositionValid(localOldPos, localnewPos))
                {
                    VertHandler.quickDragHandle.transform.position = newPos;
                }
            }
        }