UIScreenBase LoadScreen(UIScreenType screenType)
        {
            string fileName;

            m_prefabFiles.TryGetValue(screenType, out fileName);
            if (fileName == null)
            {
                Debug.LogError("Attempting to load screen '" + screenType.ToString() + "' which does not exist in UIManagerData!");
                return(null);
            }

            UIScreenBase prefab = Resources.Load <UIScreenBase>(fileName);

            if (prefab == null)
            {
                Debug.LogError("Could not load the ui prefab file: " + fileName);
                return(null);
            }

            UIScreenBase screen = GameObject.Instantiate(prefab) as UIScreenBase;

            GameObject go = screen.gameObject;

            go.transform.SetParent(gameObject.transform);
            go.SetActive(true);

            return(screen);
        }
示例#2
0
    public void ShowScreen(UIScreenType _screen)
    {
        if (currentScreen != _screen)
        {
            if (!allScreens.ContainsKey(_screen))
            {
                Debug.LogError("UI Screen missing  :: " + _screen.ToString());
                return;
            }
            if (allScreens.ContainsKey(currentScreen))
            {
                allScreens[currentScreen].SetActive(false);
            }

            currentScreen = _screen;

            allScreens[currentScreen].SetActive(true);
        }
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="screenToLoad"></param>
    /// <returns>True if the screen is loaded, false otherwise.</returns>
    public bool LoadScreen(UIScreenType screenToLoad)
    {
        UIScreen screen = null;

        if (GetScreen(screenToLoad, out screen))
        {
            return(true);
        }

        screen = Instantiate(Resources.Load <GameObject>("Prefabs/UI/screen_" + screenToLoad.ToString())).GetComponent <UIScreen>( );
        if (screen == null)
        {
            return(false);
        }

        screen.gameObject.SetActive(false);
        screen.transform.parent        = transform;
        screen.screenRect.sizeDelta    = Vector2.zero;
        screen.transform.localScale    = Vector3.one;
        screen.transform.localPosition = Vector3.zero;

        _loadedScreens.Add(screen);
        return(true);
    }