| | 1 | | using DCL; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public class InfiniteFloorController : MonoBehaviour |
| | 5 | | { |
| 1 | 6 | | private static readonly int MAP_PROPERTY = Shader.PropertyToID("_Map"); |
| 1 | 7 | | private static readonly int ESTATE_ID_PROPERTY = Shader.PropertyToID("_EstateIDMap"); |
| 1 | 8 | | private static readonly int PLAYER_POSITION = Shader.PropertyToID("_PlayerPosition"); |
| | 9 | |
|
| | 10 | | [SerializeField] private Renderer renderer; |
| | 11 | |
|
| | 12 | | void OnEnable() |
| | 13 | | { |
| 82 | 14 | | CommonScriptableObjects.worldOffset.OnChange += OnWorldReposition; |
| | 15 | |
|
| 82 | 16 | | DataStore.i.HUDs.mapMainTexture.OnChange += OnMapTextureChanged; |
| 82 | 17 | | OnMapTextureChanged(DataStore.i.HUDs.latestDownloadedMainTexture.Get(), null); |
| | 18 | |
|
| 82 | 19 | | DataStore.i.HUDs.mapEstatesTexture.OnChange += OnEstateIdTextureChanged; |
| 82 | 20 | | OnMapTextureChanged(DataStore.i.HUDs.latestDownloadedMapEstatesTexture.Get(), null); |
| | 21 | |
|
| 82 | 22 | | CommonScriptableObjects.playerCoords.OnChange += OnPlayerCoordsChanged; |
| 82 | 23 | | OnPlayerCoordsChanged(CommonScriptableObjects.playerCoords.Get(), Vector2Int.zero); |
| 82 | 24 | | } |
| | 25 | |
|
| 180 | 26 | | private void OnPlayerCoordsChanged(Vector2Int current, Vector2Int previous) { renderer.material.SetVector(PLAYER_POS |
| | 27 | |
|
| 328 | 28 | | private void OnMapTextureChanged(Texture current, Texture previous) { renderer.material.SetTexture(MAP_PROPERTY, cur |
| | 29 | |
|
| 0 | 30 | | private void OnEstateIdTextureChanged(Texture current, Texture previous) { renderer.material.SetTexture(ESTATE_ID_PR |
| | 31 | |
|
| 4 | 32 | | void OnWorldReposition(UnityEngine.Vector3 current, UnityEngine.Vector3 previous) { transform.position = -current; } |
| | 33 | |
|
| | 34 | | void OnDisable() |
| | 35 | | { |
| 82 | 36 | | CommonScriptableObjects.worldOffset.OnChange -= OnWorldReposition; |
| 82 | 37 | | DataStore.i.HUDs.mapMainTexture.OnChange -= OnMapTextureChanged; |
| 82 | 38 | | DataStore.i.HUDs.mapEstatesTexture.OnChange -= OnEstateIdTextureChanged; |
| 82 | 39 | | CommonScriptableObjects.playerCoords.OnChange -= OnPlayerCoordsChanged; |
| 82 | 40 | | } |
| | 41 | | } |