Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
    public void ChangePivot(JelloBody t)
    {
        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);

        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);

        Vector2 diff = pivot;

        diff = new Vector2(diff.x / t.Scale.x, diff.y / t.Scale.y);
        diff = JelloVectorTools.rotateVector(diff, -t.Angle);


        if (t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if (t.meshLink.UpdatePivotPoint(diff, out monoBehavior))
            {
                EditorUtility.SetDirty(monoBehavior);
            }
        }

        for (int i = 0; i < t.Shape.VertexCount; i++)
        {
            t.Shape.setVertex(i, t.Shape.getVertex(i) - diff);
        }

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(diff.x * t.Scale.x, diff.y * t.Scale.y), t.Angle);
        if (t.transform.childCount > 0)
        {
            for (int i = 0; i < t.transform.childCount; i++)
            {
                t.transform.GetChild(i).position -= (Vector3)diff;
            }
        }

        if (t.JointCount > 0)
        {
            for (int i = 0; i < t.JointCount; i++)
            {
                t.GetJoint(i).localAnchorA -= diff;
            }
        }

        if (t.AttachPointCount > 0)
        {
            for (int i = 0; i < t.AttachPointCount; i++)
            {
                t.GetAttachPoint(i).point -= diff;
            }
        }

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }
Ejemplo n.º 3
0
    public void CenterPivot(JelloBody t)
    {
        Vector2 center = new Vector2();

        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);
        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);


        center = JelloShapeTools.FindCenter(t.Shape.EdgeVertices);        //using vertices instead of collider.points because need of assigning entire array at once


        if (t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if (t.meshLink.UpdatePivotPoint(center, out monoBehavior))
            {
                EditorUtility.SetDirty(monoBehavior);
            }
        }

        for (int i = 0; i < t.Shape.VertexCount; i++)
        {
            t.Shape.setVertex(i, t.Shape.getVertex(i) - center);
        }

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(center.x * t.Scale.x, center.y * t.Scale.y), t.Angle);
        if (t.transform.childCount > 0)
        {
            for (int i = 0; i < t.transform.childCount; i++)
            {
                t.transform.GetChild(i).position -= (Vector3)center;
            }
        }

        if (t.JointCount > 0)
        {
            for (int i = 0; i < t.JointCount; i++)
            {
                t.GetJoint(i).localAnchorA -= center;
            }
        }

        if (t.AttachPointCount > 0)
        {
            for (int i = 0; i < t.AttachPointCount; i++)
            {
                t.GetAttachPoint(i).point -= center;
            }
        }

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }
Ejemplo n.º 4
0
	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);
	}
Ejemplo n.º 5
0
	//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();
	}
Ejemplo n.º 6
0
    //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);
    }
Ejemplo n.º 7
0
    public void ChangePivot(JelloBody t)
    {
        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);

        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);

        Vector2 diff = pivot;
        diff = new Vector2(diff.x / t.Scale.x, diff.y / t.Scale.y);
        diff = JelloVectorTools.rotateVector( diff, -t.Angle);

        if(t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if(t.meshLink.UpdatePivotPoint(diff, out monoBehavior))
                EditorUtility.SetDirty(monoBehavior);
        }

        for(int i = 0; i < t.Shape.VertexCount; i++)
            t.Shape.setVertex(i, t.Shape.getVertex(i) - diff);

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(diff.x * t.Scale.x, diff.y * t.Scale.y), t.Angle);
        if(t.transform.childCount > 0)
            for(int i = 0; i < t.transform.childCount; i++)
                t.transform.GetChild(i).position -= (Vector3)diff;

        if(t.JointCount > 0)
            for(int i = 0; i < t.JointCount; i++)
                t.GetJoint (i).localAnchorA -= diff;

        if(t.AttachPointCount > 0)
            for(int i = 0; i < t.AttachPointCount; i++)
                t.GetAttachPoint(i).point -= diff;

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }
Ejemplo n.º 8
0
    public void CenterPivot(JelloBody t)
    {
        Vector2 center = new Vector2();

        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);
        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);

        center = JelloShapeTools.FindCenter(t.Shape.EdgeVertices);//using vertices instead of collider.points because need of assigning entire array at once

        if(t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if(t.meshLink.UpdatePivotPoint(center, out monoBehavior))
                EditorUtility.SetDirty(monoBehavior);
        }

        for(int i = 0; i < t.Shape.VertexCount; i++)
            t.Shape.setVertex(i, t.Shape.getVertex(i) - center);

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(center.x * t.Scale.x, center.y * t.Scale.y), t.Angle);
        if(t.transform.childCount > 0)
            for(int i = 0; i < t.transform.childCount; i++)
                t.transform.GetChild(i).position -= (Vector3)center;

        if(t.JointCount > 0)
            for(int i = 0; i < t.JointCount; i++)
                t.GetJoint (i).localAnchorA -= center;

        if(t.AttachPointCount > 0)
            for(int i = 0; i < t.AttachPointCount; i++)
                t.GetAttachPoint(i).point -= center;

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }