summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/MeshBaker/scripts/MB3_MBVersionConcrete.cs
blob: 58ddc81e2d7763518904d4f312baba2752a38bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/**
 *	\brief Hax!  DLLs cannot interpret preprocessor directives, so this class acts as a "bridge"
 */
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

#if MB_USING_HDRP && UNITY_2019_3_OR_NEWER
    using UnityEngine.Rendering.HighDefinition;
#elif MB_USING_HDRP && UNITY_2018_4_OR_NEWER
    using UnityEngine.Experimental.Rendering.HDPipeline;
#endif

namespace DigitalOpus.MB.Core
{
    public class MBVersionConcrete : MBVersionInterface
    {
        public string version()
        {
            return "3.32.0";
        }

        public int GetMajorVersion()
        {
            /*
#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
                        return 3;
#elif UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
                        return 4;
#else
                        return 5;
#endif
            */
            string v = Application.unityVersion;
            String[] vs = v.Split(new char[] { '.' });
            return Int32.Parse(vs[0]);
        }

        public int GetMinorVersion()
        {
            /*
#if UNITY_3_0 || UNITY_3_0_0
            return 0;
#elif UNITY_3_1
            return 1;
#elif UNITY_3_2
            return 2;
#elif UNITY_3_3
            return 3;
#elif UNITY_3_4
            return 4;
#elif UNITY_3_5
            return 5;
#elif UNITY_4_0 || UNITY_4_0_1
            return 0;
#elif UNITY_4_1
            return 1;
#elif UNITY_4_2
            return 2;
#elif UNITY_4_3
            return 3;
#elif UNITY_4_4
            return 4;
#elif UNITY_4_5
            return 5;
#else
            return 0;
#endif
            */
            string v = Application.unityVersion;     String[] vs = v.Split(new char[] { '.' });
            return Int32.Parse(vs[1]);
        }

        public bool GetActive(GameObject go)
        {
#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            return go.active;
#else
            return go.activeInHierarchy;
#endif
        }

        public void SetActive(GameObject go, bool isActive)
        {
#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            go.active = isActive;
#else
            go.SetActive(isActive);
#endif
        }

        public void SetActiveRecursively(GameObject go, bool isActive)
        {
#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            go.SetActiveRecursively(isActive);
#else
            go.SetActive(isActive);
#endif
        }

        public UnityEngine.Object[] FindSceneObjectsOfType(Type t)
        {
#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            return GameObject.FindSceneObjectsOfType(t);
#else
            return GameObject.FindObjectsOfType(t);
#endif
        }

        public void OptimizeMesh(Mesh m)
        {
#if UNITY_EDITOR
#if UNITY_5_5_OR_NEWER
            UnityEditor.MeshUtility.Optimize(m);
#else
            m.Optimize();
#endif
#endif
        }


        public bool IsRunningAndMeshNotReadWriteable(Mesh m)
        {
            if (Application.isPlaying)
            {
#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
                return false;
#else
                return !m.isReadable;
#endif
            }
            else
            {
                return false;
            }
        }

        Vector2 _HALF_UV = new Vector2(.5f, .5f);
        public Vector2[] GetMeshUV1s(Mesh m, MB2_LogLevel LOG_LEVEL)
        {
            Vector2[] uv;
#if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
            uv = m.uv1;

#else
            if (LOG_LEVEL >= MB2_LogLevel.warn) MB2_Log.LogDebug("UV1 does not exist in Unity 5+");
            uv = m.uv;
#endif
            if (uv.Length == 0)
            {
                if (LOG_LEVEL >= MB2_LogLevel.debug) MB2_Log.LogDebug("Mesh " + m + " has no uv1s. Generating");
                if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Mesh " + m + " didn't have uv1s. Generating uv1s.");
                uv = new Vector2[m.vertexCount];
                for (int i = 0; i < uv.Length; i++) { uv[i] = _HALF_UV; }
            }
            return uv;
        }

