Пример #1
0
    public BaseDialog OpenDialog(string dialogId)
    {
        GameObject dialogPrefab = null;
        BaseDialog dialog       = null;


        // Check if the dialog is opened
        if (_openedDialogs.TryGetValue(dialogId, out dialog))
        {
            // unhide/initialize dialog?

            return(dialog);
        }

        // First check the map to see if the mapping is cached
        if (!_dialogPrefabMap.TryGetValue(dialogId, out dialogPrefab))
        {
            // Check the list of dialog prefabs
            for (int i = 0, count = _dialogPrefabs.Count; i < count; i++)
            {
                dialog = _dialogPrefabs[i].GetComponent <BaseDialog>();
                if (dialog.GetDialogId() == dialogId)
                {
                    dialogPrefab = _dialogPrefabs[i];
                    _dialogPrefabMap.Add(dialogId, dialogPrefab);
                    break;
                }
            }
        }

        // Instantiate the prefab
        GameObject dialogGO = GameObject.Instantiate(dialogPrefab, Vector3.zero, Quaternion.identity) as GameObject;

        dialogGO.transform.SetParent(transform, false);
        dialog = dialogGO.GetComponent <BaseDialog>();

        // Initialize the dialog

        _openedDialogs.Add(dialogId, dialog);

        return(dialog);
    }