| | 1 | | using DCL.Models; |
| | 2 | | using UnityEngine; |
| | 3 | | using System.Collections.Generic; |
| | 4 | |
|
| | 5 | | namespace DCL.Controllers |
| | 6 | | { |
| | 7 | | public class SceneBoundsFeedbackStyle_Simple : ISceneBoundsFeedbackStyle |
| | 8 | | { |
| 665 | 9 | | private readonly List<Renderer> disabledRenderers = new List<Renderer>(); |
| | 10 | |
|
| | 11 | | public void ApplyFeedback(MeshesInfo meshesInfo, bool isInsideBoundaries) |
| | 12 | | { |
| 520 | 13 | | if (meshesInfo?.renderers == null || meshesInfo.renderers.Length == 0) |
| 352 | 14 | | return; |
| | 15 | |
|
| 168 | 16 | | if (meshesInfo?.currentShape != null && !meshesInfo.currentShape.IsVisible()) |
| 3 | 17 | | return; |
| | 18 | |
|
| 742 | 19 | | for (int i = 0; i < meshesInfo.renderers.Length; i++) |
| | 20 | | { |
| 206 | 21 | | if (meshesInfo.renderers[i] == null) |
| | 22 | | continue; |
| | 23 | |
|
| 206 | 24 | | if (isInsideBoundaries == meshesInfo.renderers[i].enabled) |
| | 25 | | continue; |
| | 26 | |
|
| | 27 | | //We add a check to stop the material transition controller in case its there and |
| | 28 | | //needs to be turned off |
| 59 | 29 | | MaterialTransitionController mtcController = meshesInfo.renderers[i].GetComponent<MaterialTransitionCont |
| 59 | 30 | | if (!isInsideBoundaries && mtcController) |
| | 31 | | { |
| 22 | 32 | | mtcController.ForceStop(); |
| | 33 | | } |
| | 34 | |
|
| 59 | 35 | | meshesInfo.renderers[i].enabled = isInsideBoundaries; |
| | 36 | |
|
| 59 | 37 | | if (isInsideBoundaries && disabledRenderers.Contains(meshesInfo.renderers[i])) |
| 26 | 38 | | disabledRenderers.Remove( meshesInfo.renderers[i]); |
| 33 | 39 | | else if (!isInsideBoundaries && !disabledRenderers.Contains(meshesInfo.renderers[i])) |
| 26 | 40 | | disabledRenderers.Add( meshesInfo.renderers[i]); |
| | 41 | | } |
| 165 | 42 | | } |
| | 43 | |
|
| | 44 | | public void CleanFeedback() |
| | 45 | | { |
| 68 | 46 | | foreach (var renderer in disabledRenderers) |
| | 47 | | { |
| 0 | 48 | | if (renderer != null) |
| 0 | 49 | | renderer.enabled = true; |
| | 50 | | } |
| | 51 | |
|
| 34 | 52 | | disabledRenderers.Clear(); |
| 34 | 53 | | } |
| | 54 | |
|
| | 55 | | public List<Material> GetOriginalMaterials(MeshesInfo meshesInfo) |
| | 56 | | { |
| 0 | 57 | | List<Material> result = new List<Material>(); |
| | 58 | |
|
| 0 | 59 | | for (int i = 0; i < meshesInfo.renderers.Length; i++) |
| | 60 | | { |
| 0 | 61 | | result.AddRange(meshesInfo.renderers[i].sharedMaterials); |
| | 62 | | } |
| | 63 | |
|
| 0 | 64 | | return result; |
| | 65 | | } |
| | 66 | | } |
| | 67 | | } |