-
Notifications
You must be signed in to change notification settings - Fork 1
/
MeshPivotChecker.cs
68 lines (52 loc) · 2.39 KB
/
MeshPivotChecker.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
62
63
64
65
66
67
68
//// This Code Checks if Pivot is at geometric center
/// mr.yilanci
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class MeshPivotChecker : EditorWindow
{
public List<GameObject> PivotProblemList = new List<GameObject>();
private Vector2 scrollPosition;
[MenuItem("Araclar/Mesh Pivot Checker")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(MeshPivotChecker));
}
private float threshold = 8000f;
private void OnGUI()
{
GUILayout.Label("Mesh Pivot Checker", EditorStyles.boldLabel);
threshold = EditorGUILayout.FloatField("Threshold", threshold);
if (GUILayout.Button("Check Pivot for All Objects"))
{
PivotProblemList.Clear();
GameObject[] objects = FindObjectsOfType<GameObject>();
foreach (GameObject obj in objects)
{
MeshFilter meshFilter = obj.GetComponent<MeshFilter>();
Bounds bounds = obj.GetComponent<MeshRenderer>().bounds;
Vector3 geometricCenter = bounds.center;
Vector3 size = bounds.size;
if (meshFilter != null && meshFilter.sharedMesh != null )
{
Vector3 pivot = obj.transform.position;
float distanceX = Mathf.Abs(pivot.x - geometricCenter.x);
float distanceY = Mathf.Abs(pivot.y - geometricCenter.y);
float distanceZ = Mathf.Abs(pivot.z - geometricCenter.z);
if (distanceX > threshold || distanceY > threshold || distanceZ > threshold)
{
Debug.Log( $"Parent::{obj.transform.parent.name } --- sorunlu: {obj.name} Mesh pivot is not at the geometric center.");
PivotProblemList.Add(obj);
}
}
}
}
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
ScriptableObject scriptableObj = this;
SerializedObject serialObj = new SerializedObject (scriptableObj);
SerializedProperty serialProp = serialObj.FindProperty ("PivotProblemList");
EditorGUILayout.PropertyField (serialProp, true);
serialObj.ApplyModifiedProperties ();
EditorGUILayout.EndScrollView();
}
}