Exemplo n.º 1
0
        private void OnEnable()
        {
            if (text == null && inputField == null)
            {
                return;
            }

            string value = null;

            if (variableString != null)
            {
                value = variableString.ToString();
            }

            if (variableInt != null)
            {
                value = variableInt.ToString();
            }

            if (variableFloat != null)
            {
                value = variableFloat.ToString();
            }

            if (variableBool != null)
            {
                value = variableBool.ToString();
            }

            if (text != null)
            {
                text.text = value;
            }

            if (inputField != null)
            {
                inputField.text = value;
            }
        }
Exemplo n.º 2
0
        public void Use_Globals_Without_Args_To_Formatter()
        {
            // The top container
            // It gets its name later, when being added to the PersistentVariablesSource
            var varGroup = new VariablesGroup();

            // Add a (nested) VariablesGroup named 'group' to the top container
            varGroup.Add("group", new VariablesGroup
            {
                // Add variables to the nested group
                { "groupString", new StringVariable("groupStringValue") },
                { "groupDateTime", new Variable <DateTime>(new DateTime(2024, 12, 31)) }
            });
            // Add more variables to the top group container
            varGroup.Add(new KeyValuePair <string, IVariable>("topInteger", new IntVariable(12345)));
            var stringVar = new StringVariable("topStringValue");

            varGroup.Add("topString", stringVar);

            // The formatter for persistent variables requires only 2 extensions
            var smart = new SmartFormatter();

            smart.FormatterExtensions.Add(new DefaultFormatter());
            // Add as the first in the source extensions list
            var pvs = new PersistentVariablesSource
            {
                // Here, the top container gets its name
                { "global", varGroup }
            };

            smart.InsertExtension(0, pvs);

            // Act
            // Note: We don't need args to the formatter for globals
            var globalGroup = smart.Format(CultureInfo.InvariantCulture,
                                           "{global.group.groupString} {global.group.groupDateTime:'groupDateTime='yyyy-MM-dd}");
            var topInteger = smart.Format("{global.topInteger}");
            var topString  = smart.Format("{global.topString}");

            // Assert
            Assert.That(globalGroup, Is.EqualTo("groupStringValue groupDateTime=2024-12-31"));
            Assert.That(topString, Is.EqualTo(stringVar.ToString()));
            Assert.That(topInteger, Is.EqualTo("12345"));
        }