Newer
Older
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
using UnityEngine;
public class BoundingPositioning : MonoBehaviour
{
public Anker x = Anker.center;
public Anker y = Anker.center;
public Anker z = Anker.center;
public MeshFilter mesh = null;
public enum Anker
{
min = 0, center = 1, max = 2
}
private void OnValidate() => UpdatePosition();
private void Awake() => UpdatePosition();
private void UpdatePosition()
{
if (mesh == null
|| mesh.sharedMesh == null)
return;
Vector3[] bounds = {
mesh.sharedMesh.bounds.min,
mesh.sharedMesh.bounds.center,
mesh.sharedMesh.bounds.max,
};
transform.position = new Vector3(
bounds[(int)x][0],
bounds[(int)y][1],
bounds[(int)z][2]
);
}
}