summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/MeshBaker/Editor/MB3_MBVersionConcreteEditor.cs
blob: 1e009bae93112b9c1f37ea4712b800e1aee466e1 (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
/**
 *	\brief Hax!  DLLs cannot interpret preprocessor directives, so this class acts as a "bridge"
 */
using System;
using UnityEngine;
using UnityEditor;
using System.Collections;
using DigitalOpus.MB.Core;

namespace DigitalOpus.MB.Core
{

    public class MBVersionEditorConcrete : MBVersionEditorInterface
    {

        /// <summary>
        /// Used to map the activeBuildTarget to a string argument needed by TextureImporter.GetPlatformTextureSettings
        /// The allowed values for GetPlatformTextureSettings are "Web", "Standalone", "iPhone", "Android" and "FlashPlayer".
        /// </summary>
        /// <returns></returns>
        public string GetPlatformString()
        {
#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)
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iPhone){
                return "iPhone";	
            }
#else
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
            {
                return "iPhone";
            }
#endif
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WSAPlayer)
            {
                return "Windows Store Apps";
            }
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.PSP2)
            {
                return "PSP2";
            }
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.PS4)
            {
                return "PS4";
            }
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.XboxOne)
            {
                return "XboxOne";
            }
#if (UNITY_2017_3_OR_NEWER)
#else
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.SamsungTV)
            {
                return "Samsung TV";
            }
#endif
#if (UNITY_5_5_OR_NEWER)
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.N3DS)
            {
                return "Nintendo 3DS";
            }
#endif
#if (UNITY_5_3 || UNITY_5_2 || UNITY_5_3_OR_NEWER)
#if (UNITY_2018_1_OR_NEWER)
            // wiiu support was removed in 2018.1
#else
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WiiU)
            {
                return "WiiU";
            }
#endif
#endif
#if (UNITY_5_3 || UNITY_5_3_OR_NEWER)
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.tvOS)
            {
                return "tvOS";
            }
#endif
#if (UNITY_2018_2_OR_NEWER)

#else
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Tizen)
            {
                return "Tizen";
            }
#endif
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
            {
                return "Android";
            }
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneLinux ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneLinux64 ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneLinuxUniversal ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64 ||
#if UNITY_2017_3_OR_NEWER
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSX
#else
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSXIntel ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSXIntel64 ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSXUniversal
#endif
                )
            {
                return "Standalone";
            }
#if !UNITY_5_4_OR_NEWER
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayer ||
                EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayerStreamed
                )
            {
                return "Web";
            }
