FindSceneObjectsOfType() public static method

public static FindSceneObjectsOfType ( Type type ) : Object[]
type Type
return Object[]
Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
    private static void PlaymodeStateChanged(PlayModeStateChange playModeStateChange)
#endif
    {
        if (!EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
        {
            if (Exists())
            {
#pragma warning disable 618
                OnlineMaps map = ((OnlineMaps[])Object.FindSceneObjectsOfType(typeof(OnlineMaps))).FirstOrDefault();
#pragma warning restore 618
                if (map != null)
                {
                    try
                    {
                        IOnlineMapsSavableComponent[] savableComponents = map.GetComponents <IOnlineMapsSavableComponent>();
                        OnlineMapsSavableItem[]       savableItems      = savableComponents.SelectMany(c => c.GetSavableItems()).ToArray();
                        if (savableItems.Length != 0)
                        {
                            string prefs = EditorPrefs.GetString(prefsKey);
                            OnlineMapsJSONObject json = OnlineMapsJSON.Parse(prefs) as OnlineMapsJSONObject;
                            foreach (KeyValuePair <string, OnlineMapsJSONItem> pair in json.table)
                            {
                                OnlineMapsSavableItem savableItem = savableItems.FirstOrDefault(s => s.name == pair.Key);
                                if (savableItem != null && savableItem.loadCallback != null)
                                {
                                    savableItem.loadCallback(pair.Value as OnlineMapsJSONObject);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogException(ex);
                        // ignored
                    }

                    EditorPrefs.DeleteKey(prefsKey);
                    EditorUtility.SetDirty(map);
                }
            }

            if (EditorPrefs.HasKey("OnlineMapsRefreshAssets"))
            {
                EditorPrefs.DeleteKey("OnlineMapsRefreshAssets");
                AssetDatabase.Refresh();
            }
        }
    }