Ejemplo n.º 1
0
        public void InitializeFields()
        {
            this.AssertGetComponent <HDCanvas>(ref this.hdCanvas);
            this.AssertGetComponent <Canvas>(ref this.canvas);
            this.AssertGetComponent <Animator>(ref this.animator);
            this.AssertGetComponent <GraphicRaycaster>(ref this.graphicRaycaster);

            if (this.dialogStateMachine == null)
            {
                this.dialogStateMachine = this.animator.GetBehaviour <DialogStateMachine>();
            }

            if (this.contentRectTransform == null || this.contentRectTransform.gameObject.name != "Content")
            {
                Transform contentTransform = this.gameObject.transform.Find("Content");
                this.contentRectTransform = contentTransform != null?contentTransform.GetComponent <RectTransform>() : null;
            }

            if ((this.blocker == null || this.blocker.gameObject.name != "Blocker") && (this.blockInput || this.tapOutsideToDismiss))
            {
                GameObject blockerObject = this.gameObject.GetChild("Blocker");
                this.blocker = blockerObject != null?blockerObject.GetComponent <InputBlocker>() : null;
            }

            this.UpdateRenderMode();
        }
Ejemplo n.º 2
0
        protected virtual void Awake()
        {
            this.hdCanvas           = this.GetComponent <HDCanvas>();
            this.canvas             = this.GetComponent <Canvas>();
            this.animator           = this.GetComponent <Animator>();
            this.dialogStateMachine = this.animator.GetBehaviour <DialogStateMachine>();
            this.graphicRaycaster   = this.GetComponent <GraphicRaycaster>();

            // cleaning up the editor UI a little bit
            this.hdCanvas.hideFlags         = HideFlags.HideInInspector;
            this.graphicRaycaster.hideFlags = HideFlags.HideInInspector;

            // making sure the animator is set up properly
            Debug.AssertFormat(this.dialogStateMachine != null, this, "Dialog {0} doesn't have a DialogStateMachine behaviour attached.", this.gameObject.name);
            Debug.AssertFormat(this.animator.HasState(0, ShownHash), this, "Dialog {0} doesn't have a \"Shown\" state.", this.gameObject.name);
            Debug.AssertFormat(this.animator.HasState(0, HiddenHash), this, "Dialog {0} doesn't have a \"Hidden\" state.", this.gameObject.name);

            var showingParameter = this.animator.parameters.FirstOrDefault(x => x.nameHash == ShowHash);

            Debug.Assert(showingParameter != null, "Dialog doesn't have a \"Show\" Bool parameter.", this);

            // making sure the content object exists
            Transform contentTransform = this.gameObject.transform.FindChild("Content");

            Debug.Assert(contentTransform != null, "Dialog doesn't contain a Content child object.", this);

            this.contentRectTransform = contentTransform.GetComponent <RectTransform>();
            Debug.Assert(this.contentRectTransform != null, "Dialog's Content child object doesn't contain a RectTransform component.", this);

            // making sure the blocker object exists
            if (this.blockInput || this.tapOutsideToDismiss)
            {
                GameObject blockerObject = this.gameObject.GetOrCreateChild("Blocker", typeof(InputBlocker));
                this.blocker = blockerObject.GetComponent <InputBlocker>();
                this.blocker.gameObject.transform.SetAsFirstSibling();

                if (this.tapOutsideToDismiss)
                {
                    this.blocker.OnClick.AddListener(this.Hide);
                    this.contentRectTransform.gameObject.AddComponent <GraphicRaycaster>();
                }
            }

            // default everything to inactive and wait for someone to call Show()
            this.SetActive(false);
        }