| | 1 | | using Builder; |
| | 2 | | using DCL.Configuration; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Rendering.Universal; |
| | 7 | |
|
| | 8 | | public class BIWOutlinerController : BIWController |
| | 9 | | { |
| | 10 | | [Header("Build References")] |
| 198 | 11 | | public int builderRendererIndex = 1; |
| | 12 | |
|
| | 13 | | public Material outlineMaterial; |
| | 14 | | public Material cameraOutlinerMaterial; |
| | 15 | |
|
| | 16 | | [SerializeField] internal BuilderInWorldEntityHandler builderInWorldEntityHandler; |
| | 17 | | public BIWInputHandler biwInputHandler; |
| | 18 | | public LayerMask layerToStopOutline; |
| | 19 | |
|
| 198 | 20 | | private List<DCLBuilderInWorldEntity> entitiesOutlined = new List<DCLBuilderInWorldEntity>(); |
| | 21 | | private int outlinerOptimizationCounter = 0; |
| 198 | 22 | | private bool isOutlineCheckActive = true; |
| | 23 | |
|
| | 24 | | public override void EnterEditMode(ParcelScene scene) |
| | 25 | | { |
| 0 | 26 | | base.EnterEditMode(scene); |
| 0 | 27 | | ActivateBuilderInWorldCamera(); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public override void ExitEditMode() |
| | 31 | | { |
| 0 | 32 | | base.ExitEditMode(); |
| 0 | 33 | | DeactivateBuilderInWorldCamera(); |
| 0 | 34 | | } |
| | 35 | |
|
| 0 | 36 | | public void SetOutlineCheckActive(bool isActive) { isOutlineCheckActive = isActive; } |
| | 37 | |
|
| | 38 | | public void CheckOutline() |
| | 39 | | { |
| 0 | 40 | | if (outlinerOptimizationCounter >= 10 && isOutlineCheckActive) |
| | 41 | | { |
| 0 | 42 | | if (!BuilderInWorldUtils.IsPointerOverUIElement() && !BuilderInWorldUtils.IsPointerOverMaskElement(layerToSt |
| | 43 | | { |
| 0 | 44 | | DCLBuilderInWorldEntity entity = builderInWorldEntityHandler.GetEntityOnPointer(); |
| 0 | 45 | | RemoveEntitiesOutsidePointerOrUnselected(); |
| | 46 | |
|
| 0 | 47 | | if (entity != null && !entity.IsSelected) |
| 0 | 48 | | OutlineEntity(entity); |
| 0 | 49 | | } |
| | 50 | | else |
| | 51 | | { |
| 0 | 52 | | CancelUnselectedOutlines(); |
| | 53 | | } |
| | 54 | |
|
| 0 | 55 | | outlinerOptimizationCounter = 0; |
| 0 | 56 | | } |
| | 57 | | else |
| 0 | 58 | | outlinerOptimizationCounter++; |
| 0 | 59 | | } |
| | 60 | |
|
| 3 | 61 | | public bool IsEntityOutlined(DCLBuilderInWorldEntity entity) { return entitiesOutlined.Contains(entity); } |
| | 62 | |
|
| | 63 | | public void OutlineEntities(List<DCLBuilderInWorldEntity> entitiesToEdit) |
| | 64 | | { |
| 0 | 65 | | foreach (DCLBuilderInWorldEntity entityToEdit in entitiesToEdit) |
| | 66 | | { |
| 0 | 67 | | OutlineEntity(entityToEdit); |
| | 68 | | } |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | public void OutlineEntity(DCLBuilderInWorldEntity entity) |
| | 72 | | { |
| 3 | 73 | | if (entity.rootEntity.meshRootGameObject == null) |
| 0 | 74 | | return; |
| | 75 | |
|
| 3 | 76 | | if (!entity.rootEntity.meshRootGameObject && entity.rootEntity.renderers.Length <= 0) |
| 0 | 77 | | return; |
| | 78 | |
|
| 3 | 79 | | if (entitiesOutlined.Contains(entity)) |
| 0 | 80 | | return; |
| | 81 | |
|
| 3 | 82 | | if (entity.IsLocked) |
| 1 | 83 | | return; |
| | 84 | |
|
| 2 | 85 | | entitiesOutlined.Add(entity); |
| | 86 | |
|
| 8 | 87 | | for (int i = 0; i < entity.rootEntity.meshesInfo.renderers.Length; i++) |
| | 88 | | { |
| 2 | 89 | | if ( entity.rootEntity.meshesInfo.renderers[i] == null) |
| | 90 | | continue; |
| 2 | 91 | | entity.rootEntity.meshesInfo.renderers[i].gameObject.layer = BuilderInWorldSettings.SELECTION_LAYER; |
| | 92 | | } |
| 2 | 93 | | } |
| | 94 | |
|
| | 95 | | public void CancelUnselectedOutlines() |
| | 96 | | { |
| 0 | 97 | | for (int i = 0; i < entitiesOutlined.Count; i++) |
| | 98 | | { |
| 0 | 99 | | if (!entitiesOutlined[i].IsSelected) |
| | 100 | | { |
| 0 | 101 | | CancelEntityOutline(entitiesOutlined[i]); |
| | 102 | | } |
| | 103 | | } |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | public void RemoveEntitiesOutsidePointerOrUnselected() |
| | 107 | | { |
| 0 | 108 | | var entity = builderInWorldEntityHandler.GetEntityOnPointer(); |
| 0 | 109 | | for (int i = 0; i < entitiesOutlined.Count; i++) |
| | 110 | | { |
| 0 | 111 | | if (!entitiesOutlined[i].IsSelected || entity != entitiesOutlined[i]) |
| 0 | 112 | | CancelEntityOutline(entitiesOutlined[i]); |
| | 113 | | } |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | public void CancelAllOutlines() |
| | 117 | | { |
| 22 | 118 | | for (int i = 0; i < entitiesOutlined.Count; i++) |
| | 119 | | { |
| 0 | 120 | | CancelEntityOutline(entitiesOutlined[i]); |
| | 121 | | } |
| 11 | 122 | | } |
| | 123 | |
|
| | 124 | | public void CancelEntityOutline(DCLBuilderInWorldEntity entityToQuitOutline) |
| | 125 | | { |
| 12 | 126 | | if (!entitiesOutlined.Contains(entityToQuitOutline)) |
| 10 | 127 | | return; |
| | 128 | |
|
| 2 | 129 | | if (entityToQuitOutline.rootEntity.meshRootGameObject && entityToQuitOutline.rootEntity.meshesInfo.renderers.Len |
| | 130 | | { |
| 8 | 131 | | for (int x = 0; x < entityToQuitOutline.rootEntity.meshesInfo.renderers.Length; x++) |
| | 132 | | { |
| 2 | 133 | | if ( entityToQuitOutline.rootEntity.meshesInfo.renderers[x] == null) |
| | 134 | | continue; |
| 2 | 135 | | entityToQuitOutline.rootEntity.meshesInfo.renderers[x].gameObject.layer = BuilderInWorldSettings.DEFAULT |
| | 136 | | } |
| | 137 | | } |
| | 138 | |
|
| 2 | 139 | | entitiesOutlined.Remove(entityToQuitOutline); |
| 2 | 140 | | } |
| | 141 | |
|
| | 142 | | public void ActivateBuilderInWorldCamera() |
| | 143 | | { |
| 0 | 144 | | Camera camera = Camera.main; |
| 0 | 145 | | DCLBuilderOutline outliner = camera.GetComponent<DCLBuilderOutline>(); |
| | 146 | |
|
| 0 | 147 | | if (outliner == null) |
| | 148 | | { |
| 0 | 149 | | outliner = camera.gameObject.AddComponent(typeof(DCLBuilderOutline)) as DCLBuilderOutline; |
| 0 | 150 | | outliner.SetOutlineMaterial(cameraOutlinerMaterial); |
| 0 | 151 | | } |
| | 152 | | else |
| | 153 | | { |
| 0 | 154 | | outliner.enabled = true; |
| | 155 | | } |
| | 156 | |
|
| 0 | 157 | | outliner.Activate(); |
| | 158 | |
|
| 0 | 159 | | UniversalAdditionalCameraData additionalCameraData = camera.transform.GetComponent<UniversalAdditionalCameraData |
| 0 | 160 | | additionalCameraData.SetRenderer(builderRendererIndex); |
| 0 | 161 | | } |
| | 162 | |
|
| | 163 | | public void DeactivateBuilderInWorldCamera() |
| | 164 | | { |
| 0 | 165 | | Camera camera = Camera.main; |
| | 166 | |
|
| 0 | 167 | | if (camera == null) |
| 0 | 168 | | return; |
| | 169 | |
|
| 0 | 170 | | DCLBuilderOutline outliner = camera.GetComponent<DCLBuilderOutline>(); |
| 0 | 171 | | if (outliner != null) |
| | 172 | | { |
| 0 | 173 | | outliner.enabled = false; |
| 0 | 174 | | outliner.Deactivate(); |
| | 175 | | } |
| | 176 | |
|
| 0 | 177 | | UniversalAdditionalCameraData additionalCameraData = camera.transform.GetComponent<UniversalAdditionalCameraData |
| 0 | 178 | | additionalCameraData.SetRenderer(0); |
| 0 | 179 | | } |
| | 180 | | } |