fr.jeanf.universal.player 0.8.20 → 0.8.22

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.
@@ -1259,7 +1259,7 @@ Canvas:
1259
1259
  serializedVersion: 3
1260
1260
  m_RenderMode: 1
1261
1261
  m_Camera: {fileID: 0}
1262
- m_PlaneDistance: 0.1
1262
+ m_PlaneDistance: 0.15
1263
1263
  m_PixelPerfect: 0
1264
1264
  m_ReceivesEvents: 1
1265
1265
  m_OverrideSorting: 0
@@ -4,7 +4,8 @@ using jeanf.EventSystem;
4
4
  using UnityEngine.Serialization;
5
5
  using UnityEngine.Rendering;
6
6
  using LitMotion;
7
- using UnityEngine.Rendering.HighDefinition;
7
+ using System;
8
+ using System.Linq;
8
9
  using Volume = UnityEngine.Rendering.Volume;
9
10
 
10
11
  namespace jeanf.universalplayer
@@ -38,11 +39,14 @@ namespace jeanf.universalplayer
38
39
  private static Material _shaderMaterial;
39
40
  private static bool _isFaded = false;
40
41
 
41
- [SerializeField] private VolumeProfile HDRPVolumeProfile;
42
- [SerializeField] private VolumeProfile URPVolumeProfile;
42
+ [Header("Volume Profiles - Only assign the one for your current pipeline")]
43
+ [SerializeField] private VolumeProfile volumeProfile;
43
44
  [SerializeField] private Volume postProcessVolume;
44
45
  private static Volume staticPostProcessVolume;
45
- private static ColorAdjustments colorAdjustments;
46
+
47
+ // Use objects to handle both URP and HDRP ColorAdjustments via reflection
48
+ private static object hdrpColorAdjustments;
49
+ private static object urpColorAdjustments;
46
50
 
47
51
  private static MotionHandle _fadeHandle;
48
52
  private static bool _isCurrentlyFading = false;
@@ -55,27 +59,231 @@ namespace jeanf.universalplayer
55
59
 
56
60
  public static TogglePpeDelegate TogglePPE;
57
61
 
62
+ // Pipeline detection
63
+ private enum RenderPipeline
64
+ {
65
+ BuiltIn,
66
+ URP,
67
+ HDRP,
68
+ Unknown
69
+ }
70
+
71
+ private static RenderPipeline _currentPipeline = RenderPipeline.Unknown;
58
72
 
59
73
  private void Awake()
60
74
  {
61
- if (GraphicsSettings.defaultRenderPipeline == null) return;
75
+ DetectRenderPipeline();
76
+ SetupVolumeProfile();
77
+ SetVolumeTo_InitialSetup();
78
+ FadeValue(false, .5f);
79
+ }
80
+
81
+ private void DetectRenderPipeline()
82
+ {
83
+ if (GraphicsSettings.defaultRenderPipeline == null)
84
+ {
85
+ _currentPipeline = RenderPipeline.BuiltIn;
86
+ return;
87
+ }
88
+
62
89
  var renderingAssetType = GraphicsSettings.defaultRenderPipeline.GetType().ToString();
90
+
63
91
  if (renderingAssetType.Contains("HDRenderPipelineAsset"))
64
92
  {
65
- postProcessVolume.profile = HDRPVolumeProfile;
66
- postProcessVolume.blendDistance = 10.0f;
93
+ _currentPipeline = RenderPipeline.HDRP;
67
94
  }
68
95
  else if (renderingAssetType.Contains("UniversalRenderPipelineAsset"))
69
96
  {
70
- postProcessVolume.profile = URPVolumeProfile;
97
+ _currentPipeline = RenderPipeline.URP;
98
+ }
99
+ else
100
+ {
101
+ _currentPipeline = RenderPipeline.Unknown;
102
+ }
103
+
104
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Detected render pipeline: {_currentPipeline}");
105
+ }
106
+
107
+ private void SetupVolumeProfile()
108
+ {
109
+ if (postProcessVolume == null)
110
+ {
111
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: postProcessVolume is not assigned!");
112
+ return;
113
+ }
114
+
115
+ // Use the assigned volume profile if available
116
+ if (volumeProfile != null)
117
+ {
118
+ postProcessVolume.profile = volumeProfile;
119
+ }
120
+ else if (postProcessVolume.profile == null)
121
+ {
122
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: No volume profile assigned and postProcessVolume has no profile!");
123
+ return;
124
+ }
125
+
126
+ // Handle built-in pipeline
127
+ if (_currentPipeline == RenderPipeline.BuiltIn)
128
+ {
129
+ if (_isDebugSTATIC) Debug.LogWarning("FadeMask: Built-in pipeline detected. Volume system may not be available.");
130
+ return;
71
131
  }
72
132
 
133
+ // Set blend distance (same for all pipelines that support volumes)
134
+ postProcessVolume.blendDistance = 10.0f;
135
+
73
136
  staticPostProcessVolume = postProcessVolume;
74
- staticPostProcessVolume.profile.TryGet<ColorAdjustments>(out colorAdjustments);
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
+ }
143
+ }
75
144
 