        public Vector2[] GetMeshUVChannel(int channel, Mesh m, MB2_LogLevel LOG_LEVEL)
        {
            Vector2[] uvs = new Vector2[0];

            switch (channel)
            {
                case 0:
                    uvs = m.uv;
                    break;
                case 2:
                    uvs = m.uv2;
                    break;
                case 3:
                    uvs = m.uv3;
                    break;
                case 4:
                    uvs = m.uv4;
                    break;
#if UNITY_2018_2_OR_NEWER
                case 5:
                    uvs = m.uv5;
                    break;
                case 6:
                    uvs = m.uv6;
                    break;
                case 7:
                    uvs = m.uv7;
                    break;
                case 8:
                    uvs = m.uv8;
                    break;
#endif
                default:
                    Debug.LogError("Mesh does not have UV channel " + channel);
                    break;
            }

            if (uvs.Length == 0)
            {
                if (LOG_LEVEL >= MB2_LogLevel.debug) MB2_Log.LogDebug("Mesh " + m + " has no uv" + channel + ". Generating");
                uvs = new Vector2[m.vertexCount];
                for (int i = 0; i < uvs.Length; i++) { uvs[i] = _HALF_UV; }
            }

            return uvs;
        }

        public void MeshClear(Mesh m, bool t)
        {
#if UNITY_3_5
                m.Clear();
#else
            m.Clear(t);
#endif
        }

        public void MeshAssignUVChannel(int channel, Mesh m, Vector2[] uvs)
        {
            switch (channel)
            {
                case 0:
                    m.uv = uvs;
                    break;
                case 2:
                    m.uv2 = uvs;
                    break;
                case 3:
                    m.uv3 = uvs;
                    break;
                case 4:
                    m.uv4 = uvs;
                    break;
#if UNITY_2018_2_OR_NEWER
                case 5:
                    m.uv5 = uvs;
                    break;
                case 6:
                    m.uv6 = uvs;
                    break;
                case 7:
                    m.uv7 = uvs;
                    break;
                case 8:
                    m.uv8 = uvs;
                    break;
#endif
                default:
                    Debug.LogError("Mesh does not have UV channel " + channel);
                    break;
            }
        }

        public Vector4 GetLightmapTilingOffset(Renderer r)
        {
#if (UNITY_4_6 || UNITY_4_7 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
              return r.lightmapTilingOffset ;
#else
            return r.lightmapScaleOffset; //r.lightmapScaleOffset ;
#endif
        }
#if UNITY_5_OR_NEWER
        public Transform[] GetBones(Renderer r, bool isSkinnedMeshWithBones)
        {
            if (r is SkinnedMeshRenderer)
            {
                Transform[] bone;
                //check if I need to deoptimize
                Animator anim = r.GetComponentInParent<Animator>();

                if (anim != null)
                {
                    if (anim.hasTransformHierarchy)
                    {
                        //nothing to do
                    } else if (anim.isOptimizable)
                    {
                        //Deoptimize
                        AnimatorUtility.DeoptimizeTransformHierarchy(anim.gameObject);
                        
                    }
                    else
                    {
                        Debug.LogError("Could not getBones. Bones optimized but could not create TransformHierarchy.");
                        return null;
                    }
                    bone = ((SkinnedMeshRenderer)r).bones;
                    //can't deoptimize here because the transforms need to exist for the combined  mesh
                } else
                {
                    //no Animator component but check to see if bones were optimized on import
                    bone = ((SkinnedMeshRenderer)r).bones;
#if UNITY_EDITOR
                    if (bone.Length == 0)
                    {
                    Mesh m = ((SkinnedMeshRenderer)r).sharedMesh;
                    if (m.bindposes.Length != bone.Length) Debug.LogError("SkinnedMesh (" + r.gameObject + ") in the list of objects to combine has no bones. Check that 'optimize game object' is not checked in the 'Rig' tab of the asset importer. Mesh Baker cannot combine optimized skinned meshes because the bones are not available.");
                }
#endif
                }
                return bone;	
            }
            else if (r is MeshRenderer)
            {
                Transform[] bone = new Transform[1];
                bone[0] = r.transform;
                return bone;
            }
            else {
                Debug.LogError("Could not getBones. Object is not a Renderer.");
                return null;
            }
        }
#else
        public Transform[] GetBones(Renderer r, bool isSkinnedMeshWithBones)
        {
            if (isSkinnedMeshWithBones)
            {
                Transform[] bone = ((SkinnedMeshRenderer)r).bones;
#if UNITY_EDITOR
                if (bone.Length == 0)
                {
                    Mesh m = ((SkinnedMeshRenderer)r).sharedMesh;
                    if (m.bindposes.Length != bone.Length) Debug.LogError("SkinnedMesh (" + r.gameObject + ") in the list of objects to combine has no bones. Check that 'optimize game object' is not checked in the 'Rig' tab of the asset importer. Mesh Baker cannot combine optimized skinned meshes because the bones are not available.");
                }
#endif
                return bone;
            }
            else if (r is MeshRenderer ||
                (r is SkinnedMeshRenderer && !isSkinnedMeshWithBones))
            {
                Transform[] bone = new Transform[1];
                bone[0] = r.transform;
                return bone;
            }
            else
            {
                Debug.LogError("Could not getBones. Object does not have a renderer");
                return null;
            }
        }
#endif

