I made a script that round the points of the polygon collider 2D:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(PolygonPoints))]
public class PolyColliderPointAling : Editor
{
PolygonPoints polygonPoints;
public override void OnInspectorGUI()
{
serializedObject.Update();
if(GUILayout.Button("Run!"))
{
polygonPoints = target as PolygonPoints;
PolygonCollider2D[] colliders = polygonPoints.gameObject.GetComponents<PolygonCollider2D>();
for(int y = 0; y < colliders.Length; y++)
{
Vector2[] points = colliders[y].points;
Debug.Log(points.Length);
for(int i = 0; i < points.Length; i++)
{
Vector2 pointPosition = new Vector2(Mathf.Round(points_.x), Mathf.Round(points*.y));*_
_ points = pointPosition;
Debug.Log(points*.ToString(“F5”));
}
}
EditorUtility.SetDirty(polygonPoints);
}*_
* serializedObject.ApplyModifiedProperties();*
* }*
}
The PolygonPoints script:
using UnityEngine;
using System.Collections;
public class PolygonPoints : MonoBehaviour {
* PolygonCollider2D[] colliders;*
* void Start()*
* {*
* colliders = gameObject.GetComponents();*
* for(int y = 0; y < colliders.Length; y++)*
* {*
* Vector2[] points = colliders[y].points;*
* Debug.Log(points.Length + “pontos.”);*
* for(int i = 0; i < points.Length; i++)*
* {*
_ Debug.Log(points*.ToString(“F5”));
}
}
}
}*
When I hit the “run” button the console shows that the points have been rounded. But when I hit play I lose all changes and I don’t know why. How can I apply the changes that I have made ?_