#endif
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL)
            {
                return "WebGL";
            }
            return null;
        }

        public void RegisterUndo(UnityEngine.Object o, string s)
        {
#if (UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
            Undo.RegisterUndo(o, s);
#else
            Undo.RecordObject(o, s);
#endif
        }

        public void SetInspectorLabelWidth(float width)
        {
#if (UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5)
            EditorGUIUtility.LookLikeControls(width);
#else
            EditorGUIUtility.labelWidth = width;
#endif
        }

        public void UpdateIfDirtyOrScript(SerializedObject so)
        {
#if UNITY_5_6_OR_NEWER
            so.UpdateIfRequiredOrScript();
#else
            so.UpdateIfDirtyOrScript();
#endif
        }

        public UnityEngine.Object PrefabUtility_GetCorrespondingObjectFromSource(GameObject go)
        {
#if UNITY_2018_2_OR_NEWER
            return PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
            return PrefabUtility.GetPrefabParent(go);
#endif
        }

        public bool IsAutoPVRTC(TextureImporterFormat platformFormat, TextureImporterFormat platformDefaultFormat)
        {
            if ((
#if UNITY_2017_1_OR_NEWER
                    platformFormat == TextureImporterFormat.Automatic
#elif UNITY_5_5_OR_NEWER
                    platformFormat == TextureImporterFormat.Automatic ||
                    platformFormat == TextureImporterFormat.Automatic16bit ||
                    platformFormat == TextureImporterFormat.AutomaticCompressed ||
                    platformFormat == TextureImporterFormat.AutomaticCompressedHDR ||
                    platformFormat == TextureImporterFormat.AutomaticCrunched ||
                    platformFormat == TextureImporterFormat.AutomaticHDR
#else
                    platformFormat == TextureImporterFormat.Automatic16bit ||
                    platformFormat == TextureImporterFormat.AutomaticCompressed ||
                    platformFormat == TextureImporterFormat.AutomaticCrunched
#endif
                ) && (
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGB2 ||
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGB4 ||
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGBA2 ||
                    platformDefaultFormat == TextureImporterFormat.PVRTC_RGBA4
                ))
            {
                return true;
            }
            return false;
        }

        public MB_PrefabType GetPrefabType(UnityEngine.Object obj)
        {
#if UNITY_2018_3_OR_NEWER
            if (PrefabUtility.IsPartOfNonAssetPrefabInstance(obj))
            {
                return MB_PrefabType.scenePefabInstance;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(obj))
            {
                return MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab;
            }

            PrefabAssetType assetType = PrefabUtility.GetPrefabAssetType(obj);
            if (assetType == PrefabAssetType.NotAPrefab)
            {
                if (PrefabUtility.GetPrefabInstanceStatus(obj) != PrefabInstanceStatus.NotAPrefab)
                {
                    return MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab;
                }
                else
                {
                    return MB_PrefabType.scenePefabInstance;
                }
            }
            else if (assetType == PrefabAssetType.Model)
            {
                return MB_PrefabType.modelPrefabAsset;
            }
            else if (assetType == PrefabAssetType.Regular ||
                     assetType == PrefabAssetType.Variant ||
                     assetType == PrefabAssetType.MissingAsset)
            {
                return MB_PrefabType.prefabAsset;
            }
            else
            {
                Debug.Assert(false, "Should never get here. Unknown prefab asset type.");
                return MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab;
            }
#else
            PrefabType prefabType = PrefabUtility.GetPrefabType(obj);
            if (prefabType == PrefabType.ModelPrefab)
            {
                return MB_PrefabType.modelPrefabAsset;
            } else if (prefabType == PrefabType.Prefab)
            {
                return MB_PrefabType.prefabAsset;
            } else if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.ModelPrefabInstance)
            {
                return MB_PrefabType.scenePefabInstance;
            } else
            {
                return MB_PrefabType.isInstanceAndNotAPartOfAnyPrefab;
            }
#endif
        }

        public void UnpackPrefabInstance(UnityEngine.GameObject go, ref SerializedObject so)
        {
#if UNITY_2018_3_OR_NEWER
            UnityEngine.Object targetObj = null;
            if (so != null) targetObj = so.targetObject;
            PrefabUtility.UnpackPrefabInstance(go, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);

            // This is a workaround for a nasty Unity bug. The call to UnpackPrefabInstance
            // corrupts the serialized object, Recreate a clean reference here.
            if (so != null) so = new SerializedObject(targetObj);
#else
            // Do nothing.
#endif
        }

        public void ReplacePrefab(GameObject gameObject, string assetPath, MB_ReplacePrefabOption replacePrefabOptions)
        {
#if UNITY_2018_3_OR_NEWER
            PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, assetPath, InteractionMode.AutomatedAction);
#else
            GameObject obj = (GameObject) AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject));
            PrefabUtility.ReplacePrefab(gameObject, obj, (ReplacePrefabOptions) replacePrefabOptions);
