| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | | using DCL.Components.Video.Plugin; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using DCL.Interface; |
| | 9 | |
|
| | 10 | | namespace DCL.Components |
| | 11 | | { |
| | 12 | | public class DCLVideoTexture : DCLTexture |
| | 13 | | { |
| | 14 | | #if UNITY_EDITOR |
| 1 | 15 | | internal static bool isTest = true; |
| | 16 | | #else |
| | 17 | | internal static bool isTest = false; |
| | 18 | | #endif |
| | 19 | |
|
| | 20 | | private const float OUTOFSCENE_TEX_UPDATE_INTERVAL_IN_SECONDS = 1.5f; |
| | 21 | | private const float VIDEO_PROGRESS_UPDATE_INTERVAL_IN_SECONDS = 1f; |
| | 22 | |
|
| | 23 | | [System.Serializable] |
| | 24 | | new public class Model : BaseModel |
| | 25 | | { |
| | 26 | | public string videoClipId; |
| | 27 | | public bool playing = false; |
| 42 | 28 | | public float volume = 1f; |
| 42 | 29 | | public float playbackRate = 1f; |
| | 30 | | public bool loop = false; |
| 42 | 31 | | public float seek = -1; |
| | 32 | | public BabylonWrapMode wrap = BabylonWrapMode.CLAMP; |
| 42 | 33 | | public FilterMode samplingMode = FilterMode.Bilinear; |
| | 34 | |
|
| 14 | 35 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 36 | | } |
| | 37 | |
|
| | 38 | | internal WebVideoPlayer texturePlayer; |
| | 39 | | private Coroutine texturePlayerUpdateRoutine; |
| | 40 | | private float baseVolume; |
| 14 | 41 | | private float distanceVolumeModifier = 1f; |
| | 42 | | private bool isPlayStateDirty = false; |
| | 43 | | internal bool isVisible = false; |
| | 44 | |
|
| 14 | 45 | | private bool isPlayerInScene = true; |
| 14 | 46 | | private float currUpdateIntervalTime = OUTOFSCENE_TEX_UPDATE_INTERVAL_IN_SECONDS; |
| | 47 | | private float lastVideoProgressReportTime; |
| | 48 | |
|
| 14 | 49 | | internal Dictionary<string, MaterialInfo> attachedMaterials = new Dictionary<string, MaterialInfo>(); |
| | 50 | | private string lastVideoClipID; |
| | 51 | |
|
| 14 | 52 | | public DCLVideoTexture() |
| | 53 | | { |
| 14 | 54 | | model = new Model(); |
| | 55 | |
|
| 14 | 56 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.OnChange += OnVirtualAudioMixerChangedValue; |
| 14 | 57 | | } |
| | 58 | |
|
| | 59 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 60 | | { |
| 28 | 61 | | yield return new WaitUntil(() => CommonScriptableObjects.rendererState.Get()); |
| | 62 | |
|
| | 63 | | //If the scene creates and destroy the component before our renderer has been turned on bad things happen! |
| | 64 | | //TODO: Analyze if we can catch this upstream and stop the IEnumerator |
| 14 | 65 | | if (isDisposed) |
| 0 | 66 | | yield break; |
| | 67 | |
|
| 14 | 68 | | var model = (Model) newModel; |
| | 69 | |
|
| 14 | 70 | | unitySamplingMode = model.samplingMode; |
| | 71 | |
|
| 14 | 72 | | switch (model.wrap) |
| | 73 | | { |
| | 74 | | case BabylonWrapMode.CLAMP: |
| 14 | 75 | | unityWrap = TextureWrapMode.Clamp; |
| 14 | 76 | | break; |
| | 77 | | case BabylonWrapMode.WRAP: |
| 0 | 78 | | unityWrap = TextureWrapMode.Repeat; |
| 0 | 79 | | break; |
| | 80 | | case BabylonWrapMode.MIRROR: |
| 0 | 81 | | unityWrap = TextureWrapMode.Mirror; |
| | 82 | | break; |
| | 83 | | } |
| 14 | 84 | | lastVideoClipID = model.videoClipId; |
| | 85 | |
|
| 14 | 86 | | if (texturePlayer == null) |
| | 87 | | { |
| 14 | 88 | | DCLVideoClip dclVideoClip = scene.GetSharedComponent(lastVideoClipID) as DCLVideoClip; |
| | 89 | |
|
| 14 | 90 | | if (dclVideoClip == null) |
| | 91 | | { |
| 0 | 92 | | Debug.LogError("Wrong video clip type when playing VideoTexture!!"); |
| 0 | 93 | | yield break; |
| | 94 | | } |
| | 95 | |
|
| 14 | 96 | | string videoId = (!string.IsNullOrEmpty(scene.sceneData.id)) ? scene.sceneData.id + id : scene.GetHashCo |
| 14 | 97 | | texturePlayer = new WebVideoPlayer(videoId, dclVideoClip.GetUrl(), dclVideoClip.isStream, new WebVideoPl |
| 14 | 98 | | texturePlayerUpdateRoutine = CoroutineStarter.Start(OnUpdate()); |
| 14 | 99 | | CommonScriptableObjects.playerCoords.OnChange += OnPlayerCoordsChanged; |
| 14 | 100 | | CommonScriptableObjects.sceneID.OnChange += OnSceneIDChanged; |
| 14 | 101 | | scene.OnEntityRemoved += OnEntityRemoved; |
| 14 | 102 | | Settings.i.OnGeneralSettingsChanged += OnSettingsChanged; |
| | 103 | |
|
| 14 | 104 | | OnSceneIDChanged(CommonScriptableObjects.sceneID.Get(), null); |
| | 105 | | } |
| | 106 | |
|
| | 107 | | // NOTE: create texture for testing cause real texture will only be created on web platform |
| 14 | 108 | | if (isTest) |
| | 109 | | { |
| 14 | 110 | | if (texture == null) |
| 14 | 111 | | texture = new Texture2D(1, 1); |
| | 112 | | } |
| | 113 | |
|
| 14 | 114 | | if (texture == null) |
| | 115 | | { |
| 0 | 116 | | while (texturePlayer.texture == null && !texturePlayer.isError) |
| | 117 | | { |
| 0 | 118 | | yield return null; |
| | 119 | | } |
| | 120 | |
|
| 0 | 121 | | if (texturePlayer.isError) |
| | 122 | | { |
| 0 | 123 | | if (texturePlayerUpdateRoutine != null) |
| | 124 | | { |
| 0 | 125 | | CoroutineStarter.Stop(texturePlayerUpdateRoutine); |
| 0 | 126 | | texturePlayerUpdateRoutine = null; |
| | 127 | | } |
| | 128 | |
|
| 0 | 129 | | yield break; |
| | 130 | | } |
| | 131 | |
|
| 0 | 132 | | texture = texturePlayer.texture; |
| 0 | 133 | | isPlayStateDirty = true; |
| | 134 | | } |
| | 135 | |
|
| 14 | 136 | | if (texturePlayer != null) |
| | 137 | | { |
| 14 | 138 | | if (model.seek >= 0) |
| | 139 | | { |
| 1 | 140 | | texturePlayer.SetTime(model.seek); |
| 1 | 141 | | model.seek = -1; |
| | 142 | |
|
| | 143 | | // Applying seek is not immediate |
| 1 | 144 | | yield return null; |
| | 145 | | } |
| | 146 | |
|
| 14 | 147 | | if (model.playing) |
| | 148 | | { |
| 2 | 149 | | texturePlayer.Play(); |
| 2 | 150 | | } |
| | 151 | | else |
| | 152 | | { |
| 12 | 153 | | texturePlayer.Pause(); |
| | 154 | | } |
| | 155 | |
|
| 14 | 156 | | ReportVideoProgress(); |
| | 157 | |
|
| 14 | 158 | | if (baseVolume != model.volume) |
| | 159 | | { |
| 14 | 160 | | baseVolume = model.volume; |
| 14 | 161 | | UpdateVolume(); |
| | 162 | | } |
| | 163 | |
|
| 14 | 164 | | texturePlayer.SetPlaybackRate(model.playbackRate); |
| 14 | 165 | | texturePlayer.SetLoop(model.loop); |
| | 166 | | } |
| 14 | 167 | | } |
| | 168 | |
|
| 0 | 169 | | public float GetVolume() { return ((Model) model).volume; } |
| | 170 | |
|
| 0 | 171 | | private bool HasTexturePropertiesChanged() { return texture.wrapMode != unityWrap || texture.filterMode != unity |
| | 172 | |
|
| | 173 | | private void ApplyTextureProperties() |
| | 174 | | { |
| 0 | 175 | | texture.wrapMode = unityWrap; |
| 0 | 176 | | texture.filterMode = unitySamplingMode; |
| 0 | 177 | | texture.Compress(false); |
| 0 | 178 | | texture.Apply(unitySamplingMode != FilterMode.Point, true); |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | private IEnumerator OnUpdate() |
| | 182 | | { |
| 50 | 183 | | while (true) |
| | 184 | | { |
| 64 | 185 | | UpdateDirtyState(); |
| 64 | 186 | | UpdateVideoTexture(); |
| 64 | 187 | | UpdateProgressReport(); |
| 64 | 188 | | yield return null; |
| | 189 | | } |
| | 190 | | } |
| | 191 | | private void UpdateDirtyState() |
| | 192 | | { |
| 64 | 193 | | if (isPlayStateDirty) |
| | 194 | | { |
| 20 | 195 | | CalculateVideoVolumeAndPlayStatus(); |
| 20 | 196 | | isPlayStateDirty = false; |
| | 197 | | } |
| 64 | 198 | | } |
| | 199 | | private void UpdateVideoTexture() |
| | 200 | | { |
| 64 | 201 | | if (!isPlayerInScene && currUpdateIntervalTime < OUTOFSCENE_TEX_UPDATE_INTERVAL_IN_SECONDS) |
| | 202 | | { |
| 0 | 203 | | currUpdateIntervalTime += Time.unscaledDeltaTime; |
| 0 | 204 | | } |
| 64 | 205 | | else if (texturePlayer != null && !isTest) |
| | 206 | | { |
| 0 | 207 | | currUpdateIntervalTime = 0; |
| 0 | 208 | | texturePlayer.UpdateWebVideoTexture(); |
| | 209 | | } |
| 64 | 210 | | } |
| | 211 | | private void UpdateProgressReport() |
| | 212 | | { |
| 64 | 213 | | if (texturePlayer.playing && IsTimeToReportVideoProgress()) |
| | 214 | | { |
| 2 | 215 | | lastVideoProgressReportTime = Time.unscaledTime; |
| 2 | 216 | | ReportVideoProgress(); |
| | 217 | | } |
| 64 | 218 | | } |
| | 219 | | private void ReportVideoProgress() |
| | 220 | | { |
| 16 | 221 | | var videoStatus = (int)texturePlayer.GetState(); |
| 16 | 222 | | var currentOffset = texturePlayer.GetTime(); |
| 16 | 223 | | var length = texturePlayer.GetDuration(); |
| 16 | 224 | | WebInterface.ReportVideoProgressEvent(id, scene.sceneData.id, lastVideoClipID, videoStatus, currentOffset, l |
| 16 | 225 | | } |
| 2 | 226 | | private bool IsTimeToReportVideoProgress() { return Time.unscaledTime - lastVideoProgressReportTime > VIDEO_PROG |
| | 227 | |
|
| | 228 | | private void CalculateVideoVolumeAndPlayStatus() |
| | 229 | | { |
| 20 | 230 | | isVisible = false; |
| 20 | 231 | | float minDistance = float.MaxValue; |
| 20 | 232 | | distanceVolumeModifier = 0; |
| | 233 | |
|
| 20 | 234 | | if (attachedMaterials.Count > 0) |
| | 235 | | { |
| 20 | 236 | | using (var iterator = attachedMaterials.GetEnumerator()) |
| | 237 | | { |
| 31 | 238 | | while (iterator.MoveNext()) |
| | 239 | | { |
| 20 | 240 | | var materialInfo = iterator.Current; |
| 20 | 241 | | if (materialInfo.Value.IsVisible()) |
| | 242 | | { |
| 9 | 243 | | isVisible = true; |
| 9 | 244 | | var entityDist = materialInfo.Value.GetClosestDistanceSqr(DCLCharacterController.i.transform |
| 9 | 245 | | if (entityDist < minDistance) |
| 9 | 246 | | minDistance = entityDist; |
| | 247 | | // NOTE: if current minDistance is enough for full volume then there is no need to keep iter |
| 9 | 248 | | if (minDistance <= DCL.Configuration.ParcelSettings.PARCEL_SIZE * DCL.Configuration.ParcelSe |
| 9 | 249 | | break; |
| | 250 | | } |
| | 251 | | } |
| 11 | 252 | | } |
| | 253 | | } |
| | 254 | |
|
| 20 | 255 | | if (isVisible) |
| | 256 | | { |
| | 257 | | const float maxDistanceBlockForSound = 6; |
| 9 | 258 | | float sqrParcelDistance = DCL.Configuration.ParcelSettings.PARCEL_SIZE * DCL.Configuration.ParcelSetting |
| 9 | 259 | | distanceVolumeModifier = 1 - Mathf.Clamp01(Mathf.FloorToInt(minDistance / sqrParcelDistance) / maxDistan |
| | 260 | | } |
| | 261 | |
|
| 20 | 262 | | if (texturePlayer != null) |
| | 263 | | { |
| 20 | 264 | | texturePlayer.visible = isVisible; |
| | 265 | | } |
| | 266 | |
|
| 20 | 267 | | UpdateVolume(); |
| 20 | 268 | | } |
| | 269 | |
|
| 0 | 270 | | private void OnVirtualAudioMixerChangedValue(float currentValue, float previousValue) { UpdateVolume(); } |
| | 271 | |
|
| | 272 | | private void UpdateVolume() |
| | 273 | | { |
| 34 | 274 | | if (texturePlayer == null) |
| 0 | 275 | | return; |
| | 276 | |
|
| 34 | 277 | | float targetVolume = 0f; |
| | 278 | |
|
| 34 | 279 | | if (CommonScriptableObjects.rendererState.Get() && IsPlayerInSameSceneAsComponent((CommonScriptableObjects.s |
| | 280 | | { |
| 27 | 281 | | targetVolume = baseVolume * distanceVolumeModifier; |
| 27 | 282 | | float virtualMixerVolume = DataStore.i.virtualAudioMixer.sceneSFXVolume.Get(); |
| 27 | 283 | | float sceneSFXSetting = Settings.i.currentAudioSettings.sceneSFXVolume; |
| 27 | 284 | | float masterSetting = Settings.i.currentAudioSettings.masterVolume; |
| 27 | 285 | | targetVolume *= Utils.ToVolumeCurve(virtualMixerVolume * sceneSFXSetting * masterSetting); |
| | 286 | | } |
| | 287 | |
|
| 34 | 288 | | texturePlayer.SetVolume(targetVolume); |
| 34 | 289 | | } |
| | 290 | |
|
| | 291 | | private bool IsPlayerInSameSceneAsComponent(string currentSceneId) |
| | 292 | | { |
| 50 | 293 | | if (scene == null) |
| 0 | 294 | | return false; |
| 50 | 295 | | if (string.IsNullOrEmpty(currentSceneId)) |
| 0 | 296 | | return false; |
| | 297 | |
|
| 50 | 298 | | return (scene.sceneData.id == currentSceneId) || (scene is GlobalScene globalScene && globalScene.isPortable |
| | 299 | | } |
| | 300 | |
|
| 8 | 301 | | private void OnPlayerCoordsChanged(Vector2Int coords, Vector2Int prevCoords) { isPlayStateDirty = true; } |
| | 302 | |
|
| 32 | 303 | | private void OnSceneIDChanged(string current, string previous) { isPlayerInScene = IsPlayerInSameSceneAsComponen |
| | 304 | |
|
| | 305 | | public override void AttachTo(PBRMaterial material) |
| | 306 | | { |
| 0 | 307 | | base.AttachTo(material); |
| 0 | 308 | | AttachToMaterial(material); |
| 0 | 309 | | } |
| | 310 | |
|
| | 311 | | public override void DetachFrom(PBRMaterial material) |
| | 312 | | { |
| 0 | 313 | | base.DetachFrom(material); |
| 0 | 314 | | DetachFromMaterial(material); |
| 0 | 315 | | } |
| | 316 | |
|
| | 317 | | public override void AttachTo(BasicMaterial material) |
| | 318 | | { |
| 10 | 319 | | base.AttachTo(material); |
| 10 | 320 | | AttachToMaterial(material); |
| 10 | 321 | | } |
| | 322 | |
|
| | 323 | | public override void DetachFrom(BasicMaterial material) |
| | 324 | | { |
| 11 | 325 | | base.DetachFrom(material); |
| 11 | 326 | | DetachFromMaterial(material); |
| 11 | 327 | | } |
| | 328 | |
|
| | 329 | | private void AttachToMaterial(BaseDisposable baseDisposable) |
| | 330 | | { |
| 10 | 331 | | if (!attachedMaterials.ContainsKey(baseDisposable.id)) |
| | 332 | | { |
| 10 | 333 | | attachedMaterials.Add(baseDisposable.id, new MaterialComponent(baseDisposable)); |
| 10 | 334 | | baseDisposable.OnAttach += OnEntityAttachedMaterial; |
| 10 | 335 | | baseDisposable.OnDetach += OnEntityDetachedMaterial; |
| 10 | 336 | | isPlayStateDirty = true; |
| | 337 | |
|
| 10 | 338 | | if (baseDisposable.attachedEntities.Count > 0) |
| | 339 | | { |
| 8 | 340 | | using (var iterator = baseDisposable.attachedEntities.GetEnumerator()) |
| | 341 | | { |
| 16 | 342 | | while (iterator.MoveNext()) |
| | 343 | | { |
| 8 | 344 | | var entity = iterator.Current; |
| 8 | 345 | | entity.OnShapeUpdated -= OnEntityShapeUpdated; |
| 8 | 346 | | entity.OnShapeUpdated += OnEntityShapeUpdated; |
| | 347 | | } |
| 8 | 348 | | } |
| | 349 | | } |
| | 350 | | } |
| 10 | 351 | | } |
| | 352 | |
|
| | 353 | | private void DetachFromMaterial(BaseDisposable baseDisposable) |
| | 354 | | { |
| 11 | 355 | | if (attachedMaterials.ContainsKey(baseDisposable.id)) |
| | 356 | | { |
| 10 | 357 | | attachedMaterials.Remove(baseDisposable.id); |
| 10 | 358 | | baseDisposable.OnAttach -= OnEntityAttachedMaterial; |
| 10 | 359 | | baseDisposable.OnDetach -= OnEntityDetachedMaterial; |
| 10 | 360 | | isPlayStateDirty = true; |
| | 361 | | } |
| 11 | 362 | | } |
| | 363 | |
|
| | 364 | | // TODO: we will need an event for visibility change on UI for supporting video |
| | 365 | | public override void AttachTo(UIImage image) |
| | 366 | | { |
| 0 | 367 | | if (!attachedMaterials.ContainsKey(image.id)) |
| | 368 | | { |
| 0 | 369 | | attachedMaterials.Add(image.id, new UIShapeComponent(image)); |
| 0 | 370 | | isPlayStateDirty = true; |
| | 371 | | } |
| 0 | 372 | | } |
| | 373 | |
|
| | 374 | | public override void DetachFrom(UIImage image) |
| | 375 | | { |
| 0 | 376 | | if (attachedMaterials.ContainsKey(image.id)) |
| | 377 | | { |
| 0 | 378 | | attachedMaterials.Remove(image.id); |
| 0 | 379 | | isPlayStateDirty = true; |
| | 380 | | } |
| 0 | 381 | | } |
| | 382 | |
|
| 2 | 383 | | void OnEntityRemoved(IDCLEntity entity) { isPlayStateDirty = true; } |
| | 384 | |
|
| 0 | 385 | | void OnSettingsChanged(SettingsData.GeneralSettings settings) { UpdateVolume(); } |
| | 386 | |
|
| | 387 | | public override void Dispose() |
| | 388 | | { |
| 15 | 389 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.OnChange -= OnVirtualAudioMixerChangedValue; |
| 15 | 390 | | Settings.i.OnGeneralSettingsChanged -= OnSettingsChanged; |
| 15 | 391 | | CommonScriptableObjects.playerCoords.OnChange -= OnPlayerCoordsChanged; |
| 15 | 392 | | CommonScriptableObjects.sceneID.OnChange -= OnSceneIDChanged; |
| 15 | 393 | | if (scene != null) |
| 15 | 394 | | scene.OnEntityRemoved -= OnEntityRemoved; |
| 15 | 395 | | if (texturePlayerUpdateRoutine != null) |
| | 396 | | { |
| 14 | 397 | | CoroutineStarter.Stop(texturePlayerUpdateRoutine); |
| 14 | 398 | | texturePlayerUpdateRoutine = null; |
| | 399 | | } |
| | 400 | |
|
| 15 | 401 | | if (texturePlayer != null) |
| | 402 | | { |
| 14 | 403 | | texturePlayer.Dispose(); |
| 14 | 404 | | texturePlayer = null; |
| | 405 | | } |
| | 406 | |
|
| 15 | 407 | | Utils.SafeDestroy(texture); |
| 15 | 408 | | base.Dispose(); |
| 15 | 409 | | } |
| | 410 | |
|
| 0 | 411 | | private void OnEntityAttachedMaterial(IDCLEntity entity) { entity.OnShapeUpdated += OnEntityShapeUpdated; } |
| | 412 | |
|
| | 413 | | private void OnEntityDetachedMaterial(IDCLEntity entity) |
| | 414 | | { |
| 1 | 415 | | if (texturePlayer != null) |
| 1 | 416 | | texturePlayer.Pause(); |
| | 417 | |
|
| 1 | 418 | | entity.OnShapeUpdated -= OnEntityShapeUpdated; |
| 1 | 419 | | } |
| | 420 | |
|
| 28 | 421 | | private void OnEntityShapeUpdated(IDCLEntity entity) { isPlayStateDirty = true; } |
| | 422 | |
|
| | 423 | | internal interface MaterialInfo |
| | 424 | | { |
| | 425 | | float GetClosestDistanceSqr(Vector3 fromPosition); |
| | 426 | | bool IsVisible(); |
| | 427 | | } |
| | 428 | |
|
| | 429 | | struct MaterialComponent : MaterialInfo |
| | 430 | | { |
| | 431 | | BaseDisposable component; |
| | 432 | |
|
| | 433 | | float MaterialInfo.GetClosestDistanceSqr(Vector3 fromPosition) |
| | 434 | | { |
| 9 | 435 | | float dist = int.MaxValue; |
| 9 | 436 | | if (component.attachedEntities.Count > 0) |
| | 437 | | { |
| 9 | 438 | | using (var iterator = component.attachedEntities.GetEnumerator()) |
| | 439 | | { |
| 18 | 440 | | while (iterator.MoveNext()) |
| | 441 | | { |
| 9 | 442 | | var entity = iterator.Current; |
| 9 | 443 | | if (IsEntityVisible(entity)) |
| | 444 | | { |
| 9 | 445 | | var entityDist = (entity.meshRootGameObject.transform.position - fromPosition).sqrMagnit |
| 9 | 446 | | if (entityDist < dist) |
| 9 | 447 | | dist = entityDist; |
| | 448 | | } |
| | 449 | | } |
| 9 | 450 | | } |
| | 451 | | } |
| | 452 | |
|
| 9 | 453 | | return dist; |
| | 454 | | } |
| | 455 | |
|
| | 456 | | bool MaterialInfo.IsVisible() |
| | 457 | | { |
| 20 | 458 | | if (component.attachedEntities.Count > 0) |
| | 459 | | { |
| 18 | 460 | | using (var iterator = component.attachedEntities.GetEnumerator()) |
| | 461 | | { |
| 27 | 462 | | while (iterator.MoveNext()) |
| | 463 | | { |
| 18 | 464 | | if (IsEntityVisible(iterator.Current)) |
| | 465 | | { |
| 9 | 466 | | return true; |
| | 467 | | } |
| | 468 | | } |
| 9 | 469 | | } |
| | 470 | | } |
| | 471 | |
|
| 11 | 472 | | return false; |
| 9 | 473 | | } |
| | 474 | |
|
| | 475 | | bool IsEntityVisible(IDCLEntity entity) |
| | 476 | | { |
| 27 | 477 | | if (entity.meshesInfo == null) |
| 0 | 478 | | return false; |
| 27 | 479 | | if (entity.meshesInfo.currentShape == null) |
| 7 | 480 | | return false; |
| 20 | 481 | | return entity.meshesInfo.currentShape.IsVisible(); |
| | 482 | | } |
| | 483 | |
|
| 0 | 484 | | public MaterialComponent(BaseDisposable component) { this.component = component; } |
| | 485 | | } |
| | 486 | |
|
| | 487 | | struct UIShapeComponent : MaterialInfo |
| | 488 | | { |
| | 489 | | UIShape shape; |
| | 490 | |
|
| 0 | 491 | | float MaterialInfo.GetClosestDistanceSqr(Vector3 fromPosition) { return 0; } |
| | 492 | |
|
| | 493 | | bool MaterialInfo.IsVisible() |
| | 494 | | { |
| 0 | 495 | | if (!((UIShape.Model) shape.GetModel()).visible) |
| 0 | 496 | | return false; |
| 0 | 497 | | return IsParentVisible(shape); |
| | 498 | | } |
| | 499 | |
|
| | 500 | | bool IsParentVisible(UIShape shape) |
| | 501 | | { |
| 0 | 502 | | UIShape parent = shape.parentUIComponent; |
| 0 | 503 | | if (parent == null) |
| 0 | 504 | | return true; |
| 0 | 505 | | if (parent.referencesContainer.canvasGroup.alpha == 0) |
| | 506 | | { |
| 0 | 507 | | return false; |
| | 508 | | } |
| | 509 | |
|
| 0 | 510 | | return IsParentVisible(parent); |
| | 511 | | } |
| | 512 | |
|
| 0 | 513 | | public UIShapeComponent(UIShape image) { shape = image; } |
| | 514 | | } |
| | 515 | | } |
| | 516 | | } |