        public int GetBlendShapeFrameCount(Mesh m, int shapeIndex)
        {
#if UNITY_5_3_OR_NEWER
            return m.GetBlendShapeFrameCount(shapeIndex);
#else
            return 0;
#endif
        }

        public float GetBlendShapeFrameWeight(Mesh m, int shapeIndex, int frameIndex)
        {
#if UNITY_5_3_OR_NEWER
            return m.GetBlendShapeFrameWeight(shapeIndex, frameIndex);
#else
            return 0;
#endif
        }

        public void GetBlendShapeFrameVertices(Mesh m, int shapeIndex, int frameIndex, Vector3[] vs, Vector3[] ns, Vector3[] ts)
        {
#if UNITY_5_3_OR_NEWER
            m.GetBlendShapeFrameVertices(shapeIndex, frameIndex, vs, ns, ts);
#endif
        }

        public void ClearBlendShapes(Mesh m)
        {
#if UNITY_5_3_OR_NEWER
            m.ClearBlendShapes();
#endif
        }

        public void AddBlendShapeFrame(Mesh m, string nm, float wt, Vector3[] vs, Vector3[] ns, Vector3[] ts)
        {
#if UNITY_5_3_OR_NEWER
            m.AddBlendShapeFrame(nm, wt, vs, ns, ts);
#endif
        }

        public int MaxMeshVertexCount()
        {
#if UNITY_2017_3_OR_NEWER
            return 2147483646;
#else
            return 65535;
#endif
        }

        public void SetMeshIndexFormatAndClearMesh(Mesh m, int numVerts, bool vertices, bool justClearTriangles)
        {
#if UNITY_2017_3_OR_NEWER
            if (vertices && numVerts > 65534 && m.indexFormat == UnityEngine.Rendering.IndexFormat.UInt16)
            {
                MBVersion.MeshClear(m, false);
                m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
                return;
            }
            else if (vertices && numVerts <= 65534 && m.indexFormat == UnityEngine.Rendering.IndexFormat.UInt32)
            {
                MBVersion.MeshClear(m, false);
                m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt16;
                return;
            }
#endif
            if (justClearTriangles)
            {
                MBVersion.MeshClear(m, true); //clear just triangles 
            }
            else
            {//clear all the data and start with a blank mesh
                MBVersion.MeshClear(m, false);
            }
        }

        public bool GraphicsUVStartsAtTop()
        {
#if UNITY_2017_1_OR_NEWER
            return SystemInfo.graphicsUVStartsAtTop;
#else
            if (SystemInfo.graphicsDeviceVersion.Contains("metal"))
            {
                return false;
            }
            else
            {
                // "opengl es, direct3d"
                return true;
            }
#endif
        }

        public bool IsTextureReadable(Texture2D tex)
        {
#if UNITY_2018_3_OR_NEWER
            return tex.isReadable;
#else
            try
            {
                tex.GetPixel(0, 0);
                return true;
            }
            catch
            {
                return false;
            }
#endif
        }

