protected virtual void OnEnable() { Utility.LoadEditorPref(this); if (string.IsNullOrEmpty(this.contactName) == true || string.IsNullOrEmpty(this.contactEMail) == true) { try { Type UnityConnect = UnityAssemblyVerifier.TryGetType(typeof(Editor).Assembly, "UnityEditor.Connect.UnityConnect"); FieldInfo s_Instance = UnityAssemblyVerifier.TryGetField(UnityConnect, "s_Instance", BindingFlags.Static | BindingFlags.NonPublic); PropertyInfo userInfo = UnityAssemblyVerifier.TryGetProperty(UnityConnect, "userInfo", BindingFlags.Instance | BindingFlags.Public); //PropertyInfo projectInfo = UnityAssemblyVerifier.TryGetProperty(UnityConnect, "projectInfo", BindingFlags.Instance | BindingFlags.Public); //PropertyInfo connectInfo = UnityAssemblyVerifier.TryGetProperty(UnityConnect, "connectInfo", BindingFlags.Instance | BindingFlags.Public); object UnityConnectInstance = s_Instance.GetValue(null); object ui = userInfo.GetValue(UnityConnectInstance, null); Type UserInfo = UnityAssemblyVerifier.TryGetType(typeof(Editor).Assembly, "UnityEditor.Connect.UserInfo"); //NGDebug.Snapshot(UnityConnectInstance); //NGDebug.Snapshot(ui); //NGDebug.Snapshot(projectInfo.GetValue(UnityConnectInstance, null)); //NGDebug.Snapshot(connectInfo.GetValue(UnityConnectInstance, null)); if (string.IsNullOrEmpty(this.contactName) == true) { FieldInfo displayName = UnityAssemblyVerifier.TryGetField(UserInfo, "m_DisplayName", BindingFlags.Instance | BindingFlags.NonPublic); this.contactName = displayName.GetValue(ui) as string; } if (string.IsNullOrEmpty(this.contactEMail) == true) { FieldInfo m_UserName = UnityAssemblyVerifier.TryGetField(UserInfo, "m_UserName", BindingFlags.Instance | BindingFlags.NonPublic); this.contactEMail = m_UserName.GetValue(ui) as string; } } catch { } } }
static RootGameObjectsManager() { // TODO Unity <5.6 backward compatibility? MethodInfo ResetRootObjectsMethod = typeof(RootGameObjectsManager).GetMethod("ResetRootObjects", BindingFlags.Static | BindingFlags.NonPublic); try { EventInfo hierarchyChangedEvent = typeof(EditorApplication).GetEvent("hierarchyChanged"); hierarchyChangedEvent.AddEventHandler(null, Delegate.CreateDelegate(hierarchyChangedEvent.EventHandlerType, null, ResetRootObjectsMethod)); //EditorApplication.hierarchyChanged += RootGameObjectsManager.ResetRootObjects; } catch { FieldInfo hierarchyWindowChangedField = UnityAssemblyVerifier.TryGetField(typeof(EditorApplication), "hierarchyWindowChanged", BindingFlags.Static | BindingFlags.Public); if (hierarchyWindowChangedField != null) { hierarchyWindowChangedField.SetValue(null, Delegate.Combine((Delegate)hierarchyWindowChangedField.GetValue(null), Delegate.CreateDelegate(hierarchyWindowChangedField.FieldType, null, ResetRootObjectsMethod))); } //EditorApplication.hierarchyWindowChanged += RootGameObjectsManager.ResetRootObjects; } NGEditorApplication.ChangeScene += RootGameObjectsManager.ClearRootGameObjects; }
static HQ() { HQ.rootPath = Utility.GetPackagePath(); NGDiagnostic.Log(Preferences.Title, "RootPath", HQ.RootPath); if (HQ.RootPath == string.Empty) { InternalNGDebug.LogWarning(Constants.RootFolderName + " folder was not found."); return; } HQ.SettingsChanged += HQ.CheckSettingsVersion; string[] files = Directory.GetFiles(HQ.RootPath, HQ.NestedNGMenuItems, SearchOption.AllDirectories); if (files.Length == 1) { HQ.rootedMenuFilePath = files[0]; } NGLicensesManager.LicensesLoaded += () => { NGDiagnostic.Log(Preferences.Title, "AllowSendStats", NGEditorPrefs.GetBool(HQ.AllowSendStatsKeyPref, true)); if (NGEditorPrefs.GetBool(HQ.AllowSendStatsKeyPref, true) == true) { HQ.SendStats(); } }; NGLicensesManager.ActivationSucceeded += (invoice) => { string path = Path.Combine(Application.persistentDataPath, Path.Combine(Constants.InternalPackageTitle, "sendStats." + Utility.UnityVersion + "." + Constants.Version + ".txt")); if (File.Exists(path) == true) { File.Delete(path); } }; //Conf.DebugMode = (Conf.DebugState)EditorPrefs.GetInt(Conf.DebugModeKeyPref, (int)Conf.DebugMode); Utility.SafeDelayCall(() => { NGLicensesManager.Title = Constants.PackageTitle; NGLicensesManager.IntermediatePath = Constants.InternalPackageTitle; NGDiagnostic.Log(Preferences.Title, "LogPath", InternalNGDebug.LogPath); }); NGDiagnostic.Log(Preferences.Title, "DebugMode", Conf.DebugMode); // TODO Unity <5.6 backward compatibility? MethodInfo ResetAssetsMethod = typeof(HQ).GetMethod("ResetAssets", BindingFlags.Static | BindingFlags.NonPublic); try { EventInfo projectChangedEvent = typeof(EditorApplication).GetEvent("projectChanged"); projectChangedEvent.AddEventHandler(null, Delegate.CreateDelegate(projectChangedEvent.EventHandlerType, null, ResetAssetsMethod)); //EditorApplication.projectChanged += HQ.ResetAssets; } catch { FieldInfo projectWindowChangedField = UnityAssemblyVerifier.TryGetField(typeof(EditorApplication), "projectWindowChanged", BindingFlags.Static | BindingFlags.Public); if (projectWindowChangedField != null) { projectWindowChangedField.SetValue(null, Delegate.Combine((Delegate)projectWindowChangedField.GetValue(null), Delegate.CreateDelegate(projectWindowChangedField.FieldType, null, ResetAssetsMethod))); } //EditorApplication.projectWindowChanged += HQ.ResetAssets; } EditorApplication.projectWindowItemOnGUI += ProjectCopyAssets.OnProjectElementGUI; }