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