private static GameObject buildCustomElement(string _type, string _value, Dictionary <string, string> _variants, CustomElementModel.CustomElementStatus _elementStatus) { CustomElementModel.CustomElement element = _elementStatus.elements.Find((_item) => { return(_item.name.Equals(_type)); }); if (null == element) { return(null); } GameObject clone = null; if (element.type.Equals("dropdown")) { clone = GameObject.Instantiate(templateElementDropdown.gameObject); Dropdown dd = clone.GetComponent <Dropdown>(); dd.options.Clear(); foreach (string value in element.values) { dd.options.Add(new Dropdown.OptionData(value)); } if (element.values.Count > 0) { dd.captionText.text = element.values[0]; } FacadeUtility.StretchDropdown(dd); dd.onValueChanged.AddListener((_ddValue) => { if (null != OnDropdownUpdated) { OnDropdownUpdated(clone.transform.parent.name, _value, dd.value); } }); } return(clone); }
private static void decorateElements(GameObject _expression, List <BlockModel.Element> _elements, Dictionary <string, string> _variants, CustomElementModel.CustomElementStatus _elementStatus) { RectTransform space = _expression.transform.Find("__space__").GetComponent <RectTransform>(); space.gameObject.SetActive(_elements.Count == 0); foreach (BlockModel.Element element in _elements) { GameObject clone = null; if (element.type.Equals("text")) { clone = GameObject.Instantiate(templateElementText.gameObject); UnityEngine.UI.Text text = clone.GetComponent <UnityEngine.UI.Text>(); text.text = element.value; FacadeUtility.StretchText(text); } else if (element.type.Equals("input")) { clone = GameObject.Instantiate(templateElementInput.gameObject); InputField input = clone.GetComponent <InputField>(); input.text = element.value; if (_variants.ContainsKey(element.value)) { input.text = _variants[element.value]; } FacadeUtility.StretchInput(input); input.onEndEdit.AddListener((_text) => { if (null != OnInputUpdated) { OnInputUpdated(clone.transform.parent.name, element.value, _text); } }); } else if (element.type.Equals("dropdown")) { clone = GameObject.Instantiate(templateElementDropdown.gameObject); Dropdown dropdown = clone.GetComponent <Dropdown>(); FacadeUtility.StretchDropdown(dropdown); dropdown.onValueChanged.AddListener((_value) => { if (null != OnDropdownUpdated) { OnDropdownUpdated(clone.transform.parent.name, element.value, dropdown.value); } }); } else if (element.type.Equals("object")) { clone = GameObject.Instantiate(templateElementObject.gameObject); DropObject drop = clone.AddComponent <DropObject>(); FacadeUtility.StretchDropObject(drop); if (_variants.ContainsKey(element.value)) { string uuid = _variants[element.value]; if (!string.IsNullOrEmpty(uuid)) { if (objectElements.ContainsKey(uuid)) { ObjectElement oe = objectElements[uuid]; drop.captionText.text = oe.alias; drop.imgIcon.gameObject.SetActive(true); drop.imgIcon.sprite = oe.icon; } } } drop.onObjectDrop = (_dragObject) => { if (null != OnDropObjectUpdated) { OnDropObjectUpdated(clone.transform.parent.name, element.value, _dragObject.name); } }; } else { clone = buildCustomElement(element.type, element.value, _variants, _elementStatus); } if (null == clone) { continue; } clone.name = element.value; clone.transform.SetParent(_expression.transform); clone.transform.localScale = Vector3.one; } }