Exemplo n.º 1
0
    public SpringSubComponentEditor(Editor editor) : base(editor)
    {
        name             = "Springs";
        springBodyEditor = (JelloSpringBodyEditor)editor;
        springBody       = (JelloSpringBody)springBodyEditor.serializedObject.targetObject;

        handlePositions = new Vector3[2];
        handleSizes     = new float[2];

        eShapeMatching      = springBodyEditor.serializedObject.FindProperty("mShapeMatchingOn");
        eShapeSpringK       = springBodyEditor.serializedObject.FindProperty("mShapeSpringK");
        eShapeSpringDamp    = springBodyEditor.serializedObject.FindProperty("mShapeSpringDamp");
        eEdgeSpringK        = springBodyEditor.serializedObject.FindProperty("mDefaultEdgeSpringK");
        eEdgeSpringDamp     = springBodyEditor.serializedObject.FindProperty("mDefaultEdgeSpringDamp");
        eInternalSpringK    = springBodyEditor.serializedObject.FindProperty("mDefaultInternalSpringK");
        eInternalSpringDamp = springBodyEditor.serializedObject.FindProperty("mDefaultInternalSpringDamp");
        eCustomSpringK      = springBodyEditor.serializedObject.FindProperty("mDefaultCustomSpringK");
        eCustomSpringDamp   = springBodyEditor.serializedObject.FindProperty("mDefaultCustomSpringDamp");
        eEdgeSprings        = springBodyEditor.serializedObject.FindProperty("mEdgeSprings");
        eInternalSprings    = springBodyEditor.serializedObject.FindProperty("mInternalSprings");
        eCustomSprings      = springBodyEditor.serializedObject.FindProperty("mCustomSprings");

        drawIndex            = editIndex = -1;
        newSpring            = null;
        newSubComponentState = AddSubComponentState.inactive;
    }
Exemplo n.º 2
0
	protected virtual void DrawEditPointMassGUI(SerializedProperty pointMassArray, int index, bool isInternal)
	{
		SerializedProperty eMass = pointMassArray.GetArrayElementAtIndex(index).FindPropertyRelative("mMass");
		SerializedProperty eMultiplier = pointMassArray.GetArrayElementAtIndex(index).FindPropertyRelative("shapeMatchingMultiplier");
		SerializedProperty eForceInternal = pointMassArray.GetArrayElementAtIndex(index).FindPropertyRelative("forceInternal");

		SerializedProperty ePosition; 
		if(isInternal)
			ePosition = mainEditor.serializedObject.FindProperty("mBaseShape").FindPropertyRelative("mInternalVertices").GetArrayElementAtIndex(index);
		else
			ePosition = mainEditor.serializedObject.FindProperty("mBaseShape").FindPropertyRelative("mEdgeVertices").GetArrayElementAtIndex(index);

		if(!body.IsStatic)
			EditorGUILayout.PropertyField(eMass, massContent);

		if(body.GetType() == typeof(JelloSpringBody) || body.GetType() == typeof(JelloPressureBody))
		{
			JelloSpringBody b = (JelloSpringBody)body;
			
			if(b.ShapeMatching)
				EditorGUILayout.PropertyField(eMultiplier, shapeMatchingMultiplierContent);
		}

		if(isInternal)
			EditorGUILayout.PropertyField(eForceInternal, forceInternalContent);

		GUIStyle style = new GUIStyle(EditorStyles.label);
		if(ePosition.prefabOverride)
			style.fontStyle = FontStyle.Bold;

		EditorGUILayout.LabelField("Position", body.transform.TransformPoint(body.Shape.getVertex(editIndex)).ToString(), style);
	}
    public virtual void CopyToSpringBody(JelloBody oldBody, JelloSpringBody newBody)
    {
        newBody.affectedByGravity    = oldBody.affectedByGravity;
        newBody.disabled             = oldBody.disabled;
        newBody.gravity              = oldBody.gravity;
        newBody.IsAwake              = oldBody.IsAwake;
        newBody.IsKinematic          = oldBody.IsKinematic;
        newBody.IsStatic             = false;
        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 = oldBody.Mass != Mathf.Infinity ? oldBody.Mass : 1f;
        }

        for (int i = 0; i < oldBody.EdgePointMassCount; i++)
        {
            newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i);
            newBody.getEdgePointMass(i).body = newBody;

            if (oldBody.Mass == Mathf.Infinity)
            {
                newBody.getEdgePointMass(i).Mass = 1f;
            }
        }
        for (int i = 0; i < oldBody.InternalPointMassCount; i++)
        {
            newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i);
            newBody.getInternalPointMass(i).body = newBody;

            if (oldBody.Mass == Mathf.Infinity)
            {
                newBody.getInternalPointMass(i).Mass = 1f;
            }
        }
        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);
    }
	// Use this for initialization
	void Start () 
	{
		//cache the body
		body = GetComponent<JelloSpringBody>();

		//subscribe to the JelloCollisionEvent delegate.
		body.JelloCollisionEvent += ProcessCollisionEvent;
	}
