summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Editor/SDK3Compatibility/VRCSdk3Analysis.cs
blob: ee656b385860dea778c8df90c1513a0e3fc7bd1c (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
using System.Reflection;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using UnityEditor;

public class VRCSdk3Analysis
{
    static Assembly GetAssemblyByName(string name)
    {
        return AppDomain.CurrentDomain.GetAssemblies().
               SingleOrDefault(assembly => assembly.GetName().Name == name);
    }

    static List<Component> GetSceneComponentsFromAssembly( Assembly assembly )
    {
        if (assembly == null)
            return new List<Component>();

        Type[] types = assembly.GetTypes();

        List<Component> present = new List<Component>();
        foreach (var type in types )
        {
            if (!type.IsSubclassOf(typeof(MonoBehaviour)))
                continue;

            var monos = VRC.Tools.FindSceneObjectsOfTypeAll(type);
            present.AddRange(monos);
        }
        return present;
    }

    public enum SdkVersion
    {
        VRCSDK2,
        VRCSDK3
    };

    public static List<Component> GetSDKInScene(SdkVersion version)
    {
        var assembly = GetAssemblyByName( version.ToString() );
        return GetSceneComponentsFromAssembly(assembly);
    }

    public static bool IsSdkDllActive(SdkVersion version)
    {
        string assembly = version.ToString();
        PluginImporter importer = GetImporterForAssemblyString(assembly);
        if (importer == false)
        {
            //Handle Avatar Dll Split
            importer = GetImporterForAssemblyString(assembly + "A");
            if (importer == false)
                return false;
        }

        return importer.GetCompatibleWithAnyPlatform();
    }

    public static PluginImporter GetImporterForAssemblyString(string assembly)
    {
#if VRCUPM
        return AssetImporter.GetAtPath($"Packages/com.vrchat.{assembly.ToLower()}/Runtime/VRCSDK/Plugins/{assembly}.dll") as PluginImporter;
#else
        return AssetImporter.GetAtPath($"Assets/VRCSDK/Plugins/{assembly}.dll") as PluginImporter;
#endif
    }
}