Exemplo n.º 1
0
        /// <summary>
        /// Adds a quest group to the table using the template.
        /// </summary>
        /// <param name="questInfo">Quest info.</param>
        private void AddQuestGroupToTable(string group)
        {
            if (string.IsNullOrEmpty(group) || questGroupTemplate == null || !questGroupTemplate.ArePropertiesAssigned)
            {
                return;
            }
            GameObject questGroupGameObject = Instantiate(questGroupTemplate.gameObject) as GameObject;

            if (questGroupGameObject == null)
            {
                Debug.LogError(string.Format("{0}: {1} couldn't instantiate quest group template", new object[] { DialogueDebug.Prefix, name }));
                return;
            }
            questGroupGameObject.name = group;
            questGroupGameObject.transform.SetParent(questTable.transform, false);
            questGroupGameObject.SetActive(true);
            UnityUIQuestGroupTemplate template = questGroupGameObject.GetComponent <UnityUIQuestGroupTemplate>();

            if (template == null)
            {
                return;
            }
            template.Initialize();
            template.heading.text = group;

            // Set up the collapse/expand button:
            var button = questGroupGameObject.GetComponentInChildren <UnityEngine.UI.Button>();

            if (button != null)
            {
                button.onClick.AddListener(() => ClickQuestGroupFoldout(group));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a quest group to the table using the template.
        /// </summary>
        /// <param name="questInfo">Quest group name.</param>
        protected virtual void AddQuestGroupToTable(string group)
        {
            if (string.IsNullOrEmpty(group) || questGroupTemplate == null || !questGroupTemplate.ArePropertiesAssigned)
            {
                return;
            }

            // Try to use existing instance from unused list first:
            var existingChild = unusedGroupTemplateInstances.Find(x => string.Equals(x.heading.text, group));

            if (existingChild != null)
            {
                unusedGroupTemplateInstances.Remove(existingChild);
                groupTemplateInstances.Add(existingChild);
                existingChild.transform.SetSiblingIndex(siblingIndexCounter++);
                return;
            }

            // Otherwise create a new one:
            GameObject questGroupGameObject = Instantiate(questGroupTemplate.gameObject) as GameObject;

            if (questGroupGameObject == null)
            {
                Debug.LogError(string.Format("{0}: {1} couldn't instantiate quest group template", new object[] { DialogueDebug.Prefix, name }));
                return;
            }
            questGroupGameObject.name = group;
            questGroupGameObject.transform.SetParent(questTable.transform, false);
            questGroupGameObject.SetActive(true);
            UnityUIQuestGroupTemplate template = questGroupGameObject.GetComponent <UnityUIQuestGroupTemplate>();

            if (template == null)
            {
                return;
            }
            groupTemplateInstances.Add(template);
            template.transform.SetSiblingIndex(siblingIndexCounter++);
            template.Initialize();
            template.heading.text = group;

            // Set up the collapse/expand button:
            var button = questGroupGameObject.GetComponentInChildren <UnityEngine.UI.Button>();

            if (button != null)
            {
                button.onClick.AddListener(() => ClickQuestGroupFoldout(group));
            }
        }