Example #1
0
        // Made its own method for now as we have issues auto-converting between string and char in a TextField
        // TODO: refactor SetupField so we can do just the field.value part separately to combine with this
        private VisualElement SetupCharField()
        {
            TextField field = new TextField();

            field.AddToClassList("portField");
            if (TryGetValueObject(out object result))
            {
                field.value = UdonGraphExtensions.UnescapeLikeALiteral((char)result);
            }

            field.isDelayed = true;

            // Special handling for escaping char value
            field.OnValueChanged((e) =>
            {
                if (e.newValue[0] == '\\' && e.newValue.Length > 1)
                {
                    SetNewValue(UdonGraphExtensions.EscapeLikeALiteral(e.newValue.Substring(0, 2)));
                }
                else
                {
                    SetNewValue(e.newValue[0]);
                }
            });
            _inputField = field;

            // Add label, shown when input is connected. Not shown by default
            var friendlyName = UdonGraphExtensions.FriendlyTypeName(typeof(char)).FriendlyNameify();
            var label        = new EngineUI.Label(friendlyName);

            _inputFieldTypeLabel = label;

            return(_inputField);
        }
Example #2
0
        private void SetupField(VisualElement field)
        {
            // Delay color fields so they don't break UI
            if (portType.IsAssignableFrom(typeof(EditorUI.ColorField)))
            {
                _waitToReserialize = true;
            }

            // Custom Event fields need their event names sanitized after input and their connectors removed
            if (_udonNodeData.fullName.CompareTo("Event_Custom") == 0)
            {
                var tfield = (TextField)field;
                tfield.OnValueChanged((e) =>
                {
                    string newValue = e.newValue.SanitizeVariableName();
                    tfield.value    = newValue;
                    SetNewValue(newValue);
                });
                RemoveConnector();
            }

            // Add label, shown when input is connected. Not shown by default
            var friendlyName = UdonGraphExtensions.FriendlyTypeName(portType).FriendlyNameify();
            var label        = new EngineUI.Label(friendlyName);

            _inputFieldTypeLabel = label;
            field.AddToClassList("portField");

            _inputField = field;
            Add(_inputField);
        }
Example #3
0
 static public int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.Experimental.UIElements.Label o;
         if (argc == 1)
         {
             o = new UnityEngine.Experimental.UIElements.Label();
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 2)
         {
             System.String a1;
             checkType(l, 2, out a1);
             o = new UnityEngine.Experimental.UIElements.Label(a1);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        // Works for any TextValueField types, needs to know fieldType and object type
        private VisualElement SetupField <TField, TType>(TField field) where TField : VisualElement, INotifyValueChanged <TType>
        {
            field.AddToClassList("portField");
            if (TryGetValueObject(out object result))
            {
                try
                {
                    field.value = (TType)(result as object);
                }
                catch (Exception e)
                {
                    // Quietly catch this and continue
                }
            }

            // Delay text inputs
            if (typeof(TField).IsAssignableFrom(typeof(TextField)))
            {
                (field as TextField).isDelayed = true;
            }

            // Don't update color fields right away, breaks the UI
            if (typeof(TField).IsAssignableFrom(typeof(EditorUI.ColorField)))
            {
                _waitToReserialize = true;
            }

            // Custom Event fields need their event names sanitized after input and their connectors removed
            if (_udonNodeData.fullName.CompareTo("Event_Custom") == 0)
            {
                var tfield = field as TextField;
                tfield.OnValueChanged((e) =>
                {
                    string newValue = e.newValue.SanitizeVariableName();
                    tfield.value    = newValue;
                    SetNewValue(newValue);
                });
                RemoveConnector();
            }
            else
            {
                field.OnValueChanged((e) => SetNewValue(e.newValue));
            }
            _inputField = field;

            // Add label, shown when input is connected. Not shown by default
            var friendlyName = UdonGraphExtensions.FriendlyTypeName(typeof(TType)).FriendlyNameify();
            var label        = new EngineUI.Label(friendlyName);

            _inputFieldTypeLabel = label;

            return(_inputField);
        }