From 67b39175603039fb300d6b381ae6645fc40307a2 Mon Sep 17 00:00:00 2001 From: Bruno Assarisse Date: Mon, 31 Aug 2015 23:51:18 -0300 Subject: [PATCH 1/2] Better support for prefabs. --- Assets/Editor/PhysicsEditor.cs | 5 ++++- Assets/Scripts/Polygon.cs | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) mode change 100644 => 100755 Assets/Editor/PhysicsEditor.cs 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 index 33608e7..dd46448 100644 --- 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(); @@ -143,6 +144,9 @@ private Vector2 ConvertToVector2FromString(string strVector) { public void setPolygonOfIndex(int index) { _polygonObject = _totalPolygonsinFile[index]; + if (_polygonCollider == null) + return; + _polygonCollider.pathCount = _polygonObject.TotalPaths; for(int i = 0; i<_polygonCollider.pathCount; i++) { From c930f043aeb8d24db14161945bf353d1d850f0f2 Mon Sep 17 00:00:00 2001 From: Bruno Assarisse Date: Mon, 31 Aug 2015 23:54:42 -0300 Subject: [PATCH 2/2] Multiple fixtures support. --- Assets/Scripts/Polygon.cs | 45 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) mode change 100644 => 100755 Assets/Scripts/Polygon.cs diff --git a/Assets/Scripts/Polygon.cs b/Assets/Scripts/Polygon.cs old mode 100644 new mode 100755 index dd46448..054716e --- a/Assets/Scripts/Polygon.cs +++ b/Assets/Scripts/Polygon.cs @@ -92,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