You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
781 B
C#
39 lines
781 B
C#
|
3 years ago
|
using UnityEngine;
|
||
|
|
using UnityEngine.ProBuilder;
|
||
|
|
|
||
|
|
namespace ProBuilder.Examples
|
||
|
|
{
|
||
|
|
struct MeshAndFace
|
||
|
|
{
|
||
|
|
public ProBuilderMesh mesh;
|
||
|
|
public Face face;
|
||
|
|
}
|
||
|
|
|
||
|
|
static class Utility
|
||
|
|
{
|
||
|
|
internal static GameObject PickObject(Camera camera, Vector2 mousePosition)
|
||
|
|
{
|
||
|
|
var ray = camera.ScreenPointToRay(mousePosition);
|
||
|
|
|
||
|
|
RaycastHit hit;
|
||
|
|
|
||
|
|
if (Physics.Raycast(ray, out hit))
|
||
|
|
return hit.collider.gameObject;
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static MeshAndFace PickFace(Camera camera, Vector3 mousePosition)
|
||
|
|
{
|
||
|
|
var res = new MeshAndFace();
|
||
|
|
var go = PickObject(camera, mousePosition);
|
||
|
|
|
||
|
|
if (go == null || !(res.mesh = go.GetComponent<ProBuilderMesh>()))
|
||
|
|
return res;
|
||
|
|
|
||
|
|
res.face = SelectionPicker.PickFace(camera, mousePosition, res.mesh);
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|