コード例 #1
0
    SceneNeighbours CreateSceneNeighbours(GameObject scene)
    {
        if (!scene)
        {
            return(null);
        }
        SceneNeighbours  sceneNeighbours = scene.AddComponent <SceneNeighbours>();
        HashSet <string> neighbours      = new HashSet <string>();

        SceneTrigger[] triggers = scene.GetComponentsInChildren <SceneTrigger>();
        foreach (SceneTrigger t in triggers)
        {
            neighbours.Add(t.nextSceneName);
        }
        sceneNeighbours.sceneNames = new string[neighbours.Count];
        neighbours.CopyTo(sceneNeighbours.sceneNames);
        return(sceneNeighbours);
    }
コード例 #2
0
    void LoadNeighbours(string sceneName, int depth)
    {
        // scene already addded? return
        if (nearScenes.Contains(sceneName))
        {
            return;
        }
        // add scene to near
        nearScenes.Add(sceneName);
        // at max depth? return
        if (depth >= neighbourLoadDepth)
        {
            return;
        }
        // get sceneRoot and its neighbouring scenes
        GameObject      scene      = GameObject.Find(sceneName);
        SceneNeighbours neighbours = (scene ? scene.GetComponent <SceneNeighbours>() : null);

        // if neighbours are null, build the list
        if (!neighbours)
        {
            neighbours = CreateSceneNeighbours(scene);
        }
        // if still null, return
        if (!neighbours)
        {
            return;
        }
        for (int i = 0; i < neighbours.sceneNames.Length; i++)
        {
            if (!IsLoading(neighbours.sceneNames[i]))
            {
                Load(neighbours.sceneNames[i], LoadNeighbours, depth + 1);
            }
        }
    }