/// <summary> /// Places the decal at the given point. /// </summary> /// <param name="interactionResult">The interaction result this decal is being created for.</param> /// <param name="point">The point at which to place the decal.</param> /// <param name="normal">The surface normal used to set the decal rotation.</param> public override void SetupDecal(DecalInteractionResult interactionResult, Vector3 point, Vector3 normal) { transform.position = point + normal * _decalDistance; if (RotationMode == DecalRotationMode.Random) { transform.rotation = getNormalRotation(normal); rotateRandom(); } else if (RotationMode == DecalRotationMode.Velocity) { transform.rotation = getVelocityRotation(normal, interactionResult.OriginalData.Velocity); } else { transform.rotation = getNormalRotation(normal); } if (ParentToObject && interactionResult.OriginalData.OtherObject) { transform.SetParent(interactionResult.OriginalData.OtherObject.transform); parentObject = interactionResult.OriginalData.OtherObject.GetOrAddComponent <DestroyMessenger>(); parentObject.OnDestroyed += onParentDestroyed; } else { transform.SetParent(OriginalParent, true); } }
/// <summary> /// Updates for sliding and rolling and places new decals if applicable. /// </summary> /// <param name="newResult">The new interaction result.</param> public void KeepAlive(IInteractionResult newResult) { IsAlive = true; DecalInteractionResult decalInteractionResult = newResult as DecalInteractionResult; if (CreationIntervalType == InteractionIntervalType.Time) { intervalCounter += Time.fixedDeltaTime; } else { intervalCounter = Vector3.Distance(decalInteractionResult.OriginalData.Point, previousCreationPosition); } if (intervalCounter >= currentCreationIntervalTarget) { currentCreationIntervalTarget = CreationInterval.RandomInRange(); if (newResult.IsValid) { ImpactDecalPool.CreateDecal(this, decalInteractionResult.OriginalData.Point, decalInteractionResult.OriginalData.Normal); } intervalCounter = 0; previousCreationPosition = decalInteractionResult.OriginalData.Point; } OriginalData = decalInteractionResult.OriginalData; }
/// <summary> /// Retrieve a decal from the pool. /// This will ALWAYS return a decal. If all decals are unavailable, the oldest active decal will be used. /// </summary> /// <param name="collisionResult">The result to create the decal for.</param> /// <param name="point">The point at which to place the decal.</param> /// <param name="normal">The surface normal for the decal rotation.</param> /// <returns>An ImpactDecal instance.</returns> public static ImpactDecalBase CreateDecal(DecalInteractionResult collisionResult, Vector3 point, Vector3 normal) { if (collisionResult.DecalTemplate == null) { return(null); } ImpactDecalPool pool = poolGroup.GetOrCreatePool(collisionResult.DecalTemplate, collisionResult.DecalTemplate.PoolSize); if (pool != null) { ImpactDecalBase a = pool.GetObject(); if (a != null) { a.SetupDecal(collisionResult, point, normal); } return(a); } return(null); }
/// <summary> /// Places the decal at the given point. /// </summary> /// <param name="interactionResult">The interaction result this decal is being created for.</param> /// <param name="point">The point at which to place the decal.</param> /// <param name="normal">The surface normal used to set the decal rotation.</param> public abstract void SetupDecal(DecalInteractionResult interactionResult, Vector3 point, Vector3 normal);