        public bool CollectPropertyNames(List<ShaderTextureProperty> texPropertyNames, ShaderTextureProperty[] shaderTexPropertyNames, List<ShaderTextureProperty> _customShaderPropNames, Material resultMaterial, MB2_LogLevel LOG_LEVEL)
        {
#if UNITY_2019_3_OR_NEWER
            // 2018.2 and up
            // Collect the property names from the shader
            // Check with the lists of property names to flag which ones are normal maps.
            if (resultMaterial != null && resultMaterial.shader != null)
            {
                Shader s = resultMaterial.shader;

                for (int i = 0; i < s.GetPropertyCount(); i++)
                {
                    if (s.GetPropertyType(i) == UnityEngine.Rendering.ShaderPropertyType.Texture)
                    {
                        string matPropName = s.GetPropertyName(i);
                        if (resultMaterial.GetTextureOffset(matPropName) != new Vector2(0f, 0f))
                        {
                            if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material has non-zero offset for property " + matPropName + ". This is probably incorrect.");
                        }

                        if (resultMaterial.GetTextureScale(matPropName) != new Vector2(1f, 1f))
                        {
                            if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material should probably have tiling of 1,1 for propert " + matPropName);
                        }

                        ShaderTextureProperty pn = null;
                        // We need to know if the property is a normal map or not.
                        // first check the list of default names
                        for (int defaultIdx = 0; defaultIdx < shaderTexPropertyNames.Length; defaultIdx++)
                        {
                            if (shaderTexPropertyNames[defaultIdx].name == matPropName)
                            {
                                pn = new ShaderTextureProperty(matPropName, shaderTexPropertyNames[defaultIdx].isNormalMap);
                            }
                        }

                        // now check the list of custom property names
                        for (int custPropIdx = 0; custPropIdx < _customShaderPropNames.Count; custPropIdx++)
                        {
                            if (_customShaderPropNames[custPropIdx].name == matPropName)
                            {
                                pn = new ShaderTextureProperty(matPropName, _customShaderPropNames[custPropIdx].isNormalMap);
                            }
                        }

                        if (pn == null)
                        {
                            pn = new ShaderTextureProperty(matPropName, false, true);
                        }

                        texPropertyNames.Add(pn);
                    }
                }
            }

            return true;
#elif UNITY_2018_3_OR_NEWER
            // 2018.2 and up
            // Collect the property names from the material
            // Check with the lists of property names to flag which ones are normal maps.
            string[] matPropertyNames = resultMaterial.GetTexturePropertyNames();
            for (int matIdx = 0; matIdx < matPropertyNames.Length; matIdx++)
            {
                string matPropName = matPropertyNames[matIdx];
                if (resultMaterial.GetTextureOffset(matPropName) != new Vector2(0f, 0f))
                {
                    if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material has non-zero offset for property " + matPropName + ". This is probably incorrect.");
                }

                if (resultMaterial.GetTextureScale(matPropName) != new Vector2(1f, 1f))
                {
                    if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material should probably have tiling of 1,1 for propert " + matPropName);
                }

                ShaderTextureProperty pn = null;
                // We need to know if the property is a normal map or not.
                // first check the list of default names
                for (int defaultIdx = 0; defaultIdx < shaderTexPropertyNames.Length; defaultIdx++)
                {
                    if (shaderTexPropertyNames[defaultIdx].name == matPropName)
                    {
                        pn = new ShaderTextureProperty(matPropName, shaderTexPropertyNames[defaultIdx].isNormalMap);
                    }
                }

                // now check the list of custom property names
                for (int custPropIdx = 0; custPropIdx < _customShaderPropNames.Count; custPropIdx++)
                {
                    if (_customShaderPropNames[custPropIdx].name == matPropName)
                    {
                        pn = new ShaderTextureProperty(matPropName, _customShaderPropNames[custPropIdx].isNormalMap);
                    }
                }

                if (pn == null)
                {
                    pn = new ShaderTextureProperty(matPropName, false, true);
                }

                texPropertyNames.Add(pn);
            }

            return true;
#else
            { // Pre 2018.2, doesn't have API for querying material for property names.
                //Collect the property names for the textures
                string shaderPropStr = "";
                for (int i = 0; i < shaderTexPropertyNames.Length; i++)
                {
                    if (resultMaterial.HasProperty(shaderTexPropertyNames[i].name))
                    {
                        shaderPropStr += ", " + shaderTexPropertyNames[i].name;
                        if (!texPropertyNames.Contains(shaderTexPropertyNames[i])) texPropertyNames.Add(shaderTexPropertyNames[i]);
                        if (resultMaterial.GetTextureOffset(shaderTexPropertyNames[i].name) != new Vector2(0f, 0f))
                        {
                            if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material has non-zero offset. This is may be incorrect.");
                        }
                        if (resultMaterial.GetTextureScale(shaderTexPropertyNames[i].name) != new Vector2(1f, 1f))
                        {
                            if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material should have tiling of 1,1");
                        }
                    }
                }

                for (int i = 0; i < _customShaderPropNames.Count; i++)
                {
                    if (resultMaterial.HasProperty(_customShaderPropNames[i].name))
                    {
                        shaderPropStr += ", " + _customShaderPropNames[i].name;
                        texPropertyNames.Add(_customShaderPropNames[i]);
                        if (resultMaterial.GetTextureOffset(_customShaderPropNames[i].name) != new Vector2(0f, 0f))
                        {
                            if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material has non-zero offset. This is probably incorrect.");
                        }
                        if (resultMaterial.GetTextureScale(_customShaderPropNames[i].name) != new Vector2(1f, 1f))
                        {
                            if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material should probably have tiling of 1,1.");
                        }
                    }
                    else
                    {
                        if (LOG_LEVEL >= MB2_LogLevel.warn) Debug.LogWarning("Result material shader does not use property " + _customShaderPropNames[i].name + " in the list of custom shader property names");
                    }
                }
            }
            return true;
#endif
        }

