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