public void CopyToStaticBody(JelloBody oldBody, JelloBody newBody) //TODO make sure these all are up to date with any new variables that need assigning { newBody.affectedByGravity = oldBody.affectedByGravity; newBody.disabled = oldBody.disabled; newBody.gravity = oldBody.gravity; newBody.IsAwake = oldBody.IsAwake; newBody.IsKinematic = oldBody.IsKinematic; newBody.IsStatic = tar.IsStatic; newBody.IsStatic = true; newBody.IsTrigger = oldBody.IsTrigger; newBody.overrideWorldGravity = oldBody.overrideWorldGravity; newBody.pivotOffset = oldBody.pivotOffset; newBody.setComponentReferences(); newBody.polyCollider = oldBody.polyCollider; if(oldBody.meshLink != null) { newBody.meshLink = oldBody.meshLink; newBody.meshLink.body = newBody; } if(oldBody.Shape != null) { newBody.setShape(oldBody.Shape, shapeSettingOptions); newBody.Mass = Mathf.Infinity; } for(int i = 0; i < oldBody.EdgePointMassCount; i++) { newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i); newBody.getEdgePointMass(i).Mass = Mathf.Infinity; newBody.getEdgePointMass(i).body = newBody; } for(int i = 0; i < oldBody.InternalPointMassCount; i++) { newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i); newBody.getInternalPointMass(i).Mass = Mathf.Infinity; newBody.getInternalPointMass(i).body = newBody; } for(int i = 0; i < oldBody.AttachPointCount; i++) { newBody.AddAttachPoint(oldBody.GetAttachPoint(i)); newBody.GetAttachPoint(i).body = newBody; } for(int i = 0; i < oldBody.JointCount; i++) { newBody.AddJoint(oldBody.GetJoint(i)); newBody.GetJoint(i).bodyA = newBody; } EditorUtility.SetDirty(newBody); }
//todo add onenable and ondisable events to body. public virtual void DrawEditorGUI() { //check polycollider vs pointmasscount if(!Application.isPlaying) //TODO have this be handled by a class that extends the polycollider and recognises changes? { for(int b = 0; b < targets.Length; b++) { JelloBody body = (JelloBody)targets[b]; body.setComponentReferences(); body.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(body.polyCollider.points); JelloClosedShape shape = new JelloClosedShape(body.polyCollider.points, null, false); if(body.Shape != null) { for(int i = 0; i < body.Shape.InternalVertexCount; i++) shape.addInternalVertex(body.Shape.InternalVertices[i]); shape.finish(false); } if(shape.EdgeVertexCount != body.Shape.EdgeVertexCount || shape.InternalVertexCount != body.Shape.InternalVertexCount) body.smartSetShape(shape, JelloBody.ShapeSettingOptions.MovePointMasses, smartShapeSettingOptions); else body.setShape(shape, JelloBody.ShapeSettingOptions.MovePointMasses); //will i need to do this for constraints as well? for(int i = 0; i < body.AttachPointCount; i++) { body.GetAttachPoint(i).UpdateEditorMode(); } } } serializedObject.Update(); EditorGUI.showMixedValue = eMass.hasMultipleDifferentValues; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(eMass, massContent); if(EditorGUI.EndChangeCheck()) { for(int i = 0; i < serializedObject.targetObjects.Length; i++) { JelloBody b = (JelloBody)serializedObject.targetObjects[i]; b.Mass = eMass.floatValue; } serializedObject.UpdateIfDirtyOrScript(); } EditorGUI.showMixedValue = false; if(!tar.IsStatic) { EditorGUILayout.BeginHorizontal(); EditorGUI.showMixedValue = eAffectedByGravity.hasMultipleDifferentValues; EditorGUILayout.PropertyField(eAffectedByGravity, useGravContent); EditorGUI.showMixedValue = false; EditorGUILayout.EndHorizontal(); if(eAffectedByGravity.boolValue) { EditorGUI.indentLevel++; EditorGUI.showMixedValue = eOverrideGravity.hasMultipleDifferentValues; EditorGUILayout.PropertyField(eOverrideGravity, overrideGravContent); EditorGUI.showMixedValue = false; if(eOverrideGravity.boolValue) { EditorGUI.indentLevel++; EditorGUI.showMixedValue = eGravity.hasMultipleDifferentValues; EditorGUILayout.PropertyField(eGravity, customGravContent); EditorGUI.showMixedValue = false; EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } EditorGUI.showMixedValue = eKinematic.hasMultipleDifferentValues; EditorGUILayout.PropertyField(eKinematic, kinematicContent); EditorGUI.showMixedValue = false; } EditorGUI.showMixedValue = eTrigger.hasMultipleDifferentValues; EditorGUILayout.PropertyField(eTrigger, triggerContent); EditorGUI.showMixedValue = false; EditorGUI.showMixedValue = eAwake.hasMultipleDifferentValues; EditorGUILayout.PropertyField(eAwake, awakeContent); EditorGUI.showMixedValue = false; if(tar.meshLink == null || tar.meshLink.canModifyPivotPoint) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); SerializedProperty ePivotOffset = serializedObject.FindProperty("pivotOffset"); GUIStyle pivotStyle = new GUIStyle(EditorStyles.foldout); if(ePivotOffset.prefabOverride) pivotStyle.fontStyle = FontStyle.Bold; showPivot = EditorGUILayout.Foldout(showPivot, pivotFoldoutContent, pivotStyle); if(GUILayout.Button(centerPivotContent, EditorStyles.miniButton)) { Undo.RecordObjects(serializedObject.targetObjects, "Center Pivot"); for(int i = 0; i < serializedObject.targetObjects.Length; i++) { JelloBody jb = (JelloBody)serializedObject.targetObjects[i]; Undo.RecordObject(jb.gameObject.transform, "Center Pivot transform"); if(jb.meshLink != null) { Undo.RecordObject(jb.meshLink, "Center Pivot mesh"); Undo.RecordObject(jb.polyCollider, "Center Pivot collider"); Undo.RecordObject(jb.GetComponent<Renderer>(), "Center Pivot renderer"); Undo.RecordObject(jb.meshLink.LinkedMeshFilter, "Center Pivot filter"); } } for(int i = 0; i < serializedObject.targetObjects.Length; i++) { JelloBody bod = (JelloBody)serializedObject.targetObjects[i]; CenterPivot(bod); EditorUtility.SetDirty(bod.gameObject); EditorUtility.SetDirty(bod.meshLink); //serializedObject.UpdateIfDirtyOrScript(); } SceneView.RepaintAll(); } EditorGUILayout.EndHorizontal(); if(showPivot) { if(!serializedObject.isEditingMultipleObjects) { pivot = EditorGUILayout.Vector2Field("Position", pivot); if(pivot != Vector2.zero) { EditorGUILayout.BeginHorizontal(); if(GUILayout.Button(applyPivotContent, EditorStyles.miniButton)) { JelloBody jb = (JelloBody)serializedObject.targetObject; Undo.RecordObject(jb, "Change Pivot"); Undo.RecordObject(jb.gameObject.transform, "Change Pivot transform"); if(jb.meshLink != null) { Undo.RecordObject(jb.meshLink, "Change Pivot mesh"); Undo.RecordObject(jb.polyCollider, "Change Pivot collider"); Undo.RecordObject(jb.GetComponent<Renderer>(), "Change Pivot renderer"); Undo.RecordObject(jb.meshLink.LinkedMeshFilter, "Change Pivot filter"); } ChangePivot(tar); EditorUtility.SetDirty(tar.gameObject); EditorUtility.SetDirty(tar.meshLink); // serializedObject.UpdateIfDirtyOrScript(); } if(GUILayout.Button(cancelPivotContent, EditorStyles.miniButton)) pivot = Vector2.zero; SceneView.RepaintAll(); EditorGUILayout.EndHorizontal(); } } else { EditorGUILayout.HelpBox("Pivot Points may only be centered when multiple Game Objects are selected", MessageType.Info); } } EditorGUI.indentLevel--; } serializedObject.ApplyModifiedProperties(); }
//TODO make sure these all are up to date with any new variables that need assigning public void CopyToStaticBody(JelloBody oldBody, JelloBody newBody) { newBody.affectedByGravity = oldBody.affectedByGravity; newBody.disabled = oldBody.disabled; newBody.gravity = oldBody.gravity; newBody.IsAwake = oldBody.IsAwake; newBody.IsKinematic = oldBody.IsKinematic; newBody.IsStatic = tar.IsStatic; newBody.IsStatic = true; newBody.IsTrigger = oldBody.IsTrigger; newBody.overrideWorldGravity = oldBody.overrideWorldGravity; newBody.pivotOffset = oldBody.pivotOffset; newBody.setComponentReferences(); newBody.polyCollider = oldBody.polyCollider; if(oldBody.meshLink != null) { newBody.meshLink = oldBody.meshLink; newBody.meshLink.body = newBody; } if(oldBody.Shape != null) { newBody.setShape(oldBody.Shape, shapeSettingOptions); newBody.Mass = Mathf.Infinity; } for(int i = 0; i < oldBody.EdgePointMassCount; i++) { newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i); newBody.getEdgePointMass(i).Mass = Mathf.Infinity; newBody.getEdgePointMass(i).body = newBody; } for(int i = 0; i < oldBody.InternalPointMassCount; i++) { newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i); newBody.getInternalPointMass(i).Mass = Mathf.Infinity; newBody.getInternalPointMass(i).body = newBody; } for(int i = 0; i < oldBody.AttachPointCount; i++) { newBody.AddAttachPoint(oldBody.GetAttachPoint(i)); newBody.GetAttachPoint(i).body = newBody; } for(int i = 0; i < oldBody.JointCount; i++) { newBody.AddJoint(oldBody.GetJoint(i)); newBody.GetJoint(i).bodyA = newBody; } EditorUtility.SetDirty(newBody); }