Exemple #1
0
        /// <summary>
        /// Loads neighbor scenes within maxNeighborDistance, adding them to the near list.
        /// </summary>
        /// <param name="sceneName">Scene name.</param>
        /// <param name="distance">Distance.</param>
        private void LoadNeighbors(string sceneName, int distance)
        {
            if (m_near.Contains(sceneName))
            {
                return;
            }
            m_near.Add(sceneName);
            if (distance >= maxNeighborDistance)
            {
                return;
            }
            GameObject        scene             = GameObject.Find(sceneName);
            NeighboringScenes neighboringScenes = (scene) ? scene.GetComponent <NeighboringScenes>() : null;

            if (!neighboringScenes)
            {
                neighboringScenes = CreateNeighboringScenesList(scene);
            }
            if (!neighboringScenes)
            {
                return;
            }
            for (int i = 0; i < neighboringScenes.sceneNames.Length; i++)
            {
                Load(neighboringScenes.sceneNames[i], LoadNeighbors, distance + 1);
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates the neighboring scenes list. It's faster to manually add a
        /// NeighboringScenes script to your scene's root object; this method
        /// builds it manually if it's missing, but requires the scene to have
        /// SceneEdge components.
        /// </summary>
        /// <returns>The neighboring scenes list.</returns>
        /// <param name="scene">Scene.</param>
        private NeighboringScenes CreateNeighboringScenesList(GameObject scene)
        {
            if (!scene)
            {
                return(null);
            }
            NeighboringScenes neighboringScenes = scene.AddComponent <NeighboringScenes>();
            HashSet <string>  neighbors         = new HashSet <string>();
            var sceneEdges = scene.GetComponentsInChildren <SceneEdge>();

            for (int i = 0; i < sceneEdges.Length; i++)
            {
                neighbors.Add(sceneEdges[i].nextSceneName);
            }
            neighboringScenes.sceneNames = new string[neighbors.Count];
            neighbors.CopyTo(neighboringScenes.sceneNames);
            return(neighboringScenes);
        }