public virtual void OnEnable() { ConcaveShape = target as FSConcaveShapeComponent; EditTarget = new SerializedObject(ConcaveShape); FSSettings.Load(); categorySettings = FSSettings.CategorySettings; }
public virtual void OnEnable() { target0 = target as FSConcaveShapeComponent; EditTarget = new SerializedObject(target0); FSSettings.Load(); categorySettings = FSSettings.CategorySettings; }
protected virtual void ConvertToConvex(FSConcaveShapeComponent targetCSC) { FSShapeComponent[] childcomps = targetCSC.GetComponentsInChildren <FSShapeComponent>(); if (childcomps != null) { if (childcomps.Length > 0) { for (int i = 0; i < childcomps.Length; i++) { if (childcomps[i] == null) { continue; } if (childcomps[i].gameObject == null) { continue; } DestroyImmediate(childcomps[i].gameObject); } } } // convert vertices FarseerPhysics.Common.Vertices concaveVertices = new FarseerPhysics.Common.Vertices(); if (targetCSC.PointInput == FSShapePointInput.Transform) { for (int i = 0; i < targetCSC.TransformPoints.Length; i++) { concaveVertices.Add(FSHelper.Vector3ToFVector2(targetCSC.TransformPoints[i].localPosition)); } } List <FarseerPhysics.Common.Vertices> convexShapeVs = FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(concaveVertices); for (int i = 0; i < convexShapeVs.Count; i++) { GameObject newConvShape = new GameObject("convexShape" + i.ToString()); newConvShape.transform.parent = targetCSC.transform; newConvShape.transform.localPosition = Vector3.zero; newConvShape.transform.localRotation = Quaternion.Euler(Vector3.zero); newConvShape.transform.localScale = Vector3.one; FSShapeComponent shape0 = newConvShape.AddComponent <FSShapeComponent>(); shape0.CollidesWith = targetCSC.CollidesWith; shape0.CollisionFilter = targetCSC.CollisionFilter; shape0.BelongsTo = targetCSC.BelongsTo; shape0.CollisionGroup = targetCSC.CollisionGroup; shape0.Friction = targetCSC.Friction; shape0.Restitution = targetCSC.Restitution; shape0.Density = targetCSC.Density; shape0.UseUnityCollider = false; shape0.PolygonPoints = new Transform[convexShapeVs[i].Count]; for (int j = 0; j < convexShapeVs[i].Count; j++) { GameObject pnew = new GameObject("p" + j.ToString()); pnew.transform.parent = shape0.transform; pnew.transform.localPosition = FSHelper.FVector2ToVector3(convexShapeVs[i][j]); shape0.PolygonPoints[j] = pnew.transform; } } }
protected virtual void ConvertToConvex(FSConcaveShapeComponent targetCSC) { FSShapeComponent[] childcomps = targetCSC.GetComponentsInChildren<FSShapeComponent>(); if(childcomps != null) { if(childcomps.Length > 0) { for(int i = 0; i < childcomps.Length; i++) { if(childcomps[i] == null) continue; if(childcomps[i].gameObject == null) continue; DestroyImmediate(childcomps[i].gameObject); } } } // convert vertices FarseerPhysics.Common.Vertices concaveVertices = new FarseerPhysics.Common.Vertices(); if(targetCSC.PointInput == FSShapePointInput.Transform) { for(int i = 0; i < targetCSC.TransformPoints.Length; i++) { concaveVertices.Add(FSHelper.Vector3ToFVector2(targetCSC.TransformPoints[i].localPosition)); } } List<FarseerPhysics.Common.Vertices> convexShapeVs = FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(concaveVertices); for(int i = 0; i < convexShapeVs.Count; i++) { GameObject newConvShape = new GameObject("convexShape"+i.ToString()); newConvShape.transform.parent = targetCSC.transform; newConvShape.transform.localPosition = Vector3.zero; newConvShape.transform.localRotation = Quaternion.Euler(Vector3.zero); newConvShape.transform.localScale = Vector3.one; FSShapeComponent shape0 = newConvShape.AddComponent<FSShapeComponent>(); shape0.CollidesWith = targetCSC.CollidesWith; shape0.CollisionFilter = targetCSC.CollisionFilter; shape0.BelongsTo = targetCSC.BelongsTo; shape0.CollisionGroup = targetCSC.CollisionGroup; shape0.Friction = targetCSC.Friction; shape0.Restitution = targetCSC.Restitution; shape0.Density = targetCSC.Density; shape0.UseUnityCollider = false; shape0.PolygonPoints = new Transform[convexShapeVs[i].Count]; for(int j = 0; j < convexShapeVs[i].Count; j++) { GameObject pnew = new GameObject("p"+j.ToString()); pnew.transform.parent = shape0.transform; pnew.transform.localPosition = FSHelper.FVector2ToVector3(convexShapeVs[i][j]); shape0.PolygonPoints[j] = pnew.transform; } } }