コード例 #1
0
        private void SetResponseButton(UnityUIResponseButton button, Response response, Transform target, int buttonNumber)
        {
            if (button != null)
            {
                button.visible   = true;
                button.clickable = response.enabled;
                button.target    = target;
                if (response != null)
                {
                    button.SetFormattedText(response.formattedText);
                }
                button.response = response;

                // Auto-number:
                if (autonumber.enabled)
                {
                    button.Text = string.Format(autonumber.format, buttonNumber + 1, button.Text);
                    var keyTrigger = button.GetComponent <UIButtonKeyTrigger>();
                    if (keyTrigger == null)
                    {
                        keyTrigger = button.gameObject.AddComponent <UIButtonKeyTrigger>();
                    }
                    keyTrigger.key = (KeyCode)((int)KeyCode.Alpha1 + buttonNumber);
                }
            }
        }
コード例 #2
0
 private void SetResponseButton(UnityUIResponseButton button, Response response, Transform target)
 {
     if (button != null)
     {
         button.visible   = true;
         button.clickable = true;
         button.target    = target;
         if (response != null)
         {
             button.SetFormattedText(response.formattedText);
         }
         button.response = response;
     }
 }
コード例 #3
0
        /// <summary>
        /// Sets the response buttons.
        /// </summary>
        /// <param name='responses'>
        /// Responses.
        /// </param>
        /// <param name='target'>
        /// Target that will receive OnClick events from the buttons.
        /// </param>
        protected override void SetResponseButtons(Response[] responses, Transform target)
        {
            DestroyInstantiatedButtons();

            if ((buttons != null) && (responses != null))
            {
                int buttonNumber = 0;

                // Add explicitly-positioned buttons:
                for (int i = 0; i < responses.Length; i++)
                {
                    if (responses[i].formattedText.position != FormattedText.NoAssignedPosition)
                    {
                        int position = Mathf.Clamp(responses[i].formattedText.position, 0, buttons.Length - 1);
                        SetResponseButton(buttons[position], responses[i], target, buttonNumber++);
                    }
                }

                if ((buttonTemplate != null) && (buttonTemplateHolder != null))
                {
                    // Reset scrollbar to top:
                    if (buttonTemplateScrollbar != null)
                    {
                        buttonTemplateScrollbar.value = buttonTemplateScrollbarResetValue;
                    }

                    // Instantiate buttons from template:
                    for (int i = 0; i < responses.Length; i++)
                    {
                        GameObject buttonGameObject = GameObject.Instantiate(buttonTemplate.gameObject) as GameObject;
                        if (buttonGameObject == null)
                        {
                            Debug.LogError(string.Format("{0}: Couldn't instantiate response button template", DialogueDebug.Prefix));
                        }
                        else
                        {
                            instantiatedButtons.Add(buttonGameObject);
                            buttonGameObject.transform.SetParent(buttonTemplateHolder.transform, false);
                            buttonGameObject.SetActive(true);
                            UnityUIResponseButton responseButton = buttonGameObject.GetComponent <UnityUIResponseButton>();
                            SetResponseButton(responseButton, responses[i], target, buttonNumber++);
                        }
                    }
                }
                else
                {
                    // Auto-position remaining buttons:
                    if (buttonAlignment == ResponseButtonAlignment.ToFirst)
                    {
                        // Align to first, so add in order to front:
                        for (int i = 0; i < Mathf.Min(buttons.Length, responses.Length); i++)
                        {
                            if (responses[i].formattedText.position == FormattedText.NoAssignedPosition)
                            {
                                int position = Mathf.Clamp(GetNextAvailableResponseButtonPosition(0, 1), 0, buttons.Length - 1);
                                SetResponseButton(buttons[position], responses[i], target, buttonNumber++);
                            }
                        }
                    }
                    else
                    {
                        // Align to last, so add in reverse order to back:
                        for (int i = Mathf.Min(buttons.Length, responses.Length) - 1; i >= 0; i--)
                        {
                            if (responses[i].formattedText.position == FormattedText.NoAssignedPosition)
                            {
                                int position = Mathf.Clamp(GetNextAvailableResponseButtonPosition(buttons.Length - 1, -1), 0, buttons.Length - 1);
                                SetResponseButton(buttons[position], responses[i], target, buttonNumber++);
                            }
                        }
                    }
                }
            }
            NotifyContentChanged();
        }
コード例 #4
0
 private void SetResponseButton(UnityUIResponseButton button, Response response, Transform target)
 {
     if (button != null) {
         button.visible = true;
         button.clickable = response.enabled;
         button.target = target;
         if (response != null) button.SetFormattedText(response.formattedText);
         button.response = response;
     }
 }
コード例 #5
0
		private void SetResponseButton(UnityUIResponseButton button, Response response, Transform target, int buttonNumber) {
			if (button != null) {
				button.visible = true;
				button.clickable = response.enabled;
				button.target = target;
				if (response != null) button.SetFormattedText(response.formattedText);
				button.response = response;

				// Auto-number:
				if (autonumber.enabled) {
					button.Text = string.Format(autonumber.format, buttonNumber + 1, button.Text);
					var keyTrigger = button.GetComponent<UIButtonKeyTrigger>();
					if (keyTrigger == null) keyTrigger = button.gameObject.AddComponent<UIButtonKeyTrigger>();
					keyTrigger.key = (KeyCode) ((int) KeyCode.Alpha1 + buttonNumber);
				}
			}
		}