| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using DCL.Interface; |
| | 4 | | using UnityEngine; |
| | 5 | | using DataStore = DCL.DataStore; |
| | 6 | |
|
| | 7 | | public static class BIWTeleportAndEdit |
| | 8 | | { |
| | 9 | | public static event Action<Vector2Int> OnTeleportStart; |
| | 10 | | public static event Action<Vector2Int> OnTeleportEnd; |
| | 11 | |
|
| | 12 | | private static bool inProgress = false; |
| | 13 | |
|
| | 14 | | public static bool TeleportAndEdit(Vector2Int targetCoords) |
| | 15 | | { |
| 1 | 16 | | if (inProgress) |
| 0 | 17 | | return false; |
| | 18 | |
|
| 1 | 19 | | CoroutineStarter.Start(TeleportAndEditRoutine(targetCoords)); |
| 1 | 20 | | return true; |
| | 21 | | } |
| | 22 | |
|
| | 23 | | private static IEnumerator TeleportAndEditRoutine(Vector2Int targetCoords) |
| | 24 | | { |
| 1 | 25 | | inProgress = true; |
| 1 | 26 | | OnTeleportStart?.Invoke(targetCoords); |
| | 27 | |
|
| 1 | 28 | | bool isPlayerTeleported = false; |
| | 29 | |
|
| 0 | 30 | | void OnPlayerTeleportToNewPosition(Vector3 current, Vector3 prev) { isPlayerTeleported = true; } |
| | 31 | |
|
| 1 | 32 | | DataStore.i.player.lastTeleportPosition.OnChange += OnPlayerTeleportToNewPosition; |
| | 33 | |
|
| 1 | 34 | | WebInterface.GoTo(targetCoords.x, targetCoords.y); |
| | 35 | |
|
| 260 | 36 | | yield return new WaitUntil(() => isPlayerTeleported); |
| 0 | 37 | | DataStore.i.player.lastTeleportPosition.OnChange -= OnPlayerTeleportToNewPosition; |
| | 38 | |
|
| 0 | 39 | | yield return new WaitUntil(() => CommonScriptableObjects.rendererState.Get()); |
| 0 | 40 | | yield return null; |
| | 41 | |
|
| 0 | 42 | | inProgress = false; |
| 0 | 43 | | OnTeleportEnd?.Invoke(targetCoords); |
| 0 | 44 | | } |
| | 45 | | } |