public void RegisterTarget(tnHoleTarget i_Target) { if (i_Target == null) { return; } m_Targets.Add(i_Target); }
private void ConfigureHoles() { tnHole[] holes = FindObjectsOfType <tnHole>(); tnHoleTarget[] holeTargets = FindObjectsOfType <tnHoleTarget>(); for (int targetIndex = 0; targetIndex < holeTargets.Length; ++targetIndex) { tnHoleTarget holeTarget = holeTargets[targetIndex]; for (int holeIndex = 0; holeIndex < holes.Length; ++holeIndex) { tnHole hole = holes[holeIndex]; hole.RegisterTarget(holeTarget); } } }
public void Clear() { for (int targetIndex = 0; targetIndex < m_Targets.Count; ++targetIndex) { tnHoleTarget holeTarget = m_Targets[targetIndex]; if (holeTarget == null) { continue; } if (holeTarget.isTeleporting && holeTarget.enteringHoleIndex == m_HoleIndex) { holeTarget.CancelTeleport(); } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (EditorApplication.isPlaying) { tnHoleTarget holeTarget = target as tnHoleTarget; if (holeTarget == null) { return; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Info", EditorStyles.boldLabel); EditorGUILayout.LabelField("Can enter hole: " + holeTarget.canEnterHole, EditorStyles.label); EditorGUILayout.LabelField("Teleporting: " + holeTarget.isTeleporting, EditorStyles.label); } }
// INTERNALS private void Internal_CacheTarget(int i_Tick, tnHoleTarget i_Target) { if (i_Target == null) { return; } List <tnHoleTarget> targets; bool alreadyPresent = m_Pending.TryGetValue(i_Tick, out targets); if (targets == null) { targets = new List <tnHoleTarget>(); } if (!alreadyPresent) { m_Pending.Add(i_Tick, targets); } targets.Add(i_Target); }
public override void OnSyncedUpdate() { base.OnSyncedUpdate(); if (!m_IsActive || m_HoleIndex < 0) { return; } // Get Simulation info. int currentTick = TrueSyncManager.ticksMain; int rollbackWindow = TrueSyncManager.rollbackWindowMain; // Check current collision TSVector2 myPosition = tsTransform2D.position; for (int targetIndex = 0; targetIndex < m_Targets.Count; ++targetIndex) { tnHoleTarget holeTarget = m_Targets[targetIndex]; if (holeTarget == null) { continue; } TSTransform2D otherTransform = holeTarget.GetComponent <TSTransform2D>(); if (otherTransform == null) { continue; } TSVector2 targetPosition = otherTransform.position; TSVector2 positionDelta = targetPosition - myPosition; FP distance2 = positionDelta.LengthSquared(); if (distance2 < m_Threshold * m_Threshold) { // Notify collision. holeTarget.CollidingWithHole(); // Add object to pending list. if (holeTarget.canEnterHole && !holeTarget.isTeleporting) { Internal_CacheTarget(currentTick, holeTarget); } } } // Check pending objects. for (int index = 0; index < m_Pending.count; ++index) { int tick = m_Pending.GetKey(index); if (currentTick == tick + rollbackWindow) { List <tnHoleTarget> holeTargets = m_Pending.GetValue(tick); if (holeTargets != null) { for (int targetIndex = 0; targetIndex < holeTargets.Count; ++targetIndex) { tnHoleTarget holeTarget = holeTargets[targetIndex]; if (holeTarget == null) { continue; } RespawnPoint respawnPoint = GetRandomSpawnPoint(); if (respawnPoint == null || respawnPoint.transform == null) { continue; } TSTransform2D targetTransform = holeTarget.tsTransform2D; TSRigidBody2D targetRigidbody = holeTarget.GetComponent <TSRigidBody2D>(); // Snap position. if (targetRigidbody != null) { targetRigidbody.MovePosition(tsTransform2D.position); } else { targetTransform.position = tsTransform2D.position; } // Set rigidbody velocity, if (targetRigidbody != null) { targetRigidbody.velocity = TSVector2.zero; } // Eavluate force TSVector2 forceDirection = respawnPoint.forceDirection; forceDirection.Normalize(); if (MathFP.Abs(respawnPoint.errorAngle) > FP.Zero) { int random = TSRandom.Range(0, 101); FP t = ((FP)random) / 100; FP randomError = MathFP.Lerp(-respawnPoint.errorAngle, respawnPoint.errorAngle, t); forceDirection = forceDirection.Rotate(randomError); } TSVector2 outForce = forceDirection * respawnPoint.forceIntensity; // Teleport. holeTarget.Teleport(m_HoleIndex, respawnPoint.respawnPosition, outForce, m_RespawnTime, m_InEffect, m_OutEffect); } } } } // Remove old data from dictionary. for (int index = 0; index < m_Pending.count; ++index) { int tick = m_Pending.GetKey(index); int executionTick = tick + rollbackWindow; bool isSafeTick = TrueSyncManager.IsTickOutOfRollbackMain(executionTick); if (isSafeTick) { m_Pending.Remove(tick); index = -1; } } }