Beispiel #1
0
        protected override void OnDraw()
        {
            DrawDefaultInspector();
            //In play mode, inspector is refreshed every frame. To prevent performance drop, only do this
            //while not in play mode.
            if (!EditorApplication.isPlaying)
            {
                ScopeSet      scopes = new ScopeSet();
                List <string> unscopedDependencies = new List <string>();

                foreach (MethodInfo method in target.GetType().GetMethods(BindingFlags.Public |
                                                                          BindingFlags.NonPublic |
                                                                          BindingFlags.Instance))
                {
                    if (method.Name.ToLower().StartsWith("inject") && method.Name != "InjectDependencies")
                    {
                        foreach (ParameterInfo parameter in method.GetParameters())
                        {
                            Scope scope = GetScopeName(parameter);

                            if (scope != null)
                            {
                                bool isResolved;
                                try
                                {
                                    isResolved = scope.GetDependencies(gameScript, parameter.ParameterType).Count > 0;
                                }
                                catch (Exception)
                                {
                                    isResolved = false;
                                }
                                scopes[scope.GetType().Name].Add(parameter.ParameterType.Name, isResolved);
                            }
                            else
                            {
                                unscopedDependencies.Add(parameter.ParameterType.Name);
                            }
                        }
                    }
                }

                if (unscopedDependencies.Count > 0)
                {
                    string unscopedDependenciesText = "Unscoped Dependencies : \n";
                    foreach (string dependency in unscopedDependencies)
                    {
                        unscopedDependenciesText += "\n ● " + dependency;
                    }
                    DrawErrorBox(unscopedDependenciesText);
                }

                if (!scopes.IsEmpty())
                {
                    BeginTable("Dependencies");
                    foreach (DependencySet scope in scopes)
                    {
                        BeginTableRow();
                        DrawTableHeader(scope.Name);
                        foreach (Dependency dependency in scope)
                        {
                            if (dependency.IsResolved)
                            {
                                DrawTableCell("✓" + dependency.Name, new Color(0.05f, 0.5F, 0.05f));
                            }
                            else
                            {
                                DrawTableCell("✗" + dependency.Name, Color.red);
                            }
                        }
                        EndTableRow();
                    }
                    EndTable();
                }
            }
        }
Beispiel #2
0
        private void DrawDependencyReport()
        {
            ScopeSet      scopes = new ScopeSet();
            List <string> unscopedDependencies = new List <string>();

            foreach (MethodInfo method in target.GetType().GetMethods(BindingFlags.Public |
                                                                      BindingFlags.NonPublic |
                                                                      BindingFlags.Instance))
            {
                if (method.Name.ToLower().StartsWith("inject") && method.Name != "InjectDependencies")
                {
                    foreach (ParameterInfo parameter in method.GetParameters())
                    {
                        Scope scope = GetScopeName(parameter);

                        if (scope != null)
                        {
                            bool isResolved;
                            try
                            {
                                isResolved = scope.GetDependencies(script, parameter.ParameterType).Count > 0;
                            }
                            catch (Exception)
                            {
                                isResolved = false;
                            }
                            scopes[scope.GetType().Name].Add(parameter.ParameterType.Name, isResolved);
                        }
                        else
                        {
                            unscopedDependencies.Add(parameter.ParameterType.Name);
                        }
                    }
                }
            }

            if (unscopedDependencies.Count > 0)
            {
                string unscopedDependenciesText = "Unscoped Dependencies : \n";
                foreach (string dependency in unscopedDependencies)
                {
                    unscopedDependenciesText += "\n ● " + dependency;
                }
                DrawErrorBox(unscopedDependenciesText);
            }

            if (!scopes.IsEmpty())
            {
                BeginTable();
                foreach (DependencySet scope in scopes)
                {
                    BeginTableRow();
                    DrawTableHeader(scope.Name);
                    foreach (Dependency dependency in scope)
                    {
                        if (dependency.IsResolved)
                        {
                            DrawTableCell("✓" + dependency.Name, new Color(0.05f, 0.5F, 0.05f));
                        }
                        else
                        {
                            DrawTableCell("✗" + dependency.Name, Color.red);
                        }
                    }
                    EndTableRow();
                }
                EndTable();
            }
        }