-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtrudeMeshApp4.cs
61 lines (54 loc) · 1.98 KB
/
ExtrudeMeshApp4.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
public class ExtrudeMeshApp4 : MonoBehaviour
{
[SerializeField] ProBuilderMesh cube;
[SerializeField] Camera camera2;
Vector3 mousePositionInWorld;
Face faceToExtrude;
bool isDragging;
private Vector3 dragStartPosition;
List<Face> extrudingFace = new List<Face>();
void Update()
{
MousePosition();
}
void MousePosition()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePosition = Input.mousePosition;
dragStartPosition = Camera.main.ScreenToWorldPoint(mousePosition);
Ray ray = Camera.main.ScreenPointToRay(mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
mousePositionInWorld = hit.point;
faceToExtrude = SelectionPicker.PickFace(camera2, mousePosition, cube);
if (faceToExtrude != null)
{
cube.SetSelectedFaces(cube.faces);
extrudingFace.Clear();
extrudingFace.Add(faceToExtrude);
isDragging = true;
}
}
}
if (Input.GetMouseButtonUp(0) && isDragging)
{
if (faceToExtrude != null)
{
Vector3 dragEndPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
float distanceBetween = Vector3.Distance(mousePositionInWorld, dragEndPosition);
float extrusionAmount = distanceBetween * 0.5f;
Debug.Log("Extrusion distance: " + extrusionAmount);
cube.Extrude(extrudingFace, ExtrudeMethod.FaceNormal, extrusionAmount);
isDragging = false;
cube.ToMesh(MeshTopology.Quads);
cube.Refresh();
}
}
}
}