76
- SetVolumeTo_InitialSetup();
145
+ private bool TryGetColorAdjustments()
146
+ {
147
+ try
148
+ {
149
+ switch (_currentPipeline)
150
+ {
151
+ case RenderPipeline.HDRP:
152
+ return TryGetHDRPColorAdjustments();
153
+
154
+ case RenderPipeline.URP:
155
+ return TryGetURPColorAdjustments();
156
+
157
+ default:
158
+ if (_isDebugSTATIC) Debug.LogError($"FadeMask: Unsupported pipeline: {_currentPipeline}");
159
+ break;
160
+ }
161
+
162
+ return false;
163
+ }
164
+ catch (Exception e)
165
+ {
166
+ if (_isDebugSTATIC) Debug.LogError($"FadeMask: Error getting ColorAdjustments: {e.Message}");
167
+ return false;
168
+ }
169
+ }
77
170
 
78
- FadeValue(false, .5f);
171
+ private bool TryGetHDRPColorAdjustments()
172
+ {
173
+ try
174
+ {
175
+ // Find HDRP ColorAdjustments type
176
+ System.Type hdrpColorAdjustmentsType = System.Type.GetType("UnityEngine.Rendering.HighDefinition.ColorAdjustments, Unity.RenderPipelines.HighDefinition.Runtime");
177
+
178
+ // Fallback: search through loaded assemblies
179
+ if (hdrpColorAdjustmentsType == null)
180
+ {
181
+ foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
182
+ {
183
+ if (assembly.GetName().Name.Contains("HighDefinition"))
184
+ {
185
+ hdrpColorAdjustmentsType = assembly.GetType("UnityEngine.Rendering.HighDefinition.ColorAdjustments");
186
+ if (hdrpColorAdjustmentsType != null) break;
187
+ }
188
+ }
189
+ }
190
+
191
+ if (hdrpColorAdjustmentsType == null)
192
+ {
193
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: HDRP ColorAdjustments type not found.");
194
+ return false;
195
+ }
196
+
197
+ // Use reflection to call TryGet<T> method
198
+ var profileType = staticPostProcessVolume.profile.GetType();
199
+ var tryGetMethods = profileType.GetMethods().Where(m => m.Name == "TryGet" && m.IsGenericMethodDefinition).ToArray();
200
+
201
+ if (tryGetMethods.Length == 0)
202
+ {
203
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: No generic TryGet methods found on VolumeProfile");
204
+ return false;
205
+ }
206
+
207
+ var tryGetMethod = tryGetMethods[0].MakeGenericMethod(hdrpColorAdjustmentsType);
208
+ var parameters = new object[] { null };
209
+ var result = (bool)tryGetMethod.Invoke(staticPostProcessVolume.profile, parameters);
210
+
211
+ if (result)
212
+ {
213
+ hdrpColorAdjustments = parameters[0];
214
+ if (_isDebugSTATIC) Debug.Log("FadeMask: Successfully got HDRP ColorAdjustments");
215
+ return true;
216
+ }
217
+ else
218
+ {
219
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: Failed to get HDRP ColorAdjustments from volume profile");
220
+ return false;
221
+ }
222
+ }
223
+ catch (Exception e)
224
+ {
225
+ if (_isDebugSTATIC) Debug.LogError($"FadeMask: Error getting HDRP ColorAdjustments: {e.Message}");
226
+ return false;
227
+ }
228
+ }
229
+
230
+ private bool TryGetURPColorAdjustments()
231
+ {
232
+ try
233
+ {
234
+ // Find URP ColorAdjustments type
235
+ System.Type urpColorAdjustmentsType = System.Type.GetType("UnityEngine.Rendering.Universal.ColorAdjustments, Unity.RenderPipelines.Universal.Runtime");
236
+
237
+ // Fallback: search through loaded assemblies
238
+ if (urpColorAdjustmentsType == null)
239
+ {
240
+ foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
241
+ {
242
+ if (assembly.GetName().Name.Contains("Universal"))
243
+ {
244
+ urpColorAdjustmentsType = assembly.GetType("UnityEngine.Rendering.Universal.ColorAdjustments");
245
+ if (urpColorAdjustmentsType != null) break;
246
+ }
247
+ }
248
+ }
249
+
250
+ if (urpColorAdjustmentsType == null)
251
+ {
252
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: URP ColorAdjustments type not found.");
253
+ return false;
254
+ }
255
+
256
+ // Use reflection to call TryGet<T> method
257
+ var profileType = staticPostProcessVolume.profile.GetType();
258
+ var tryGetMethods = profileType.GetMethods().Where(m => m.Name == "TryGet" && m.IsGenericMethodDefinition).ToArray();
259
+
260
+ if (tryGetMethods.Length == 0)
261
+ {
262
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: No generic TryGet methods found on VolumeProfile");
263
+ return false;
264
+ }
265
+
266
+ var tryGetMethod = tryGetMethods[0].MakeGenericMethod(urpColorAdjustmentsType);
267
+ var parameters = new object[] { null };
268
+ var result = (bool)tryGetMethod.Invoke(staticPostProcessVolume.profile, parameters);
269
+
270
+ if (result)
271
+ {
272
+ urpColorAdjustments = parameters[0];
273
+ if (_isDebugSTATIC) Debug.Log("FadeMask: Successfully got URP ColorAdjustments");
274
+ return true;
275
+ }
276
+ else
277
+ {
278
+ if (_isDebugSTATIC) Debug.LogError("FadeMask: Failed to get URP ColorAdjustments from volume profile");
279
+ return false;
280
+ }
281
+ }
282
+ catch (Exception e)
283
+ {
284
+ if (_isDebugSTATIC) Debug.LogError($"FadeMask: Error getting URP ColorAdjustments: {e.Message}");
285
+ return false;
286
+ }
79
287
  }
