Beispiel #1
0
 static NGDiagnostic()
 {
     if (NGDiagnostic.IsInDiagnostic() == true)
     {
         Utility.SafeDelayCall(() => EditorUtility.DisplayProgressBar(Constants.PackageTitle, "Diagnosing...", 6F / 7F));
         Utility.RegisterIntervalCallback(NGDiagnostic.PrepareResult, 100);
     }
 }
Beispiel #2
0
        public static void      DelayDiagnostic(Action callback)
        {
            if (NGDiagnostic.IsInDiagnostic() == false)
            {
                return;
            }

            NGDiagnostic.diagnosis.Push(callback);
        }
Beispiel #3
0
        public static void      Log(string group, string key, object content)
        {
            if (NGDiagnostic.IsInDiagnostic() == false)
            {
                return;
            }

            if (Conf.DebugMode == Conf.DebugState.Verbose)
            {
                Debug.Log("[" + group + "] " + key + "=" + content);
            }

            List <KeyValuePair <string, string> > logs;

            if (NGDiagnostic.logs.TryGetValue(group, out logs) == false)
            {
                logs = new List <KeyValuePair <string, string> >();
                NGDiagnostic.logs.Add(group, logs);
            }

            if (content == null)
            {
                logs.Add(new KeyValuePair <string, string>(key, "null"));
            }
            else
            {
                logs.Add(new KeyValuePair <string, string>(key, content.ToString()));
            }

            int totalLogs = 0;

            foreach (var l in NGDiagnostic.logs)
            {
                totalLogs += l.Value.Count;
            }

            EditorApplication.delayCall += () => EditorUtility.DisplayProgressBar(Constants.PackageTitle, "Diagnosing... (" + totalLogs + " / " + NGDiagnostic.logs.Count + ")", 6F / 7F);
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        private static void     PrepareResult()
        {
            if (NGDiagnostic.diagnosis.Count > 0)
            {
                if (HQ.Settings == null)
                {
                    --NGDiagnostic.forceEndDiagnosis;

                    if (NGDiagnostic.forceEndDiagnosis <= 0)
                    {
                        NGDiagnostic.diagnosis.Clear();
                    }
                    return;
                }

                try
                {
                    NGDiagnostic.diagnosis.Pop()();
                }
                catch (Exception ex)
                {
                    InternalNGDebug.LogException(ex);
                }
                return;
            }

            try
            {
                EditorUtility.ClearProgressBar();
                Utility.UnregisterIntervalCallback(NGDiagnostic.PrepareResult);
                File.Delete(Path.Combine(Path.GetTempPath(), "NGT_Diagnosing"));
            }
            catch (Exception ex)
            {
                InternalNGDebug.LogException(ex);
            }

            NGDiagnostic  window = EditorWindow.GetWindow <NGDiagnostic>(true, NGDiagnostic.Title, true);
            StringBuilder buffer = Utility.GetBuffer();

            GUI.FocusControl(null);
            foreach (var item in NGDiagnostic.logs)
            {
                buffer.AppendLine(item.Key);
                for (int i = 0; i < item.Value.Count; i++)
                {
                    buffer.Append(item.Value[i].Key);
                    buffer.Append("=");
                    buffer.AppendLine(item.Value[i].Value);
                }

                buffer.AppendLine();
            }

            if (buffer.Length > Environment.NewLine.Length << 1)
            {
                buffer.Length -= Environment.NewLine.Length << 1;
            }

            window.result = Utility.ReturnBuffer(buffer);
        }