        public void DoSpecialRenderPipeline_TexturePackerFastSetup(GameObject cameraGameObject)
        {
            MBVersion.PipelineType pipelineType = DetectPipeline();
#if MB_USING_HDRP && UNITY_2018_4_OR_NEWER
            if (pipelineType != MBVersion.PipelineType.HDRP)
            {
                Debug.LogError("The 'PlayerSettings -> Other Settings -> Scripting Define Symbols' included the symbol 'MB_USING_HDRP' which should only be used " +
                        "if the GraphicsSettings -> Render Pipeline Asset is HDRenderPipelineAsset. The Render Pipeline Asset is NOT HDRenderPipelineAsset. Please " +
                        " remove the symbol MB_USING_HDRP from PlayerSettings -> Other Settings -> Scripting Define Symbols");
            }
            
            HDAdditionalCameraData acd = cameraGameObject.GetComponent<HDAdditionalCameraData>();
            if (acd == null)
            {
                acd = cameraGameObject.AddComponent<HDAdditionalCameraData>();
            }

            acd.volumeLayerMask = LayerMask.GetMask("UI");
#endif
        }

        public ColorSpace GetProjectColorSpace()
        {
#if UNITY_EDITOR
            if (Application.isEditor)
            {
                return UnityEditor.PlayerSettings.colorSpace;
            }
#endif
            if (QualitySettings.desiredColorSpace != QualitySettings.activeColorSpace)
            {
                Debug.LogError("The active color space (" + QualitySettings.activeColorSpace + ") is not the desired color space (" + QualitySettings.desiredColorSpace + "). Baked atlases may be off.");
            }

            return QualitySettings.activeColorSpace;
        }

        public MBVersion.PipelineType DetectPipeline()
        {
#if UNITY_2019_1_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
            {
                // SRP
                var srpType = UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset.GetType().ToString();
                if (srpType.Contains("HDRenderPipelineAsset"))
                {
                    return MBVersion.PipelineType.HDRP;
                }
                else if (srpType.Contains("UniversalRenderPipelineAsset") || srpType.Contains("LightweightRenderPipelineAsset"))
                {
                    return MBVersion.PipelineType.URP;
                }
                else return MBVersion.PipelineType.Unsupported;
            }
#elif UNITY_2017_1_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null) {
                // SRP not supported before 2019
                return MBVersion.PipelineType.Unsupported;
            }
#endif
            // no SRP
            return MBVersion.PipelineType.Default;
        }

        public string UnescapeURL(string url)
        {
#if UNITY_2017_3_OR_NEWER
            return UnityEngine.Networking.UnityWebRequest.UnEscapeURL(url);
#else
            // Not correct but not going to spend a lot of effort writing custom
            // code for versions of Unity soon to be depricated.
            return url;
#endif
        }
    }
}