Пример #1
0
        public void CheckMissingComponentOnPrefabs()
        {
            List <string> listResult = new List <string>();

            string[] allPrefabs = SearchAndDestroy.GetAllPrefabs();
            foreach (string prefab in allPrefabs)
            {
                Object o = AssetDatabase.LoadMainAssetAtPath(prefab);

                // Check if it's gameobject
                if (!(o is GameObject))
                {
                    Logger.LogFormat("For some reason, prefab {0} won't cast to GameObject", Category.Tests, prefab);
                    continue;
                }

                var         go         = (GameObject)o;
                Component[] components = go.GetComponentsInChildren <Component>(true);
                foreach (Component c in components)
                {
                    if (c == null)
                    {
                        listResult.Add(prefab);
                    }
                }
            }

            foreach (string s in listResult)
            {
                Logger.LogFormat("Missing reference found in prefab {0}", Category.Tests, s);
            }

            Assert.IsEmpty(listResult, "Missing references found: {0}", string.Join(", ", listResult));
        }
Пример #2
0
    private static void Init()
    {
        SearchAndDestroy window = (SearchAndDestroy)GetWindow(typeof(SearchAndDestroy));

        window.Show();
        window.position = new Rect(50, 100, 600, 600);
    }
Пример #3
0
        public void TestAllChannelsTag()
        {
            List <string> listResult = new List <string>();

            string[] allPrefabs = SearchAndDestroy.GetAllPrefabs();
            foreach (string prefab in allPrefabs)
            {
                Object     o = AssetDatabase.LoadMainAssetAtPath(prefab);
                GameObject go;
                try
                {
                    go = (GameObject)o;
                    Component[] components = go.GetComponentsInChildren <Component>(true);
                    foreach (Component c in components)
                    {
                        if (c == null)
                        {
                            listResult.Add(prefab);
                        }
                    }
                }
                catch
                {
                    Logger.LogFormat("For some reason, prefab {0} won't cast to GameObject", Category.UI, prefab);
                }
            }

            foreach (string s in listResult)
            {
                Debug.LogFormat("Missing reference found in prefab {0}", s);
            }

            Assert.IsEmpty(listResult, "Missing references found: {0}", string.Join(", ", listResult));
        }
Пример #4
0
        public void CheckMissingReferenceFieldsOnPrefabs()
        {
            // GameObject name - Component Name - Field Nme
            var listResult = new List <(string, string, string)>();

            string[] allPrefabs = SearchAndDestroy.GetAllPrefabs();
            foreach (string prefab in allPrefabs)
            {
                Object o = AssetDatabase.LoadMainAssetAtPath(prefab);

                // Check if it's gameobject
                if (!(o is GameObject))
                {
                    Logger.LogFormat("For some reason, prefab {0} won't cast to GameObject", Category.Tests, prefab);
                    continue;
                }

                var         go         = (GameObject)o;
                Component[] components = go.GetComponentsInChildren <Component>(true);
                foreach (Component c in components)
                {
                    if (c == null)
                    {
                        continue;
                    }

                    SerializedObject so = new SerializedObject(c);
                    var sp = so.GetIterator();

                    while (sp.NextVisible(true))
                    {
                        if (sp.propertyType == SerializedPropertyType.ObjectReference)
                        {
                            if (sp.objectReferenceValue == null &&
                                sp.objectReferenceInstanceIDValue != 0)
                            {
                                listResult.Add((go.name, c.name, sp.displayName));
                            }
                        }
                    }
                }
            }

            var report = new StringBuilder();

            foreach (var s in listResult)
            {
                var msg = $"Missing reference found in prefab {s.Item1} component {s.Item2} field {s.Item3}";
                Logger.Log(msg, Category.Tests);
                report.AppendLine(msg);
            }

            Assert.IsEmpty(listResult, report.ToString());
        }
Пример #5
0
        public void SpriteHandlerTest()
        {
            var report = new StringBuilder();
            var failed = false;

            string[] allPrefabs = SearchAndDestroy.GetAllPrefabs();
            foreach (string prefab in allPrefabs)
            {
                Object o = AssetDatabase.LoadMainAssetAtPath(prefab);

                // Check if it's gameobject
                if (!(o is GameObject))
                {
                    Logger.LogFormat("For some reason, prefab {0} won't cast to GameObject", Category.Tests, prefab);
                    continue;
                }

                var gameObject = o as GameObject;

                foreach (Transform child in gameObject.transform)
                {
                    if (child.TryGetComponent <SpriteRenderer>(out var spriteRenderer) == false)
                    {
                        continue;
                    }
                    if (child.TryGetComponent <SpriteHandler>(out var spriteHandler) == false)
                    {
                        continue;
                    }

                    if (spriteRenderer.sprite != null && spriteHandler.PresentSpritesSet == null)
                    {
                        report.AppendLine($"{gameObject.name} has a null spriteHandler PresentSpriteSet but a not null spriteRender sprite on {child.name}," +
                                          $" this will lead to an invisible object! Set the PresentSpriteSet on the spriteHandler or remove the spriteRender sprite.");
                        failed = true;
                    }
                }
            }

            if (failed)
            {
                Assert.Fail(report.ToString());
            }
        }