This looks like a job for reflection:
public T MockType<T>(Dictionary<string,object> fieldValues, params object[] consParams)
{
var type = typeof (T);
var cons = type.GetConstructor(BindingFlags.NonPublic,
Type.DefaultBinder,
consParams.Select(p => p.GetType()).ToArray(),
null);
var result = (T)cons.Invoke(consParams ?? new object[0]); // invoke non-public constructor
foreach (var fieldValue in fieldValues)
{
var field = type.GetField(fieldValue.Key, BindingFlags.NonPublic)
field.SetValue(result, fieldValue.Value); // Set non-public field
}
return result;
}
// Example method demonstrating use:
public Collision2D MockCollision2D(Rigidbody2D rigidbody,
Collider2D collider,
Vector2 relativeVelocity,
ContactPoint2D[] contacts)
{
return MockType<Collision2D>(new Dictionary<string, object>
{
// Use a decompiler like ILSpy to find out what the internal fields' names are:
{"m_Rigidbody", rigidbody},
{"m_Collider", collider},
{"m_RelativeVelocity", relativeVelocity},
{"m_Contacts", contacts}
},
new object[0]
);
}
I haven't tested this, so it might need some tweaks. The game object the collision refers to is drawn from the collider field.
Rect.Overlaps
continuously to see if one collider's Rect overlaps another collider's Rect? docs.unity3d.com/ScriptReference/Rect.Overlaps.html \$\endgroup\$