public override void CopyToPressureBody(JelloBody oldBody, JelloPressureBody newBody) { base.CopyToPressureBody(oldBody, newBody); JelloSpringBody old = (JelloSpringBody)oldBody; newBody.ShapeMatching = old.ShapeMatching; newBody.DefaultEdgeSpringStiffness = old.DefaultEdgeSpringStiffness; newBody.DefaultEdgeSpringDamping = old.DefaultEdgeSpringDamping; newBody.DefaultCustomSpringDamping = old.DefaultCustomSpringDamping; newBody.DefaultCustomSpringStiffness = old.DefaultCustomSpringStiffness; newBody.DefaultInternalSpringDamping = old.DefaultInternalSpringDamping; newBody.DefaultInternalSpringStiffness = old.DefaultInternalSpringStiffness; newBody.ShapeSpringDamping = old.ShapeSpringDamping; newBody.ShapeSpringStiffness = old.ShapeSpringStiffness; newBody.setInternalSprings(old.getInternalSprings()); for (int i = 0; i < old.CustomSpringCount; i++) { newBody.addCustomSpring(old.getCustomSpring(i)); } }
public void DrawCustomSpringsGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(eCustomSprings, customSpringsContent); if (EditorGUI.EndChangeCheck()) { if (eCustomSprings.isExpanded) { eEdgeSprings.isExpanded = false; eInternalSprings.isExpanded = false; } drawIndex = -1; editIndex = -1; SceneView.RepaintAll(); } if (eCustomSprings.isExpanded) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); if (eCustomSpringK.prefabOverride || eCustomSpringDamp.prefabOverride) { foldoutStyle.fontStyle = FontStyle.Bold; } showCustomDefaultsFoldout = EditorGUILayout.Foldout(showCustomDefaultsFoldout, customDefaultsContent, foldoutStyle); if (GUILayout.Button(setDefaultCustomContent, EditorStyles.miniButton)) { for (int i = 0; i < springBodyEditor.serializedObject.targetObjects.Length; i++) { JelloSpringBody t = (JelloSpringBody)springBodyEditor.serializedObject.targetObjects[i]; t.setCustomSpringConstants(t.DefaultCustomSpringStiffness, t.DefaultCustomSpringDamping); } EditorUtility.SetDirty(springBody); } EditorGUILayout.EndHorizontal(); if (showCustomDefaultsFoldout) { EditorGUI.showMixedValue = eCustomSpringK.hasMultipleDifferentValues; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(eCustomSpringK, stiffnessContent); if (EditorGUI.EndChangeCheck()) { for (int i = 0; i < springBodyEditor.serializedObject.targetObjects.Length; i++) { JelloSpringBody sb = (JelloSpringBody)springBodyEditor.serializedObject.targetObjects[i]; sb.DefaultCustomSpringStiffness = eCustomSpringK.floatValue; } EditorUtility.SetDirty(springBody); } EditorGUI.showMixedValue = false; EditorGUI.showMixedValue = eCustomSpringDamp.hasMultipleDifferentValues; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(eCustomSpringDamp, dampingContent); if (EditorGUI.EndChangeCheck()) { for (int i = 0; i < springBodyEditor.serializedObject.targetObjects.Length; i++) { JelloSpringBody sb = (JelloSpringBody)springBodyEditor.serializedObject.targetObjects[i]; sb.DefaultCustomSpringDamping = eCustomSpringDamp.floatValue; } EditorUtility.SetDirty(springBody); } EditorGUI.showMixedValue = false; } EditorGUILayout.Separator(); if (multiEditing) { EditorGUILayout.HelpBox("Springs may not be edited when multiple GameObjects are selected", MessageType.Info); EditorGUI.indentLevel--; return; } int offset = springBody.EdgeSpringCount + springBody.InternalSpringCount; // custom springs come after edge springs and internal springs. scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false, GUILayout.MinHeight(minScrollViewHeight)); for (int i = 0; i < springBody.CustomSpringCount; i++) { EditorGUILayout.BeginHorizontal(); string text = "Spring # " + (i + offset); string tooltip = "PMA: " + springBody.getCustomSpring(i).pointMassA + " \nPMB: " + springBody.getCustomSpring(i).pointMassB + "\nRest Length: " + springBody.getCustomSpring(i).length + "\nSpring K: " + springBody.getCustomSpring(i).stiffness + "\nDamping: " + springBody.getCustomSpring(i).damping; SerializedProperty eSpring = eCustomSprings.GetArrayElementAtIndex(i); eSpring.isExpanded = editIndex == i + offset; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(eSpring, new GUIContent(text, tooltip)); if (EditorGUI.EndChangeCheck()) { if (!eSpring.isExpanded) { editIndex = -1; } else if (eSpring.isExpanded) { editIndex = i + offset; handlePositions[0] = springBody.Shape.getVertex(springBody.getCustomSpring(i).pointMassA); handlePositions[1] = springBody.Shape.getVertex(springBody.getCustomSpring(i).pointMassB); } SceneView.RepaintAll(); } if (Event.current.type == EventType.Repaint && GUI.tooltip != prevTooltip) { //mouse out if (prevTooltip != "") { drawIndex = -1; } //mouse over if (GUI.tooltip != "") { drawIndex = i + offset; //offset this in internal springs and in custom springs... } prevTooltip = GUI.tooltip; SceneView.RepaintAll(); } if (GUILayout.Button(deleteSpringContent, EditorStyles.miniButton, GUILayout.Width(20f))) { springBody.RemoveSpring(springBody.getCustomSpring(i)); if (editIndex > i + offset) { editIndex--; } else if (editIndex == i + offset) { editIndex = -1; } if (drawIndex > i + offset) { drawIndex--; } else if (editIndex == i + offset) { drawIndex = -1; } EditorUtility.SetDirty(springBody); break; } EditorGUILayout.EndHorizontal(); if (editIndex == i + offset) //offset this in internal and custom { DrawEditSpringGUI(eCustomSprings, i); } } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel--; } }