Пример #1
0
        public void Crawl_Pass()
        {
            GameObject[] objs = new GameObject[2];
            for (int i = 0; i < 2; i++)
            {
                objs[i] = new GameObject();
                objs[i].AddComponent <Text>();
            }

            SceneCrawler crawler = new SceneCrawler();

            CrawlParameters <Text> crawlParameters = new CrawlParameters <Text>();

            crawlParameters.SceneList      = new [] { EditorSceneManager.GetActiveScene().name };
            crawlParameters.OnCrawlingEnd += delegate(CrawlResult <Text> result)
            {
                Assert.AreEqual(2, result.Components.Length);
            };

            crawler.Crawl(crawlParameters);

            for (int i = 0; i < 2; i++)
            {
                GameObject.DestroyImmediate(objs[i]);
            }
        }
Пример #2
0
        public void CrawlTestForDeactivatedObjects_Pass()
        {
            int objectCount = 3;

            GameObject[] objs = new GameObject[objectCount];
            for (int i = 0; i < objectCount; i++)
            {
                objs[i] = new GameObject();
                objs[i].AddComponent <Text>();
            }
            objs[objectCount - 1].SetActive(false);

            SceneCrawler crawler = new SceneCrawler();

            CrawlParameters <Text> crawlParameters = new CrawlParameters <Text>();

            crawlParameters.SceneList      = new[] { EditorSceneManager.GetActiveScene().name };
            crawlParameters.OnCrawlingEnd += delegate(CrawlResult <Text> result)
            {
                Assert.AreEqual(3, result.Components.Length);
            };

            crawler.Crawl(crawlParameters);

            for (int i = 0; i < objectCount; i++)
            {
                GameObject.DestroyImmediate(objs[i]);
            }
        }
Пример #3
0
        public void Crawl <ComponentTypeToCrawl>(CrawlParameters <ComponentTypeToCrawl> crawlParameters)
            where ComponentTypeToCrawl : Component
        {
            EditorSceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
            {
                ComponentTypeToCrawl[] components =
                    Object.FindSceneObjectsOfType(crawlParameters.ComponentType) as ComponentTypeToCrawl[];

                CrawlResult <ComponentTypeToCrawl> result =
                    new CrawlResult <ComponentTypeToCrawl>(components);

                if (crawlParameters.OnCrawlingEnd != null)
                {
                    crawlParameters.OnCrawlingEnd(result);
                }
            };

            foreach (string sceneName in crawlParameters.SceneList)
            {
                if (!EditorSceneManager.GetActiveScene().name.Equals(sceneName))
                {
                    EditorSceneManager.LoadScene(sceneName);
                }
            }
        }