static EditorUnityObjectUtility() { try { UnityTypeType = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.UnityType", true); UnityTypeType_FindTypeByNameCaseInsensitive = UnityTypeType.GetMethod("FindTypeByNameCaseInsensitive", BindingFlags.Static | BindingFlags.Public); UnityTypeType_persistentTypeID = UnityTypeType.GetProperty("persistentTypeID", BindingFlags.Instance | BindingFlags.Public); if (UnityTypeType_FindTypeByNameCaseInsensitive == null) { throw new MissingMemberException(UnityTypeType.ToString(), "FindTypeByNameCaseInsensitive"); } if (UnityTypeType_persistentTypeID == null) { throw new MissingMemberException(UnityTypeType.ToString(), "persistentTypeID"); } #if !UNITY_2019_1_OR_NEWER EditorUtility_IsDirty = typeof(EditorUtility).GetMethod("IsDirty", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { typeof(int) }, null); if (EditorUtility_IsDirty == null) { throw new MissingMemberException(typeof(EditorUtility).ToString(), "IsDirty"); } #endif } catch (Exception ex) { throw new UnityEditorInternalException(ex); } }
static EditorUnityObjectUtility() { try { UnityTypeType = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.UnityType", true); UnityTypeType_FindTypeByNameCaseInsensitive = UnityTypeType.GetMethod("FindTypeByNameCaseInsensitive", BindingFlags.Static | BindingFlags.Public); UnityTypeType_persistentTypeID = UnityTypeType.GetProperty("persistentTypeID", BindingFlags.Instance | BindingFlags.Public); if (UnityTypeType_FindTypeByNameCaseInsensitive == null) { throw new MissingMemberException(UnityTypeType.ToString(), "FindTypeByNameCaseInsensitive"); } if (UnityTypeType_persistentTypeID == null) { throw new MissingMemberException(UnityTypeType.ToString(), "persistentTypeID"); } #if UNITY_2018_3_OR_NEWER { // GetMethod doesn't work with generic methods... var PrefabUtility_GetCorrespondingObjectFromSource_Candidates = typeof(PrefabUtility).GetMember("GetCorrespondingObjectFromSource", BindingFlags.Public | BindingFlags.Static); if (PrefabUtility_GetCorrespondingObjectFromSource_Candidates.Length > 0) { PrefabUtility_GetCorrespondingObjectFromSource = ((MethodInfo)PrefabUtility_GetCorrespondingObjectFromSource_Candidates[0]).MakeGenericMethod(typeof(UnityObject)); } PrefabUtility_GetPrefabInstanceHandle = typeof(PrefabUtility).GetMethod("GetPrefabInstanceHandle", BindingFlags.Public | BindingFlags.Static); PrefabUtility_IsPartOfPrefabAsset = typeof(PrefabUtility).GetMethod("IsPartOfPrefabAsset", BindingFlags.Public | BindingFlags.Static); PrefabUtility_IsPartOfPrefabInstance = typeof(PrefabUtility).GetMethod("IsPartOfPrefabInstance", BindingFlags.Public | BindingFlags.Static); PrefabUtility_IsDisconnectedFromPrefabAsset = typeof(PrefabUtility).GetMethod("IsDisconnectedFromPrefabAsset", BindingFlags.Public | BindingFlags.Static); if (PrefabUtility_GetCorrespondingObjectFromSource == null) { throw new MissingMemberException(typeof(PrefabUtility).ToString(), "GetCorrespondingObjectFromSource"); } if (PrefabUtility_GetPrefabInstanceHandle == null) { throw new MissingMemberException(typeof(PrefabUtility).ToString(), "GetPrefabInstanceHandle"); } if (PrefabUtility_IsPartOfPrefabAsset == null) { throw new MissingMemberException(typeof(PrefabUtility).ToString(), "IsPartOfPrefabAsset"); } if (PrefabUtility_IsPartOfPrefabInstance == null) { throw new MissingMemberException(typeof(PrefabUtility).ToString(), "IsPartOfPrefabInstance"); } if (PrefabUtility_IsDisconnectedFromPrefabAsset == null) { throw new MissingMemberException(typeof(PrefabUtility).ToString(), "IsDisconnectedFromPrefabAsset"); } PrefabStageUtilityType = #if UNITY_2021_2_OR_NEWER Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.SceneManagement.PrefabStageUtility", false) ?? #endif Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.Experimental.SceneManagement.PrefabStageUtility", true); PrefabStageUtility_GetPrefabStage = PrefabStageUtilityType.GetMethod("GetPrefabStage", BindingFlags.Public | BindingFlags.Static); if (PrefabStageUtility_GetPrefabStage == null) { throw new MissingMemberException(PrefabStageUtilityType.ToString(), "GetPrefabStage"); } } #endif } catch (Exception ex) { throw new UnityEditorInternalException(ex); } }