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