80
288
 
81
289
  private void OnEnable() => Subscribe();
@@ -86,15 +294,17 @@ namespace jeanf.universalplayer
86
294
  {
87
295
  inputBinding.Enable();
88
296
  inputBinding.performed += _ => SwitchFadeState();
89
- fadeOutChannelSO.OnEventRaised += FadeValue;
297
+ if (fadeOutChannelSO != null)
298
+ fadeOutChannelSO.OnEventRaised += FadeValue;
90
299
  TogglePPE += ChangePostProcessing;
91
300
  }
92
301
 
93
302
  private void Unsubscribe()
94
303
  {
95
- if (_shaderMaterial)_shaderMaterial.SetColor(FadeColor, color);
304
+ if (_shaderMaterial) _shaderMaterial.SetColor(FadeColor, color);
96
305
  inputBinding.performed -= null;
97
- fadeOutChannelSO.OnEventRaised -= FadeValue;
306
+ if (fadeOutChannelSO != null)
307
+ fadeOutChannelSO.OnEventRaised -= FadeValue;
98
308
  inputBinding.Disable();
99
309
  DisableFadeHandle();
100
310
  TogglePPE -= ChangePostProcessing;
@@ -102,18 +312,149 @@ namespace jeanf.universalplayer
102
312
 
103
313
  public static void SetVolumeTo_InitialSetup()
104
314
  {
105
- colorAdjustments.colorFilter.value = Color.black;
106
- colorAdjustments.saturation.value = 0;
315
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting initial setup for {_currentPipeline}");
316
+
317
+ switch (_currentPipeline)
318
+ {
319
+ case RenderPipeline.HDRP:
320
+ if (hdrpColorAdjustments != null)
321
+ {
322
+ SetColorAdjustmentProperty(hdrpColorAdjustments, "colorFilter", Color.black);
323
+ SetColorAdjustmentProperty(hdrpColorAdjustments, "saturation", 0f);
324
+ }
325
+ else if (_isDebugSTATIC) Debug.LogWarning("FadeMask: HDRP ColorAdjustments is null.");
326
+ break;
327
+
328
+ case RenderPipeline.URP:
329
+ if (urpColorAdjustments != null)
330
+ {
331
+ SetColorAdjustmentProperty(urpColorAdjustments, "colorFilter", Color.black);
332
+ SetColorAdjustmentProperty(urpColorAdjustments, "saturation", 0f);
333
+ }
334
+ else if (_isDebugSTATIC) Debug.LogWarning("FadeMask: URP ColorAdjustments is null.");
335
+ break;
336
+
337
+ default:
338
+ if (_isDebugSTATIC) Debug.LogWarning($"FadeMask: Cannot set initial setup for pipeline: {_currentPipeline}");
339
+ break;
340
+ }
107
341
  }
342
+
108
343
  public static void SetVolumeTo_HeadInWallSetup()
109
344
  {
110
- colorAdjustments.colorFilter.value = Color.white;
111
- colorAdjustments.saturation.value = -100;
345
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Setting head in wall setup for {_currentPipeline}");
346
+
347
+ switch (_currentPipeline)
348
+ {
349
+ case RenderPipeline.HDRP:
350
+ if (hdrpColorAdjustments != null)
351
+ {
352
+ SetColorAdjustmentProperty(hdrpColorAdjustments, "colorFilter", Color.white);
353
+ SetColorAdjustmentProperty(hdrpColorAdjustments, "saturation", -100f);
354
+ }
355
+ else if (_isDebugSTATIC) Debug.LogWarning("FadeMask: HDRP ColorAdjustments is null.");
356
+ break;
357
+
358
+ case RenderPipeline.URP:
359
+ if (urpColorAdjustments != null)
360
+ {
361
+ SetColorAdjustmentProperty(urpColorAdjustments, "colorFilter", Color.white);
362
+ SetColorAdjustmentProperty(urpColorAdjustments, "saturation", -100f);
363
+ }
364
+ else if (_isDebugSTATIC) Debug.LogWarning("FadeMask: URP ColorAdjustments is null.");
365
+ break;
366
+
367
+ default:
368
+ if (_isDebugSTATIC) Debug.LogWarning($"FadeMask: Cannot set head in wall setup for pipeline: {_currentPipeline}");
369
+ break;
370
+ }
371
+ }
372
+
373
+ private static void SetColorAdjustmentProperty(object colorAdjustments, string propertyName, object value)
374
+ {
375
+ if (colorAdjustments == null) return;
376
+
377
+ try
378
+ {
379
+ var colorAdjustmentsType = colorAdjustments.GetType();
380
+ var parametersProperty = colorAdjustmentsType.GetProperty("parameters");
381
+ if (parametersProperty == null) return;
382
+
383
+ var parameters = parametersProperty.GetValue(colorAdjustments);
384
+ if (parameters == null) return;
385
+
386
+ var parametersEnumerable = parameters as System.Collections.IEnumerable;
387
+ if (parametersEnumerable == null) return;
388
+
389
+ var parametersList = new System.Collections.Generic.List<object>();
390
+ foreach (var param in parametersEnumerable)
391
+ {
392
+ if (param != null) parametersList.Add(param);
393
+ }
394
+
395
+ object targetParameter = null;
396
+
397
+ if (propertyName == "colorFilter")
398
+ {
399
+ // Find ColorParameter
400
+ foreach (var param in parametersList)
401
+ {
402
+ if (param.GetType().Name == "ColorParameter")
403
+ {
404
+ targetParameter = param;
405
+ break;
406
+ }
407
+ }
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
+ {
414
+ targetParameter = parametersList[4];
415
+ }
416
+ else
417
+ {
418
+ // Fallback: find ClampedFloatParameter with range -100 to 100
419
+ foreach (var param in parametersList)
420
+ {
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
+ }
433
+ }
434
+ }
435
+ }
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
+ }
448
+ }
449
+ catch (Exception e)
450
+ {
451
+ if (_isDebugSTATIC) Debug.LogError($"FadeMask: Error setting {propertyName}: {e.Message}");
452
+ }
112
453
  }
