| | 1 | | using DCL.Helpers; |
| | 2 | | using DCL.Interface; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class RenderingController : MonoBehaviour |
| | 6 | | { |
| 0 | 7 | | public static float firstActivationTime { get; private set; } |
| | 8 | | private bool firstActivationTimeHasBeenSet = false; |
| | 9 | | private bool VERBOSE = false; |
| | 10 | |
|
| 210 | 11 | | public CompositeLock renderingActivatedAckLock = new CompositeLock(); |
| | 12 | |
|
| 0 | 13 | | private bool activatedRenderingBefore { get; set; } = false; |
| | 14 | |
|
| | 15 | | void Awake() |
| | 16 | | { |
| 105 | 17 | | CommonScriptableObjects.rendererState.OnLockAdded += AddLock; |
| 105 | 18 | | CommonScriptableObjects.rendererState.OnLockRemoved += RemoveLock; |
| 105 | 19 | | CommonScriptableObjects.rendererState.Set(false); |
| 105 | 20 | | } |
| | 21 | |
|
| | 22 | | void OnDestroy() |
| | 23 | | { |
| 104 | 24 | | CommonScriptableObjects.rendererState.OnLockAdded -= AddLock; |
| 104 | 25 | | CommonScriptableObjects.rendererState.OnLockRemoved -= RemoveLock; |
| 104 | 26 | | } |
| | 27 | |
|
| | 28 | | [ContextMenu("Disable Rendering")] |
| | 29 | | public void DeactivateRendering() |
| | 30 | | { |
| 1 | 31 | | if (!CommonScriptableObjects.rendererState.Get()) |
| 0 | 32 | | return; |
| | 33 | |
|
| 1 | 34 | | DeactivateRendering_Internal(); |
| 1 | 35 | | } |
| | 36 | |
|
| | 37 | | void DeactivateRendering_Internal() |
| | 38 | | { |
| 1 | 39 | | DCL.Configuration.ParcelSettings.VISUAL_LOADING_ENABLED = false; |
| 1 | 40 | | CommonScriptableObjects.rendererState.Set(false); |
| 1 | 41 | | } |
| | 42 | |
|
| | 43 | | [ContextMenu("Enable Rendering")] |
| 2 | 44 | | public void ActivateRendering() { ActivateRendering(forceActivate: false); } |
| | 45 | |
|
| 0 | 46 | | public void ForceActivateRendering() { ActivateRendering(forceActivate: true); } |
| | 47 | |
|
| | 48 | | public void ActivateRendering(bool forceActivate) |
| | 49 | | { |
| 1 | 50 | | if (CommonScriptableObjects.rendererState.Get()) |
| 0 | 51 | | return; |
| | 52 | |
|
| 1 | 53 | | if (!firstActivationTimeHasBeenSet) |
| | 54 | | { |
| 1 | 55 | | firstActivationTime = Time.realtimeSinceStartup; |
| 1 | 56 | | firstActivationTimeHasBeenSet = true; |
| | 57 | | } |
| | 58 | |
|
| 1 | 59 | | if (!forceActivate && !renderingActivatedAckLock.isUnlocked) |
| | 60 | | { |
| 0 | 61 | | renderingActivatedAckLock.OnAllLocksRemoved -= ActivateRendering_Internal; |
| 0 | 62 | | renderingActivatedAckLock.OnAllLocksRemoved += ActivateRendering_Internal; |
| 0 | 63 | | return; |
| | 64 | | } |
| | 65 | |
|
| 1 | 66 | | ActivateRendering_Internal(); |
| 1 | 67 | | } |
| | 68 | |
|
| | 69 | | private void ActivateRendering_Internal() |
| | 70 | | { |
| 1 | 71 | | renderingActivatedAckLock.OnAllLocksRemoved -= ActivateRendering_Internal; |
| | 72 | |
|
| 1 | 73 | | if (!activatedRenderingBefore) |
| | 74 | | { |
| 1 | 75 | | Utils.UnlockCursor(); |
| 1 | 76 | | activatedRenderingBefore = true; |
| | 77 | | } |
| | 78 | |
|
| 1 | 79 | | DCL.Configuration.ParcelSettings.VISUAL_LOADING_ENABLED = true; |
| 1 | 80 | | CommonScriptableObjects.rendererState.Set(true); |
| | 81 | |
|
| 1 | 82 | | WebInterface.ReportControlEvent(new WebInterface.ActivateRenderingACK()); |
| 1 | 83 | | } |
| | 84 | |
|
| | 85 | | private void AddLock(object id) |
| | 86 | | { |
| 642 | 87 | | if (CommonScriptableObjects.rendererState.Get()) |
| 555 | 88 | | return; |
| | 89 | |
|
| 87 | 90 | | if (VERBOSE) |
| 0 | 91 | | Debug.Log("Add lock: " + id); |
| | 92 | |
|
| 87 | 93 | | renderingActivatedAckLock.AddLock(id); |
| 87 | 94 | | } |
| | 95 | |
|
| | 96 | | private void RemoveLock(object id) |
| | 97 | | { |
| 186 | 98 | | if (VERBOSE) |
| 0 | 99 | | Debug.Log("remove lock: " + id); |
| | 100 | |
|
| 186 | 101 | | renderingActivatedAckLock.RemoveLock(id); |
| 186 | 102 | | } |
| | 103 | | } |