/** * @brief Initializes internal properties based on whether there is a {@link TSCollider2D} attached. **/ public void Initialize() { if (initialized) { return; } tsCollider = GetComponent <FPCollider2D>(); if (transform.parent != null) { tsParent = transform.parent.GetComponent <FPTransform2D>(); } if (!_serialized) { UpdateEditMode(); } if (tsCollider != null) { if (tsCollider.IsBodyInitialized) { tsCollider.Body.TSPosition = _position + scaledCenter; tsCollider.Body.TSOrientation = _rotation * FP.Deg2Rad; } } else { StateTracker.AddTracking(this); } initialized = true; }
internal void Update(GameObject otherGO, Physics2D.Contact c) { if (this.gameObject == null) { this.gameObject = otherGO; this.collider = this.gameObject.GetComponent <FPCollider2D>(); this.rigidbody = this.gameObject.GetComponent <FPRigidBody2D>(); this.transform = this.collider.FPTransform; } if (c != null) { if (contacts[0] == null) { contacts[0] = new TSContactPoint2D(); } FPVector2 normal; Physics2D.FixedArray2 <FPVector2> points; c.GetWorldManifold(out normal, out points); contacts[0].normal = normal; contacts[0].point = points[0]; this.relativeVelocity = c.CalculateRelativeVelocity(); } }
public void AddBody(ICollider iCollider) { if (!(iCollider is FPCollider2D)) { Debug.LogError("You have a 3D object but your Physics 3D is disabled."); return; } FPCollider2D tsCollider = (FPCollider2D)iCollider; if (tsCollider._body != null) { //already added return; } tsCollider.Initialize(world); gameObjectMap[tsCollider._body] = tsCollider.gameObject; if (tsCollider.gameObject.transform.parent != null && tsCollider.gameObject.transform.parent.GetComponentInParent <FPCollider2D>() != null) { FPCollider2D parentCollider = tsCollider.gameObject.transform.parent.GetComponentInParent <FPCollider2D>(); Physics2D.Body childBody = tsCollider._body; childBody.bodyConstraints.Add(new ConstraintHierarchy2D(((Physics2D.Body)parentCollider.Body), tsCollider._body, (tsCollider.GetComponent <FPTransform2D>().position + tsCollider.ScaledCenter) - (parentCollider.GetComponent <FPTransform2D>().position + parentCollider.ScaledCenter))); } world.ProcessAddedBodies(); }
/** * @brief Destroys a GameObject in a deterministic way. * * The method {@link #DestroyFPRigidBody} is called and attached FrameSyncBehaviors are disabled. * * @param rigidBody Instance of a {@link FPRigidBody} **/ public static void SyncedDestroy(GameObject gameObject) { if (instance != null && instance.lockstep != null) { SyncedDisableBehaviour(gameObject); FPCollider[] tsColliders = gameObject.GetComponentsInChildren <FPCollider>(); if (tsColliders != null) { for (int index = 0, length = tsColliders.Length; index < length; index++) { FPCollider tsCollider = tsColliders[index]; DestroyFPRigidBody(tsCollider.gameObject, tsCollider.Body); } } FPCollider2D[] tsColliders2D = gameObject.GetComponentsInChildren <FPCollider2D>(); if (tsColliders2D != null) { for (int index = 0, length = tsColliders2D.Length; index < length; index++) { FPCollider2D tsCollider2D = tsColliders2D[index]; DestroyFPRigidBody(tsCollider2D.gameObject, tsCollider2D.Body); } } } }
/** * @brief Removes objets related to a provided player. * * @param playerId Target player's id. **/ public static void RemovePlayer(int playerId) { if (instance != null && instance.lockstep != null) { List <FrameSyncManagedBehaviour> behaviorsList = instance.behaviorsByPlayer[(byte)playerId]; for (int index = 0, length = behaviorsList.Count; index < length; index++) { FrameSyncManagedBehaviour tsmb = behaviorsList[index]; tsmb.disabled = true; FPCollider[] tsColliders = ((FrameSyncBehaviour)tsmb.FrameSyncBehavior).gameObject.GetComponentsInChildren <FPCollider>(); if (tsColliders != null) { for (int index2 = 0, length2 = tsColliders.Length; index2 < length2; index2++) { FPCollider tsCollider = tsColliders[index2]; if (!tsCollider.Body.TSDisabled) { DestroyFPRigidBody(tsCollider.gameObject, tsCollider.Body); } } } FPCollider2D[] tsCollider2Ds = ((FrameSyncBehaviour)tsmb.FrameSyncBehavior).gameObject.GetComponentsInChildren <FPCollider2D>(); if (tsCollider2Ds != null) { for (int index2 = 0, length2 = tsCollider2Ds.Length; index2 < length2; index2++) { FPCollider2D tsCollider2D = tsCollider2Ds[index2]; if (!tsCollider2D.Body.TSDisabled) { DestroyFPRigidBody(tsCollider2D.gameObject, tsCollider2D.Body); } } } } } }
private static object OverlapGeneric(Physics2D.Shape shape, FPVector2 position, Physics2D.BodySpecialSensor sensorType, int layerMask) { Physics2D.World world = (Physics2D.World)Physics2DWorldManager.instance.GetWorld(); Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world); body.CreateFixture(shape); body.BodyType = Physics2D.BodyType.Static; body.IsSensor = true; body.CollidesWith = Physics2D.Category.All; body.SpecialSensor = sensorType; body.SpecialSensorMask = layerMask; body.Position = position; world.RemoveBody(body); world.ProcessRemovedBodies(); if (body._specialSensorResults.Count > 0) { if (sensorType == Physics2D.BodySpecialSensor.ActiveOnce) { return(Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[0]).GetComponent <FPCollider2D>()); } else { FPCollider2D[] result = new FPCollider2D[body._specialSensorResults.Count]; for (int i = 0; i < body._specialSensorResults.Count; i++) { result[i] = Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[i]).GetComponent <FPCollider2D>(); } return(result); } } return(null); }