113
454
 
114
455
  private void Update()
115
456
  {
116
- if(!checkForDebugChangeState) return;
457
+ if (!checkForDebugChangeState) return;
117
458
  _isDebugSTATIC = _isDebug;
118
459
  }
119
460
 
@@ -127,16 +468,15 @@ namespace jeanf.universalplayer
127
468
  {
128
469
  SetVolumeTo_InitialSetup();
129
470
 
130
- if(!isInitComplete)return;
471
+ if (!isInitComplete) return;
131
472
 
132
473
  SetVolumeTo_HeadInWallSetup();
133
474
  }
134
-
135
475
 
136
476
  public static void FadeValue(bool value)
137
477
  {
138
478
  FadeValue(value, _fadeTime);
139
- if (_isDebugSTATIC) Debug.Log($"Fading to: {value}, in {_fadeTime}");
479
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Fading to {value} in {_fadeTime}s");
140
480
  }
141
481
 
142
482
  public static void FadeValue(bool value, float fadeTime)
@@ -152,7 +492,7 @@ namespace jeanf.universalplayer
152
492
  if (_isCurrentlyFading && _targetState == value)
153
493
  return;
154
494
 
155
- if (_isDebugSTATIC) Debug.Log($"Fading to: {value}, in {fadeTime}s");
495
+ if (_isDebugSTATIC) Debug.Log($"FadeMask: Fading to {value} in {fadeTime}s");
156
496
 
