예제 #1
0
        private void AddOption(int id, string text)
        {
            AswerOptionView optionView = _quizOptionFactory.Create();

            optionView.OptionClickedEvent += HandleOptionClickedEvent;
            optionView.SetData(id, text);

            RectTransform optionTransform = optionView.gameObject.GetComponent <RectTransform>();

            optionTransform.SetParent(optionsContainer);
            optionTransform.localScale = Vector3.one;
            optionTransform.SetInsetAndSizeFromParentEdge(UnityEngine.RectTransform.Edge.Left, 0, optionsContainer.rect.size.x);

            options.Add(id, optionView);
        }
예제 #2
0
        private void HandleOptionClickedEvent(AswerOptionView optionView)
        {
            if (!inputEnabled)
            {
                return;
            }

            if (!optionView.IsSelected)
            {
                // set option as selected
                optionView.IsSelected = true;

                // deselect all if not multiselection
                if (!this.currentQuestion.isMultiselection)
                {
                    for (int i = 0; i < selectedOptions.Count; i++)
                    {
                        options[selectedOptions[i]].IsSelected = false;
                    }
                    selectedOptions.Clear();
                }

                // select current one
                selectedOptions.Add(optionView.Id);
            }
            else
            {
                // deselect current one
                optionView.IsSelected = false;

                // remove from selected list
                selectedOptions.Remove(optionView.Id);
            }

            // enable button when something is selected
            confirmtButton.enabled = selectedOptions.Count > 0;
        }