fr.jeanf.universal.player 0.8.24 → 0.8.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ using UnityEngine.Serialization;
5
5
  using UnityEngine.Rendering;
6
6
  using LitMotion;
7
7
  using System;
8
+ using System.Collections;
8
9
  using System.Linq;
9
10
  using Volume = UnityEngine.Rendering.Volume;
10
11
 
@@ -12,6 +13,12 @@ namespace jeanf.universalplayer
12
13
  {
13
14
  public class FadeMask : MonoBehaviour, IDebugBehaviour
14
15
  {
16
+ public enum FadeType
17
+ {
18
+ Loading, // Black fade for scene loading
19
+ HeadInWall // Saturation fade for collision detection
20
+ }
21
+
15
22
  public bool isDebug
16
23
  {
17
24
  get => _isDebug;
@@ -44,13 +51,13 @@ namespace jeanf.universalplayer
44
51
  [SerializeField] private Volume postProcessVolume;
45
52
  private static Volume staticPostProcessVolume;
46
53
 
47
- // Use objects to handle both URP and HDRP ColorAdjustments via reflection
48
54
  private static object hdrpColorAdjustments;
49
55
  private static object urpColorAdjustments;
50
56
 
51
57
  private static MotionHandle _fadeHandle;
52
58
  private static bool _isCurrentlyFading = false;
53
59
  private static bool _targetState = false;
60
+ private static FadeType _currentFadeType = FadeType.Loading;
54
61
 
55
62
  [Header("Listening On")] [SerializeField]
56
63
  private BoolFloatEventChannelSO fadeOutChannelSO;
@@ -59,7 +66,6 @@ namespace jeanf.universalplayer
59
66
 
60
67
  public static TogglePpeDelegate TogglePPE;
61
68
 
62
- // Pipeline detection
63
69
  private enum RenderPipeline
64
70
  {
65
71
  BuiltIn,
@@ -74,7 +80,7 @@ namespace jeanf.universalplayer
74
80
  {
75
81
  DetectRenderPipeline();
76
82
  SetupVolumeProfile();
77
- SetVolumeTo_InitialSetup();
83
+ SetVolumeTo_FadeToBlack();
78
84
  FadeValue(false, .5f);
79
85
  }
80
86
 
@@ -112,7 +118,6 @@ namespace jeanf.universalplayer
112
118
  return;
113
119
  }
114
120
 
115
- // Use the assigned volume profile if available
116
121
  if (volumeProfile != null)
117
122
  {
118
123
  postProcessVolume.profile = volumeProfile;
@@ -123,23 +128,18 @@ namespace jeanf.universalplayer
123
128
  return;
124
129
  }
125
130
 
126
- // Handle built-in pipeline
127
131
  if (_currentPipeline == RenderPipeline.BuiltIn)
128
132
  {
129
133
  if (_isDebugSTATIC) Debug.LogWarning("FadeMask: Built-in pipeline detected. Volume system may not be available.");
130
134
  return;
131
135
  }
132
136
 
133
- // Set blend distance (same for all pipelines that support volumes)
134
137
  postProcessVolume.blendDistance = 10.0f;
135
138
 
136
139
  staticPostProcessVolume = postProcessVolume;
137
-
138
- // Try to get ColorAdjustments component based on current pipeline
139
- if (!TryGetColorAdjustments())
140
- {
141
- if (_isDebugSTATIC) Debug.LogError("FadeMask: ColorAdjustments component not found in volume profile!");
142
- }
140
+
141
+ if (TryGetColorAdjustments()) return;
142
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: ColorAdjustments component not found in volume profile!");
143
143
  }
144
144
 
145
145
  private bool TryGetColorAdjustments()
@@ -153,7 +153,11 @@ namespace jeanf.universalplayer
153
153
 
154
154
  case RenderPipeline.URP:
155
155
  return TryGetURPColorAdjustments();
156
-
156
+
157
+ case RenderPipeline.BuiltIn:
158
+ break;
159
+ case RenderPipeline.Unknown:
160
+ break;
157
161
  default:
158
162
  if (_isDebugSTATIC) Debug.LogError($"FadeMask: Unsupported pipeline: {_currentPipeline}");
159
163
  break;
@@ -172,10 +176,8 @@ namespace jeanf.universalplayer
172
176
  {
173
177
  try
174
178
  {
175
- // Find HDRP ColorAdjustments type
176
179
  System.Type hdrpColorAdjustmentsType = System.Type.GetType("UnityEngine.Rendering.HighDefinition.ColorAdjustments, Unity.RenderPipelines.HighDefinition.Runtime");
177
180
 
178
- // Fallback: search through loaded assemblies
179
181
  if (hdrpColorAdjustmentsType == null)
180
182
  {
181
183
  foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
@@ -194,7 +196,6 @@ namespace jeanf.universalplayer
194
196
  return false;
195
197
  }
196
198
 
197
- // Use reflection to call TryGet<T> method
198
199
  var profileType = staticPostProcessVolume.profile.GetType();
199
200
  var tryGetMethods = profileType.GetMethods().Where(m => m.Name == "TryGet" && m.IsGenericMethodDefinition).ToArray();
200
201
 
@@ -231,10 +232,8 @@ namespace jeanf.universalplayer
231
232
  {
232
233
  try
233
234
  {
234
- // Find URP ColorAdjustments type
235
235
  System.Type urpColorAdjustmentsType = System.Type.GetType("UnityEngine.Rendering.Universal.ColorAdjustments, Unity.RenderPipelines.Universal.Runtime");
236
236
 
237
- // Fallback: search through loaded assemblies
238
237
  if (urpColorAdjustmentsType == null)
239
238
  {
240
239
  foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
@@ -253,7 +252,6 @@ namespace jeanf.universalplayer
253
252
  return false;
254
253
  }
255
254
 
256
- // Use reflection to call TryGet<T> method
257
255
  var profileType = staticPostProcessVolume.profile.GetType();
258
256
  var tryGetMethods = profileType.GetMethods().Where(m => m.Name == "TryGet" && m.IsGenericMethodDefinition).ToArray();
259
257
 
@@ -310,9 +308,9 @@ namespace jeanf.universalplayer
310
308
  TogglePPE -= ChangePostProcessing;
311
309
  }
312
310
 
313
- public static void SetVolumeTo_InitialSetup()
311
+ public static void SetVolumeTo_FadeToBlack()
314
312
  {
315
- if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting initial setup for {_currentPipeline}");
313
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting initial setup (black) for {_currentPipeline}");
316
314
 
317
315
  switch (_currentPipeline)
318
316
  {
@@ -333,16 +331,20 @@ namespace jeanf.universalplayer
333
331
  }
334
332
  else if (_isDebugSTATIC) Debug.LogWarning("FadeMask: URP ColorAdjustments is null.");
335
333
  break;
336
-
334
+
335
+ case RenderPipeline.BuiltIn:
336
+ break;
337
+ case RenderPipeline.Unknown:
338
+ break;
337
339
  default:
338
340
  if (_isDebugSTATIC) Debug.LogWarning($"FadeMask: Cannot set initial setup for pipeline: {_currentPipeline}");
339
341
  break;
340
342
  }
341
343
  }
342
344
 
343
- public static void SetVolumeTo_HeadInWallSetup()
345
+ public static void SetVolumeTo_FadeSaturation()
344
346
  {
345
- if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting head in wall setup for {_currentPipeline}");
347
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting head in wall setup (gray) for {_currentPipeline}");
346
348
 
347
349
  switch (_currentPipeline)
348
350
  {
@@ -363,7 +365,11 @@ namespace jeanf.universalplayer
363
365
  }
364
366
  else if (_isDebugSTATIC) Debug.LogWarning("FadeMask: URP ColorAdjustments is null.");
365
367
  break;
366
-
368
+
369
+ case RenderPipeline.BuiltIn:
370
+ break;
371
+ case RenderPipeline.Unknown:
372
+ break;
367
373
  default:
368
374
  if (_isDebugSTATIC) Debug.LogWarning($"FadeMask: Cannot set head in wall setup for pipeline: {_currentPipeline}");
369
375
  break;
@@ -379,12 +385,9 @@ namespace jeanf.universalplayer
379
385
  var colorAdjustmentsType = colorAdjustments.GetType();
380
386
  var parametersProperty = colorAdjustmentsType.GetProperty("parameters");
381
387
  if (parametersProperty == null) return;
382
-
383
388
  var parameters = parametersProperty.GetValue(colorAdjustments);
384
- if (parameters == null) return;
385
-
386
- var parametersEnumerable = parameters as System.Collections.IEnumerable;
387
- if (parametersEnumerable == null) return;
389
+
390
+ if (parameters is not IEnumerable parametersEnumerable) return;
388
391
 
389
392
  var parametersList = new System.Collections.Generic.List<object>();
390
393
  foreach (var param in parametersEnumerable)
@@ -394,57 +397,47 @@ namespace jeanf.universalplayer
394
397
 
395
398
  object targetParameter = null;
396
399
 
397
- if (propertyName == "colorFilter")
400
+ switch (propertyName)
398
401
  {
399
- // Find ColorParameter
400
- foreach (var param in parametersList)
402
+ case "colorFilter":
401
403
  {
402
- if (param.GetType().Name == "ColorParameter")
404
+ foreach (var param in parametersList)
403
405
  {
406
+ if (param.GetType().Name != "ColorParameter") continue;
404
407
  targetParameter = param;
405
408
  break;
406
409
  }
410
+
411
+ break;
407
412
  }
408
- }
409
- else if (propertyName == "saturation")
410
- {
411
- // Find saturation parameter - typically index 4 or by range check
412
- if (parametersList.Count > 4 && parametersList[4].GetType().Name == "ClampedFloatParameter")
413
- {
413
+ case "saturation" when parametersList.Count > 4 && parametersList[4].GetType().Name == "ClampedFloatParameter":
414
414
  targetParameter = parametersList[4];
415
- }
416
- else
415
+ break;
416
+ case "saturation":
417
417
  {
418
- // Fallback: find ClampedFloatParameter with range -100 to 100
419
418
  foreach (var param in parametersList)
420
419
  {
421
- if (param.GetType().Name == "ClampedFloatParameter")
422
- {
423
- var paramType = param.GetType();
424
- var minProp = paramType.GetProperty("min");
425
- var maxProp = paramType.GetProperty("max");
426
- if (minProp?.GetValue(param)?.ToString() == "-100" &&
427
- maxProp?.GetValue(param)?.ToString() == "100")
428
- {
429
- targetParameter = param;
430
- break;
431
- }
432
- }
420
+ if (param.GetType().Name != "ClampedFloatParameter") continue;
421
+ var paramType = param.GetType();
422
+ var minProp = paramType.GetProperty("min");
423
+ var maxProp = paramType.GetProperty("max");
424
+ if (minProp?.GetValue(param)?.ToString() != "-100" ||
425
+ maxProp?.GetValue(param)?.ToString() != "100") continue;
426
+ targetParameter = param;
427
+ break;
433
428
  }
429
+
430
+ break;
434
431
  }
435
432
  }
436
-
437
- if (targetParameter != null)
438
- {
439
- var parameterType = targetParameter.GetType();
440
- var valueProperty = parameterType.GetProperty("value");
441
-
442
- if (valueProperty != null)
443
- {
444
- valueProperty.SetValue(targetParameter, value);
445
- if (_isDebugSTATIC) Debug.Log($"FadeMask: Set {propertyName} to {value}");
446
- }
447
- }
433
+
434
+ if (targetParameter == null) return;
435
+ var parameterType = targetParameter.GetType();
436
+ var valueProperty = parameterType.GetProperty("value");
437
+
438
+ if (valueProperty == null) return;
439
+ valueProperty.SetValue(targetParameter, value);
440
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Set {propertyName} to {value}");
448
441
  }
449
442
  catch (Exception e)
450
443
  {
@@ -466,35 +459,52 @@ namespace jeanf.universalplayer
466
459
 
467
460
  private void ChangePostProcessing(bool isInitComplete)
468
461
  {
469
- SetVolumeTo_InitialSetup();
470
-
471
- if (!isInitComplete) return;
472
-
473
- SetVolumeTo_HeadInWallSetup();
462
+ SetVolumeTo_FadeToBlack();
474
463
  }
475
-
476
464
  public static void FadeValue(bool value)
477
465
  {
478
- FadeValue(value, _fadeTime);
479
- if (_isDebugSTATIC) Debug.Log($"FadeMask: Fading to {value} in {_fadeTime}s");
466
+ FadeValue(value, FadeType.Loading);
480
467
  }
481
468
 
482
469
  public static void FadeValue(bool value, float fadeTime)
483
470
  {
484
- // Check if volume is initialized
471
+ FadeValue(value, fadeTime, FadeType.Loading);
472
+ }
473
+
474
+ public static void FadeValue(bool value, FadeType fadeType)
475
+ {
476
+ FadeValue(value, _fadeTime, fadeType);
477
+ }
478
+
479
+ public static void FadeValue(bool value, float fadeTime, FadeType fadeType)
480
+ {
485
481
  if (staticPostProcessVolume == null)
486
482
  {
487
483
  if (_isDebugSTATIC) Debug.LogWarning("FadeMask: staticPostProcessVolume is null. Make sure FadeMask.Awake() has been called.");
488
484
  return;
489
485
  }
490
486
 
491
- // Don't start a new fade if we're already fading to the same target
487
+ if (value)
488
+ {
489
+ _currentFadeType = fadeType;
490
+ switch (fadeType)
491
+ {
492
+ case FadeType.Loading:
493
+ SetVolumeTo_FadeToBlack(); // Black fade
494
+ break;
495
+ case FadeType.HeadInWall:
496
+ SetVolumeTo_FadeSaturation(); // Saturation fade
497
+ break;
498
+ }
499
+
500
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting up {fadeType} fade");
501
+ }
502
+
492
503
  if (_isCurrentlyFading && _targetState == value)
493
504
  return;
494
505
 
495
- if (_isDebugSTATIC) Debug.Log($"FadeMask: Fading to {value} in {fadeTime}s");
506
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Fading to {value} in {fadeTime}s with {fadeType} style");
496
507
 
497
- // Only cancel if the handle is valid and active
498
508
  if (_fadeHandle.IsActive())
499
509
  {
500
510
  _fadeHandle.Cancel();
@@ -42,8 +42,20 @@ namespace jeanf.universalplayer
42
42
  }
43
43
 
44
44
  if (_isHeadInWall == _isHeadInWallLastValue) return;
45
- FadeMask.FadeValue(_isHeadInWall);
46
- if(isDebug) Debug.Log($"isHeadInWall changed to: {_isHeadInWall}");
45
+
46
+ // Determine fade type based on whether we're loading or detecting collision
47
+ if (_isSceneLoading)
48
+ {
49
+ // Black fade for loading
50
+ FadeMask.FadeValue(_isHeadInWall, FadeMask.FadeType.Loading);
51
+ if (isDebug) Debug.Log($"Loading fade changed to: {_isHeadInWall}");
52
+ }
53
+ else
54
+ {
55
+ // Gray fade for head-in-wall collision
56
+ FadeMask.FadeValue(_isHeadInWall, FadeMask.FadeType.HeadInWall);
57
+ if (isDebug) Debug.Log($"HeadInWall collision fade changed to: {_isHeadInWall}");
58
+ }
47
59
  }
48
60
 
49
61
  #if UNITY_EDITOR
@@ -54,10 +66,25 @@ namespace jeanf.universalplayer
54
66
  }
55
67
  #endif
56
68
 
57
- public static void SetIsLoadingState(bool value)
69
+ public static void SetIsLoadingState(bool isLoading)
70
+ {
71
+ _isSceneLoading = isLoading;
72
+ }
73
+
74
+ /// <summary>
75
+ /// Gets the current loading state
76
+ /// </summary>
77
+ public static bool IsCurrentlyLoading()
78
+ {
79
+ return _isSceneLoading;
80
+ }
81
+
82
+ /// <summary>
83
+ /// Gets the current head-in-wall state (useful for debugging)
84
+ /// </summary>
85
+ public bool IsHeadInWall()
58
86
  {
59
- value = !value;
60
- _isSceneLoading = value;
87
+ return _isHeadInWall;
61
88
  }
62
89
  }
63
90
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fr.jeanf.universal.player",
3
3
 
4
- "version": "0.8.24",
4
+ "version": "0.8.25",
5
5
 
6
6
  "displayName": "Universal Player",
7
7
  "description": "This package contains a universal player working in URP & HDRP for Mouse+Keyboard or VR",