157
497
  // Only cancel if the handle is valid and active
158
498
  if (_fadeHandle.IsActive())
@@ -176,5 +516,13 @@ namespace jeanf.universalplayer
176
516
  _fadeHandle.Complete();
177
517
  _fadeHandle.Cancel();
178
518
  }
519
+
520
+ private void OnValidate()
521
+ {
522
+ if (postProcessVolume == null)
523
+ {
524
+ Debug.LogWarning("FadeMask: postProcessVolume is not assigned!");
525
+ }
526
+ }
179
527
  }
180
528
  }
@@ -168,7 +168,7 @@ namespace jeanf.universalplayer
168
168
  else
169
169
  {
170
170
  _ipadState = IpadState.Disabled;
171
- _PrimaryItemStateChannel.RaiseEvent(false);
171
+ //_PrimaryItemStateChannel.RaiseEvent(false);
172
172
  OnIpadStateChanged.Invoke(_ipadState);
173
173
  if(_rightHandPoseManager) _rightHandPoseManager.ApplyDefaultPose();
174
174
  }
@@ -6,15 +6,14 @@
6
6
  "GUID:68550284b645f4b9894995579f34290a",
7
7
  "GUID:fe685ec1767f73d42b749ea8045bfe43",
8
8
  "GUID:24e442f89618c5d4cad09e3d635b003b",
9
- "GUID:457756d89b35d2941b3e7b37b4ece6f1",
10
9
  "GUID:e40ba710768534012815d3193fa296cb",
11
10
  "GUID:dc960734dc080426fa6612f1c5fe95f3",
12
11
  "GUID:ce522b6ed64c8be4c989a1d26d0e3275",
13
12
  "GUID:e134609276952144282613c65d798616",
14
13
  "GUID:e8958e6939af7314a97769de4be4ce25",
15
- "GUID:df380645f10b7bc4b97d4f5eb6303d95",
16
14
  "GUID:3b570a5146f9d4f0fa107ed4559471a3",
17
- "GUID:3aa1866a824b5472da50fe142777d95f"
15
+ "GUID:3aa1866a824b5472da50fe142777d95f",
16
+ "GUID:df380645f10b7bc4b97d4f5eb6303d95"
18
17
  ],
19
18
  "includePlatforms": [],
20
19
  "excludePlatforms": [],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fr.jeanf.universal.player",
3
3
 
4
- "version": "0.8.20",
4
+ "version": "0.8.22",
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",