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