private static void InitSceneWidgets(CaseSceneType sceneType, GridLayoutGroup sceneGrid, SceneData[] sceneDataArray, GameObject sceneButtonPrefab)
    {
        // First, create enough scene widgets for the current case
        // there may already be one or more scene widgets under sceneGrid to visualize better
        // in the editor, so only add what you need.
        // We assume all children of sceneGrid are actually scene widgets, so just count them.
        // If you open the Scenes page for the second time in this mission, nothing should be added.
        int currentSceneButtonsCount = sceneGrid.transform.childCount;


        for (int i = currentSceneButtonsCount; i < sceneDataArray.Length; i++)
        {
            Instantiate(sceneButtonPrefab, sceneGrid.transform);
        }

        // Second, disable any extra widgets (e.g. created from a previous case that had more scenes than the current one)
        for (int i = sceneDataArray.Length; i < currentSceneButtonsCount; i++)
        {
            sceneGrid.transform.GetChild(i).gameObject.SetActive(false);
        }

        // Third, setup the scene widgets for each available scene
        for (int i = 0; i < sceneDataArray.Length; i++)
        {
            // get widget script
            Transform sceneWidgetTr = sceneGrid.transform.GetChild(i);
            Debug.AssertFormat(sceneWidgetTr != null, sceneGrid,
                               "Scene widget grid {0} has no child of index {1}, yet we should have created up to {2} widgets " +
                               "after the existing {3}.", sceneGrid, i, sceneDataArray.Length, currentSceneButtonsCount);
            var widget = sceneWidgetTr.GetComponentOrFail <CaseFileSceneWidget>();

            // get scene data
            SceneData sceneData = sceneDataArray[i];

            // check if scene is unlocked
            bool isSceneUnlocked = sceneData.unlockedOnStart || CaseManager.Instance.CurrentCaseProgress.HasUnlockedScene(sceneType, sceneData.sceneEnum);

            // init scene button widget
            widget.Init(sceneData, isSceneUnlocked);
        }
    }
Ejemplo n.º 2
0
 public void UnlockScene(CaseSceneType sceneType, ScenesEnum sceneEnum)
 {
     m_UnlockedSceneEnumsSetBySceneType[(int)sceneType].Add(sceneEnum);
     Debug.LogFormat("Unlock scene: type {0}, enum {1}", sceneType, sceneEnum);
 }
Ejemplo n.º 3
0
 public bool HasUnlockedScene(CaseSceneType sceneType, ScenesEnum sceneEnum)
 {
     return(m_UnlockedSceneEnumsSetBySceneType[(int)sceneType].Contains(sceneEnum));
 }