diff --git a/Assets/Editor/PhysicsEditor.cs b/Assets/Editor/PhysicsEditor.cs old mode 100644 new mode 100755 index e694423..e75750a --- a/Assets/Editor/PhysicsEditor.cs +++ b/Assets/Editor/PhysicsEditor.cs @@ -7,13 +7,15 @@ [CustomEditor(typeof(Polygon))] public class PhysicsEditor : Editor { - + + SerializedProperty polygonCollider; SerializedProperty plistPath; SerializedProperty pixelsPerUnit; SerializedProperty totalPolygonsinFile; SerializedProperty selectedIndex; public void OnEnable () { + polygonCollider = serializedObject.FindProperty("_polygonCollider"); plistPath = serializedObject.FindProperty("PlistPath"); pixelsPerUnit = serializedObject.FindProperty("PixelsPerUnit"); totalPolygonsinFile = serializedObject.FindProperty("_totalPolygonsinFile"); @@ -29,6 +31,7 @@ public override void OnInspectorGUI () GUI.changed = false; + EditorGUILayout.PropertyField(polygonCollider, new GUIContent("Polygon Collider")); EditorGUILayout.PropertyField(plistPath, new GUIContent("Plist Path")); /*If file path is changed*/ diff --git a/Assets/Scripts/Polygon.cs b/Assets/Scripts/Polygon.cs old mode 100644 new mode 100755 index 33608e7..054716e --- a/Assets/Scripts/Polygon.cs +++ b/Assets/Scripts/Polygon.cs @@ -36,7 +36,7 @@ public class Polygon : MonoBehaviour { public int selectedIndex = 0; - private PolygonCollider2D _polygonCollider; + public PolygonCollider2D _polygonCollider = null; [SerializeField] public TextAsset PlistPath = null; @@ -53,7 +53,8 @@ void Awake() { // Use this for initialization void Start () { - _polygonCollider = this.GetComponent(); + if (_polygonCollider == null) + _polygonCollider = this.GetComponent(); //this.ClearBodiesList(); @@ -91,30 +92,35 @@ public void ParsePolygonsFromFile () { _totalPolygonsinFile[i].bodyname = keyNames[i] as String; Hashtable bodyDic = bodies[keyNames[i]] as Hashtable; - /*Using single fixture because unity support single fixture*/ ArrayList fixtures = bodyDic["fixtures"] as ArrayList; - - Hashtable fixture1 = fixtures[0] as Hashtable; - - ArrayList polygonsArray = fixture1["polygons"] as ArrayList; - - PolygonPath[] totalPaths = new PolygonPath[polygonsArray.Count]; - - for(int j = 0; j(); + + for (var f = 0; f < fixtures.Count; f++) { + var fixture = fixtures[f] as Hashtable; + if (fixture == null) + continue; + + var polygonsArray = fixture["polygons"] as ArrayList; + if (polygonsArray == null) + continue; + + for(int j = 0; j < polygonsArray.Count; j++) { + ArrayList pointArray = polygonsArray[j] as ArrayList; + PolygonPath tempPath = new PolygonPath(); + Vector2[] pointsVector = new Vector2[pointArray.Count]; + for(int k = 0; k