| | 1 | | using UnityEngine; |
| | 2 | | using System; |
| | 3 | | using Variables.RealmsInfo; |
| | 4 | |
|
| | 5 | | namespace DCL |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Wrapper class to handle user's marker GameObject |
| | 9 | | /// </summary> |
| | 10 | | internal class UserPositionMarker : IDisposable |
| | 11 | | { |
| 0 | 12 | | public Vector2Int coords { set; get; } |
| 0 | 13 | | public string realmServer { set; get; } |
| 0 | 14 | | public string realmLayer { set; get; } |
| | 15 | |
|
| 10 | 16 | | public string name { set { markerObject.name = value; } } |
| | 17 | |
|
| 10 | 18 | | public Vector3 localPosition { set { markerObject.transform.localPosition = value; } } |
| | 19 | |
|
| | 20 | | private UserMarkerObject markerObject; |
| | 21 | |
|
| 1005 | 22 | | public UserPositionMarker(UserMarkerObject markerObject) |
| | 23 | | { |
| 1005 | 24 | | this.markerObject = markerObject; |
| 1005 | 25 | | markerObject.gameObject.SetActive(false); |
| 1005 | 26 | | } |
| | 27 | |
|
| | 28 | | public void SetActive(bool active) |
| | 29 | | { |
| 1014 | 30 | | if (active) |
| | 31 | | { |
| 7 | 32 | | OnRealmChanged(DataStore.i.realm.playerRealm.Get(), null); |
| 7 | 33 | | DataStore.i.realm.playerRealm.OnChange -= OnRealmChanged; |
| 7 | 34 | | DataStore.i.realm.playerRealm.OnChange += OnRealmChanged; |
| 7 | 35 | | } |
| | 36 | | else |
| | 37 | | { |
| 1007 | 38 | | DataStore.i.realm.playerRealm.OnChange -= OnRealmChanged; |
| | 39 | | } |
| | 40 | |
|
| 1014 | 41 | | markerObject.gameObject.SetActive(active); |
| 1014 | 42 | | } |
| | 43 | |
|
| | 44 | | public void Dispose() |
| | 45 | | { |
| 1005 | 46 | | DataStore.i.realm.playerRealm.OnChange -= OnRealmChanged; |
| 1005 | 47 | | UnityEngine.Object.Destroy(markerObject.gameObject); |
| 1005 | 48 | | } |
| | 49 | |
|
| | 50 | | private void OnRealmChanged(CurrentRealmModel current, CurrentRealmModel prev) |
| | 51 | | { |
| 7 | 52 | | if (current == null) |
| 7 | 53 | | return; |
| | 54 | |
|
| 0 | 55 | | SetColor(current.Equals(realmServer, realmLayer) ? markerObject.sameRealmColor : markerObject.otherRealmColo |
| 0 | 56 | | } |
| | 57 | |
|
| 0 | 58 | | private void SetColor(Color color) { markerObject.color = color; } |
| | 59 | | } |
| | 60 | | } |