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