示例#1
0
        private ValueUI CreateValueUI(ValueType type)
        {
            ValueUI result = Instantiate(_resourceProvider.ValueUiPrefab, transform);

            result.Type = type;
            result.RebuildAnValue();
            _valueUis.Add(result);

            return(result);
        }
        public void SetValueFromDialog(ValueUI valueUI, IValue value)
        {
            SetValueDialog setDialog = Instantiate(_resourceProvider.SetValueDialog, _dialogLayer);

            string inputValue = "0";

            bool    isNumber = true;
            INumber number   = value as INumber;

            if (number != null)
            {
                inputValue = number.Value.ToString();
            }

            IBoolean boolean = value as IBoolean;

            if (boolean != null)
            {
                inputValue = boolean.IsTrue ? "1" : "0";
                isNumber   = false;
            }

            setDialog.Init("Set Constant", inputValue);

            setDialog.OnOk.AddListener(
                (valueString) =>
            {
                if (isNumber)
                {
                    if (float.TryParse(valueString, out float floatValue))
                    {
                        FloatConstant constant = number as FloatConstant;

                        if (constant != null)
                        {
                            number.Value = floatValue;
                        }
                        else
                        {
                            constant       = new FloatConstant();
                            constant.Value = floatValue;
                            _cursorTool.SetLabelTarget.Value = constant;

                            if (_cursorTool.SetLabelTarget.Value.Parent == null)
                            {
                                _cursorTool.SetLabelValueUi.Value = _cursorTool.SetLabelTarget.Value;
                            }
                        }
                    }
                }
                else
                {
                    if (float.TryParse(valueString, out float floatValue))
                    {
                        BoolConstant constant = boolean as BoolConstant;

                        if (constant != null)
                        {
                            boolean.IsTrue = floatValue != 0;
                        }
                        else
                        {
                            constant        = new BoolConstant();
                            constant.IsTrue = floatValue != 0;
                            _cursorTool.SetLabelTarget.Value = constant;

                            if (_cursorTool.SetLabelTarget.Value.Parent == null)
                            {
                                _cursorTool.SetLabelValueUi.Value = _cursorTool.SetLabelTarget.Value;
                            }
                        }
                    }
                }

                valueUI.RebuildAnValue();
            });
        }
        public void CursorOnContextMenuItem(MenuButton sender)
        {
            switch (_setLabelSteps)
            {
            case SetLabelSteps.ChoiceLabelType:
            {
                _activeLabelType = _labelTypeMenuButtons[sender];
                _setLabelSteps   = SetLabelSteps.SetValue;

                _contextMenu.ClearContextMenu();
                if (_activeLabelType == ActiveLabelType.Variable)
                {
                    SetLabelVariableMenuItems();
                }
                else if (_activeLabelType == ActiveLabelType.Expression)
                {
                    if (_setLabelTarget.ValueType == ValueType.Bool)
                    {
                        _setLabelTarget.Value = new LogicExpression();
                    }
                    else
                    {
                        _setLabelTarget.Value = new Expression();
                    }

                    if (_setLabelTarget.Value.Parent == null)
                    {
                        _setLabelValueUi.Value = _setLabelTarget.Value;
                    }
                    _setLabelValueUi.RebuildAnValue();

                    _contextMenu.gameObject.SetActive(false);
                    _setLabelSteps = SetLabelSteps.SetTarget;
                }
                else if (_activeLabelType == ActiveLabelType.Constant)
                {
                    _mainController.SetValueFromDialog(_setLabelValueUi, _setLabelTarget.Value);

                    _contextMenu.gameObject.SetActive(false);
                    _setLabelSteps = SetLabelSteps.SetTarget;
                }
                else if (_activeLabelType == ActiveLabelType.Operation)
                {
                    if (_setLabelTarget.LabelType == ActiveLabelType.Condition)
                    {
                        SetRelationMenuItems();
                    }
                    else
                    {
                        if (_setLabelTarget.ValueType == ValueType.Bool)
                        {
                            SetLogicOperationMenuItems();
                        }
                        else
                        {
                            SetNumberOperationMenuItems();
                        }
                    }

                    _setLabelSteps = SetLabelSteps.SetValue;
                }
                else if (_activeLabelType == ActiveLabelType.Condition)
                {
                    _setLabelTarget.Value = new Condition();

                    if (_setLabelTarget.Value.Parent == null)
                    {
                        _setLabelValueUi.Value = _setLabelTarget.Value;
                    }
                    _setLabelValueUi.RebuildAnValue();

                    _contextMenu.gameObject.SetActive(false);
                    _setLabelSteps = SetLabelSteps.SetTarget;
                }
            }
            break;

            case SetLabelSteps.SetValue:
            {
                if (_activeLabelType == ActiveLabelType.Operation)
                {
                    if (_setLabelTarget.LabelType == ActiveLabelType.Condition)
                    {
                        Condition condition = _setLabelTarget.Value as Condition;
                        condition.Relation = _relationMenuButtons[sender];
                    }
                    else
                    {
                        if (_setLabelTarget.ValueType == ValueType.Bool)
                        {
                            LogicExpression logicExpression = _setLabelTarget.Value as LogicExpression;
                            logicExpression.Operation = _logicOperationMenuButtons[sender];
                        }
                        else
                        {
                            Expression numberExpression = _setLabelTarget.Value as Expression;
                            numberExpression.Operation = _numberOperationMenuButtons[sender];
                        }
                    }

                    _setLabelValueUi.RebuildAnValue();
                }
                else if (_activeLabelType == ActiveLabelType.Variable)
                {
                    if (_isSetedLabelVariable)
                    {
                        _setLabelTarget.Value = _labelVariableMenuButtons[sender];
                        _setVariableBlock.SetBlock.Variable = _labelVariableMenuButtons[sender];

                        _setVariableBlock.RefreshParameter();
                    }
                    else
                    {
                        _setLabelTarget.Value = _labelVariableMenuButtons[sender];

                        if (_setLabelTarget.Value.Parent == null)
                        {
                            _setLabelValueUi.Value = _setLabelTarget.Value;
                        }
                        _setLabelValueUi.RebuildAnValue();
                    }
                }

                _contextMenu.gameObject.SetActive(false);
                _setLabelSteps = SetLabelSteps.SetTarget;
            }
            break;
            }
        }