public void SetEnumToBodyType(JelloBody t) { if(t.GetComponent<JelloBody>().GetType().ToString() == "JelloBody") colliderType = ColliderType.Static; if(t.GetComponent<JelloBody>().GetType().ToString() == "JelloSpringBody") colliderType = ColliderType.Spring; if(t.GetComponent<JelloBody>().GetType().ToString() == "JelloPressureBody") colliderType = ColliderType.Pressure; }
public bool CompareEnumStateWithType(JelloBody t) { if(colliderType == ColliderType.Static && t.GetComponent<JelloBody>().GetType().ToString() == "JelloBody") return false; if(colliderType == ColliderType.Spring && t.GetComponent<JelloBody>().GetType().ToString() == "JelloSpringBody") return false; if(colliderType == ColliderType.Pressure && t.GetComponent<JelloBody>().GetType().ToString() == "JelloPressureBody") return false; return true; }
public void GetBodyMeshLinkType(JelloBody t) { if(t.meshLink == null) t.meshLink = t.GetComponent<MeshLink>(); if(t.meshLink == null) return; foreach(MeshLink.MeshLinkType mltype in (MeshLink.MeshLinkType[])Enum.GetValues(typeof(MeshLink.MeshLinkType))) { if(t.meshLink.GetType().ToString() == mltype.ToString()) { t.meshLink.meshLinkType = mltype; break; } } meshLinkType = t.meshLink.meshLinkType; }
public virtual void DrawEditorGUITwo() { serializedObject.Update(); if(tar.GetComponent<MeshLink>() != null) hasMeshLink = true; else hasMeshLink = false; EditorGUILayout.BeginHorizontal(); SerializedProperty eMeshLink = serializedObject.FindProperty("meshLink"); GUIStyle meshStyle = new GUIStyle(EditorStyles.popup); if(eMeshLink.prefabOverride) meshStyle.fontStyle = FontStyle.Bold; meshLinkType = (MeshLink.MeshLinkType)EditorGUILayout.EnumPopup(meshLinkTypeContent, meshLinkType, meshStyle); bool showChangeButton = false; if(hasMeshLink) { if(tar.GetComponent<MeshLink>().meshLinkType != meshLinkType) showChangeButton = true; } else if(meshLinkType != MeshLink.MeshLinkType.None) { showChangeButton = true; } if(showChangeButton) { if(GUILayout.Button(changeTypeContent, EditorStyles.miniButton)) { for(int i = 0; i < serializedObject.targetObjects.Length; i++) ChangeMeshLink((JelloBody)serializedObject.targetObjects[i]); } } EditorGUILayout.EndHorizontal(); colliderType = (ColliderType)EditorGUILayout.EnumPopup(bodyTypeContent, colliderType, EditorStyles.miniButton); EditorGUILayout.BeginHorizontal(); if(CompareEnumStateWithType(tar)) { EditorGUI.indentLevel++; if(GUILayout.Button(new GUIContent(changeTypeContent), EditorStyles.miniButton )) //todo make this change all targets { JelloBody[] oldTargets = new JelloBody[targets.Length]; for(int i = 0; i < serializedObject.targetObjects.Length; i++) { JelloBody t = (JelloBody)serializedObject.targetObjects[i]; ChangeBodyType(t, retainBodyInformation); oldTargets[i] = t; } for(int i = 0; i < oldTargets.Length; i++) { Undo.DestroyObjectImmediate (oldTargets[i]); } return; } retainBodyInformation = EditorGUILayout.Toggle(keepInfoContent, retainBodyInformation); EditorGUI.indentLevel--; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); string[] options = new string[subEditors.Count]; for(int i = 0; i < options.Length; i++) options[i] = subEditors[i].name; currentSubEditor = EditorGUILayout.Popup("SubComponent", currentSubEditor, options); EditorGUILayout.EndHorizontal(); subEditors[currentSubEditor].DrawEditorGUI(); serializedObject.ApplyModifiedProperties(); }
//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(); }