#endif
        }

        public GameObject GetPrefabInstanceRoot(GameObject sceneInstance)
        {
#if UNITY_2018_3_OR_NEWER
            return PrefabUtility.GetOutermostPrefabInstanceRoot(sceneInstance);
#else
            return PrefabUtility.FindRootGameObjectWithSameParentPrefab(sceneInstance);
#endif
        }

        public TextureImporterFormat Map_TextureFormat_2_TextureImporterFormat(TextureFormat texFormat, out bool success)
        {
            TextureImporterFormat texImporterFormat;
            success = true;
            switch (texFormat)
            {
                case TextureFormat.ARGB32:
                    texImporterFormat = TextureImporterFormat.ARGB32;
                    break;
                case TextureFormat.RGBA32:
                    texImporterFormat = TextureImporterFormat.RGBA32;
                    break;
                case TextureFormat.RGB24:
                    texImporterFormat = TextureImporterFormat.RGB24;
                    break;
                case TextureFormat.Alpha8:
                    texImporterFormat = TextureImporterFormat.Alpha8;
                    break;

#if UNITY_2020_1_OR_NEWER
                case TextureFormat.ASTC_10x10:
                    texImporterFormat = TextureImporterFormat.ASTC_10x10;
                    break;
                case TextureFormat.ASTC_12x12:
                    texImporterFormat = TextureImporterFormat.ASTC_12x12;
                    break;
                case TextureFormat.ASTC_4x4:
                    texImporterFormat = TextureImporterFormat.ASTC_4x4;
                    break;
                case TextureFormat.ASTC_5x5:
                    texImporterFormat = TextureImporterFormat.ASTC_5x5;
                    break;
                case TextureFormat.ASTC_6x6:
                    texImporterFormat = TextureImporterFormat.ASTC_6x6;
                    break;
                case TextureFormat.ASTC_8x8:
                    texImporterFormat = TextureImporterFormat.ASTC_8x8;
                    break;
#else
                case TextureFormat.ASTC_RGBA_10x10:
                    texImporterFormat = TextureImporterFormat.ASTC_RGBA_10x10;
                    break;
                case TextureFormat.ASTC_RGBA_12x12:
                    texImporterFormat = TextureImporterFormat.ASTC_RGBA_12x12;
                    break;
                case TextureFormat.ASTC_RGBA_4x4:
                    texImporterFormat = TextureImporterFormat.ASTC_RGBA_4x4;
                    break;
                case TextureFormat.ASTC_RGBA_5x5:
                    texImporterFormat = TextureImporterFormat.ASTC_RGBA_5x5;
                    break;
                case TextureFormat.ASTC_RGBA_6x6:
                    texImporterFormat = TextureImporterFormat.ASTC_RGBA_6x6;
                    break;
                case TextureFormat.ASTC_RGBA_8x8:
                    texImporterFormat = TextureImporterFormat.ASTC_RGBA_8x8;
                    break;

                case TextureFormat.ASTC_RGB_10x10:
                    texImporterFormat = TextureImporterFormat.ASTC_RGB_10x10;
                    break;
                case TextureFormat.ASTC_RGB_12x12:
                    texImporterFormat = TextureImporterFormat.ASTC_RGB_12x12;
                    break;
                case TextureFormat.ASTC_RGB_4x4:
                    texImporterFormat = TextureImporterFormat.ASTC_RGB_4x4;
                    break;
                case TextureFormat.ASTC_RGB_5x5:
                    texImporterFormat = TextureImporterFormat.ASTC_RGB_5x5;
                    break;
                case TextureFormat.ASTC_RGB_6x6:
                    texImporterFormat = TextureImporterFormat.ASTC_RGB_6x6;
                    break;
                case TextureFormat.ASTC_RGB_8x8:
                    texImporterFormat = TextureImporterFormat.ASTC_RGB_8x8;
                    break;
#endif
                case TextureFormat.BC4:
                    texImporterFormat = TextureImporterFormat.BC4;
                    break;
                case TextureFormat.BC5:
                    texImporterFormat = TextureImporterFormat.BC5;
                    break;
                case TextureFormat.BC6H:
                    texImporterFormat = TextureImporterFormat.BC6H;
                    break;
                case TextureFormat.BC7:
                    texImporterFormat = TextureImporterFormat.BC7;
                    break;

                case TextureFormat.DXT1:
                    texImporterFormat = TextureImporterFormat.DXT1;
                    break;
                case TextureFormat.DXT1Crunched:
                    texImporterFormat = TextureImporterFormat.DXT1Crunched;
                    break;
                case TextureFormat.DXT5:
                    texImporterFormat = TextureImporterFormat.DXT5;
                    break;
                case TextureFormat.DXT5Crunched:
                    texImporterFormat = TextureImporterFormat.DXT5Crunched;
                    break;

                case TextureFormat.EAC_R:
                    texImporterFormat = TextureImporterFormat.EAC_R;
                    break;
                case TextureFormat.EAC_RG:
                    texImporterFormat = TextureImporterFormat.EAC_RG;
                    break;
                case TextureFormat.EAC_RG_SIGNED:
                    texImporterFormat = TextureImporterFormat.EAC_RG_SIGNED;
                    break;
                case TextureFormat.EAC_R_SIGNED:
                    texImporterFormat = TextureImporterFormat.EAC_R_SIGNED;
                    break;

                case TextureFormat.ETC_RGB4:
                    texImporterFormat = TextureImporterFormat.ETC_RGB4;
                    break;
#if UNITY_2017_3_OR_NEWER
                case TextureFormat.ETC_RGB4Crunched:
                    texImporterFormat = TextureImporterFormat.ETC_RGB4Crunched;
                    break;
#endif
                case TextureFormat.ETC2_RGB:
                    texImporterFormat = TextureImporterFormat.ETC2_RGB4;
                    break;
                case TextureFormat.ETC2_RGBA8:
                    texImporterFormat = TextureImporterFormat.ETC2_RGBA8;
                    break;
#if UNITY_2017_3_OR_NEWER
                case TextureFormat.ETC2_RGBA8Crunched:
                    texImporterFormat = TextureImporterFormat.ETC2_RGBA8Crunched;
                    break;
#endif
                case TextureFormat.PVRTC_RGB2:
                    texImporterFormat = TextureImporterFormat.PVRTC_RGB2;
                    break;
                case TextureFormat.PVRTC_RGB4:
                    texImporterFormat = TextureImporterFormat.PVRTC_RGB4;
                    break;
                case TextureFormat.PVRTC_RGBA2:
                    texImporterFormat = TextureImporterFormat.PVRTC_RGBA2;
                    break;
                case TextureFormat.PVRTC_RGBA4:
                    texImporterFormat = TextureImporterFormat.PVRTC_RGBA4;
                    break;
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.R16:
                    texImporterFormat = TextureImporterFormat.R16;
                    break;
#endif
#if UNITY_2018_2_OR_NEWER
                case TextureFormat.R8:
                    texImporterFormat = TextureImporterFormat.R8;
                    break;
#endif
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.RFloat:
                    texImporterFormat = TextureImporterFormat.RFloat;
                    break;
#endif
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.RG16:
                    texImporterFormat = TextureImporterFormat.RG16;
                    break;
#endif
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.RGB9e5Float:
                    texImporterFormat = TextureImporterFormat.RGB9E5;
                    break;
#endif
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.RGHalf:
                    texImporterFormat = TextureImporterFormat.RGHalf;
                    break;
#endif
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.RGFloat:
                    texImporterFormat = TextureImporterFormat.RGFloat;
                    break;
#endif
#if UNITY_2018_3_OR_NEWER
                case TextureFormat.RHalf:
                    texImporterFormat = TextureImporterFormat.RHalf;
                    break;
#endif
                default:
                    texImporterFormat = TextureImporterFormat.ARGB32;
                    success = false;
                    Debug.LogError("No mapping for TextureFormat: " + texFormat + " to a TextureImporterFormat. ");
                    break;
            }

            return texImporterFormat;
        }
    }
}