Пример #1
0
        private IVariableStore GetStore(IVariableStore variables, SelectionItem item)
        {
            if (!item.Variables.IsAssigned)
            {
                return(variables);
            }
            else
            {
                var value = item.Variables.GetValue(variables);

                if (value.Type == VariableType.Empty)
                {
                    Debug.LogErrorFormat(this, _missingItemError, item.Id, item.Variables);
                    return(null);
                }
                else if (!value.TryGetStore(out var store))
                {
                    Debug.LogErrorFormat(this, _invalidItemError, item.Id, item.Variables);
                    return(null);
                }
                else
                {
                    return(store);
                }
            }
        }
Пример #2
0
        private void AddItem(SelectionItem item, GameObject child, IVariableStore variables, IVariableStore selectedVariables, int index)
        {
            if (index < _items.Count)
            {
                if (_items[index].Item == item && _items[index].Variables == variables)
                {
                    return;
                }

                _items.RemoveRange(index, _items.Count - index);
            }

            var parent = GetItemParent();
            var obj    = child == null?Instantiate(item.Template, parent) : child;            // Don't null coalesce

            obj.transform.SetSiblingIndex(index);

            var indicator = obj.GetComponentInChildren <FocusIndicator>(true);
            var selector  = obj.GetComponentInChildren <ItemSelector>();

            if (selector)
            {
                selector.Selection = this;
                selector.Index     = index;
            }

            _items.Add(new MenuItem
            {
                Item              = item,
                Variables         = variables,
                SelectedVariables = selectedVariables,
                Object            = obj,
                Generated         = child == null,
                Indicator         = indicator,
                Selector          = selector
            });
        }