コード例 #1
0
ファイル: DialogFrame.cs プロジェクト: ToucanGamesLLC/uiStack
    public BaseDialog TryInstantiateDialogContent(BaseDialog _baseDialogPrefa)
    {
        if (dialogContent == null)
        {
            if (_baseDialogPrefa != null)
            {
                dialogContent = GameObjectHelper.AddChildrenWithComponent <BaseDialog>(
                    _baseDialogPrefa,
                    dialogPanel
                    );

                if (dialogContent != null)
                {
                    RectTransform rectTransform = GetComponent <RectTransform>();

                    if (rectTransform != null)
                    {
                        rectTransform.offsetMax =
                            new Vector2(-dialogContent.rightOffset, -dialogContent.topOffset);

                        rectTransform.offsetMin =
                            new Vector2(dialogContent.leftOffset, dialogContent.bottomOffset);
                    }

                    dialogContent.dialogFrame = this;
                }
            }
            else
            {
                LogHelper.LogWarning("Failed to set base dialog; "
                                     + nameof(_baseDialogPrefa)
                                     + " is not set",
                                     this
                                     );
            }
        }
        else
        {
            LogHelper.LogWarning("Failed to set "
                                 + nameof(dialogContent)
                                 + "; already exists",
                                 this
                                 );
        }

        return(dialogContent);
    }
コード例 #2
0
    private T LoadDialog <T>(string _dialogName = null) where T : BaseDialog
    {
        T result = null;

        if (dialogCanvas != null)
        {
            _dialogName = (!string.IsNullOrEmpty(_dialogName))
                                ? _dialogName
                                : typeof(T).Name;

            if (!string.IsNullOrEmpty(_dialogName))
            {
                GameObject baseDialogPrefab =
                    PrefabManager.Instance.LoadPrefab(typeof(T).Name);

                T dialogPrefab = (baseDialogPrefab != null)
                                        ? baseDialogPrefab.GetComponent <T>()
                                        : null;

                if (dialogPrefab != null)
                {
                    if (dialogPrefab.dialogFramePrefab != null)
                    {
                        DialogFrame dialoFrame =
                            GameObjectHelper.AddChildrenWithComponent <DialogFrame>(
                                dialogPrefab.dialogFramePrefab,
                                dialogCanvas.transform
                                );

                        if (dialoFrame != null)
                        {
                            result = dialoFrame.TryInstantiateDialogContent(dialogPrefab) as T;

                            if (result == null)
                            {
                                LogHelper.LogError(
                                    "Failed to instantiate dialog content for "
                                    + _dialogName,
                                    this
                                    );

                                GameObjectHelper.Destroy(result.gameObject, true);
                            }
                        }
                    }
                    else
                    {
                        LogHelper.LogWarning("Failed to load "
                                             + typeof(T).Name
                                             + "; missing "
                                             + nameof(dialogPrefab.dialogFramePrefab),
                                             this
                                             );
                    }
                }
            }
        }
        else
        {
            LogHelper.LogError("Failed to load dialog; "
                               + nameof(dialogCanvas)
                               + " is not set",
                               this
                               );
        }

        return(result);
    }