Exemplo n.º 5
0
    public GUIContent percentContent  = new GUIContent(" % ");      //, "Percent by which to change body solidity");


    public override void Enabled()
    {
        base.Enabled();

        springTar = (JelloSpringBody)serializedObject.targetObject;

        subEditors.Add(new SpringSubComponentEditor(this));
    }
	public override void CopyToSpringBody (JelloBody oldBody, JelloSpringBody newBody)
	{
		base.CopyToSpringBody (oldBody, newBody);
		
		JelloPressureBody old = (JelloPressureBody)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 override void CopyToSpringBody(JelloBody oldBody, JelloSpringBody newBody)
    {
        base.CopyToSpringBody (oldBody, newBody);

        JelloPressureBody old = (JelloPressureBody)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));
        }
    }
Exemplo n.º 8
0
    public override void DrawEditorGUI()
    {
        base.DrawEditorGUI();

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.LabelField(solidityContent, GUILayout.Width(50));

        if (GUILayout.Button(minusContent, EditorStyles.miniButton, GUILayout.Width(20)))
        {
            for (int i = 0; i < serializedObject.targetObjects.Length; i++)
            {
                JelloSpringBody sb = (JelloSpringBody)serializedObject.targetObjects[i];
                sb.modifySolidityByPercent(-percentSolidityChange);

                EditorUtility.SetDirty(sb);
            }
        }
        if (GUILayout.Button(plusContent, EditorStyles.miniButton, GUILayout.Width(20)))
        {
            for (int i = 0; i < serializedObject.targetObjects.Length; i++)
            {
                JelloSpringBody sb = (JelloSpringBody)serializedObject.targetObjects[i];
                sb.modifySolidityByPercent(percentSolidityChange);

                EditorUtility.SetDirty(sb);
            }
        }
        EditorGUIUtility.labelWidth = 20f;
        EditorGUIUtility.fieldWidth = 15f;
        percentSolidityChange       = EditorGUILayout.FloatField(percentContent, Mathf.Clamp(percentSolidityChange, 0f, 100f));
        EditorGUIUtility.labelWidth = 0f;
        EditorGUIUtility.fieldWidth = 0f;

        EditorGUILayout.EndHorizontal();
    }
    public override void Enabled()
    {
        base.Enabled ();

        springTar = (JelloSpringBody)serializedObject.targetObject;

        subEditors.Add (new SpringSubComponentEditor(this));
    }
Exemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        //cache the body
        body = GetComponent<JelloSpringBody>();

        //subscribe to the JelloCollisionEvent delegate.
        body.JelloCollisionEvent += ProcessCollisionEvent;
    }
Exemplo n.º 11
0
    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--;
        }
    }
    public SpringSubComponentEditor(Editor editor)
        : base(editor)
    {
        name = "Springs";
        springBodyEditor = (JelloSpringBodyEditor)editor;
        springBody = (JelloSpringBody)springBodyEditor.serializedObject.targetObject;

        handlePositions = new Vector3[2];
        handleSizes = new float[2];

        eShapeMatching = springBodyEditor.serializedObject.FindProperty("mShapeMatchingOn");
        eShapeSpringK = springBodyEditor.serializedObject.FindProperty("mShapeSpringK");
        eShapeSpringDamp = springBodyEditor.serializedObject.FindProperty("mShapeSpringDamp");
        eEdgeSpringK = springBodyEditor.serializedObject.FindProperty("mDefaultEdgeSpringK");
        eEdgeSpringDamp = springBodyEditor.serializedObject.FindProperty("mDefaultEdgeSpringDamp");
        eInternalSpringK = springBodyEditor.serializedObject.FindProperty("mDefaultInternalSpringK");
        eInternalSpringDamp = springBodyEditor.serializedObject.FindProperty("mDefaultInternalSpringDamp");
        eCustomSpringK = springBodyEditor.serializedObject.FindProperty("mDefaultCustomSpringK");
        eCustomSpringDamp = springBodyEditor.serializedObject.FindProperty("mDefaultCustomSpringDamp");
        eEdgeSprings = springBodyEditor.serializedObject.FindProperty("mEdgeSprings");
        eInternalSprings = springBodyEditor.serializedObject.FindProperty("mInternalSprings");
        eCustomSprings = springBodyEditor.serializedObject.FindProperty("mCustomSprings");

        drawIndex = editIndex = -1;
        newSpring = null;
        newSubComponentState = AddSubComponentState.inactive;
    }
Exemplo n.º 13
0
    public virtual void CopyToSpringBody(JelloBody oldBody, JelloSpringBody newBody)
    {
        newBody.affectedByGravity = oldBody.affectedByGravity;
        newBody.disabled = oldBody.disabled;
        newBody.gravity = oldBody.gravity;
        newBody.IsAwake = oldBody.IsAwake;
        newBody.IsKinematic = oldBody.IsKinematic;
        newBody.IsStatic = false;
        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 = oldBody.Mass != Mathf.Infinity ? oldBody.Mass : 1f;
        }

        for(int i = 0; i < oldBody.EdgePointMassCount; i++)
        {
            newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i);
            newBody.getEdgePointMass(i).body = newBody;

            if(oldBody.Mass == Mathf.Infinity)
                newBody.getEdgePointMass(i).Mass = 1f;
        }
        for(int i = 0; i < oldBody.InternalPointMassCount; i++)
        {
            newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i);
            newBody.getInternalPointMass(i).body = newBody;

            if(oldBody.Mass == Mathf.Infinity)
                newBody.getInternalPointMass(i).Mass = 1f;
        }
        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);
    }