Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        private void SetupPort()
        {
            this.AddManipulator(m_EdgeConnector);

            tooltip = UdonGraphExtensions.FriendlyTypeName(portType);

            if (portType == null || direction == Direction.Output)
            {
                return;
            }

            var value = TryGetValueObject(out object result);
            var field = UdonFieldFactory.CreateField(
                portType,
                result,
                newValue => SetNewValue(newValue)
                );

            if (field != null)
            {
                SetupField(field);
            }

            if (_udonNodeData.fullName.StartsWith("Const"))
            {
                RemoveConnector();
            }

            UpdateLabel(connected);
        }
        private void SetupField(VisualElement field)
        {
            // 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;
#if UNITY_2019_3_OR_NEWER
                tfield.RegisterValueChangedCallback(
#else
                tfield.OnValueChanged(
#endif
                    (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 Label(friendlyName);
            _inputFieldTypeLabel = label;
            field.AddToClassList("portField");

            _inputField = field;
            Add(_inputField);
        }
Exemplo n.º 5
0
        // 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);
        }
Exemplo n.º 6
0
        private void SetupPort()
        {
            _isSendChangePort = portName == "sendChange";
            if (_isSendChangePort)
            {
                m_EdgeConnector = null;
            }
            else
            {
                this.AddManipulator(m_EdgeConnector);
            }

            tooltip = UdonGraphExtensions.FriendlyTypeName(portType);

            FullName = _udonNodeData.fullName;

            if (portType == null || direction == Direction.Output)
            {
                return;
            }

            if (TryGetValueObject(out object result, portType))
            {
                var field = UdonFieldFactory.CreateField(
                    portType,
                    result,
                    newValue => SetNewValue(newValue)
                    );

                if (field != null)
                {
                    SetupField(field);
                }
            }

            if (_udonNodeData.fullName.StartsWithCached("Const"))
            {
                RemoveConnectorAndLabel();
            }
            else if (_udonNodeData.fullName.StartsWithCached("Set_Variable") && _nodeValueIndex == 2)
            {
                _isSendChangePort = true;
                RemoveConnector();
                AddToClassList("send-change");
            }

            AddToClassList(portName);

            UpdateLabel(connected);
        }
Exemplo n.º 7
0
        private void SetupPort()
        {
            this.AddManipulator(m_EdgeConnector);
            if (portType == null || direction == Direction.Output)
            {
                return;
            }
            tooltip = UdonGraphExtensions.FriendlyTypeName(portType);
            var field = GetTheRightField(portType);

            if (field != null)
            {
                Add(field);
            }

            if (_udonNodeData.fullName.StartsWith("Const"))
            {
                RemoveConnector();
            }

            UpdateLabel(connected);
        }
Exemplo n.º 8
0
        override public List <SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
        {
            if (_fullRegistry != null)
            {
                return(_fullRegistry);
            }

            _fullRegistry = new List <SearchTreeEntry>();

            _fullRegistry.Add(new SearchTreeGroupEntry(new GUIContent("Variable Type Search"), 0));

            var definitions = UdonEditorManager.Instance.GetNodeDefinitions("Variable_").ToList().OrderBy(n => n.name);

            foreach (var definition in definitions)
            {
                _fullRegistry.Add(new SearchTreeEntry(new GUIContent(UdonGraphExtensions.FriendlyTypeName(definition.type).FriendlyNameify()))
                {
                    level    = 1,
                    userData = definition.fullName,
                });
            }

            return(_fullRegistry);
        }
Exemplo n.º 9
0
        // 0 = Value, 1 = name, 2 = public, 3 = synced, 4 = syncType
        public UdonParameterProperty(UdonGraph graphView, UdonNodeDefinition definition, UdonNodeData nodeData)
        {
            this.graph      = graphView;
            this.definition = definition;
            this.nodeData   = nodeData;

            // Make sure the incoming nodeData has the right number of nodeValues (super old graphs didn't have sync info)
            if (this.nodeData.nodeValues.Length != 5)
            {
                this.nodeData.nodeValues = GetDefaultNodeValues();
                for (int i = 0; i < nodeData.nodeValues.Length; i++)
                {
                    this.nodeData.nodeValues[i] = nodeData.nodeValues[i];
                }
            }

            // Public Toggle
            isPublic = new EngineUI.Toggle
            {
                text  = "public",
                value = (bool)GetValue(ValueIndices.isPublic)
            };
            isPublic.OnValueChanged(e =>
            {
                SetNewValue(e.newValue, ValueIndices.isPublic);
            });
            Add(isPublic);

            // Is Synced Field
            isSynced = new EngineUI.Toggle
            {
                text  = "synced",
                value = (bool)GetValue(ValueIndices.isSynced),
            };

            isSynced.OnValueChanged(e =>
            {
                SetNewValue(e.newValue, ValueIndices.isSynced);
                syncField.visible = e.newValue;
            });
            Add(isSynced);

            // Sync Field, add to isSynced
            List <string> choices = new List <string>()
            {
                "none", "linear", "smooth"
            };

            syncField = new EditorUI.PopupField <string>(choices, 0)
            {
                visible = isSynced.value
            };
            syncField.OnValueChanged(e =>
            {
                SetNewValue(e.newValue, ValueIndices.syncType);
            });
            isSynced.Add(syncField);

            // Container to show/edit Default Value
            var friendlyName = UdonGraphExtensions.FriendlyTypeName(definition.type).FriendlyNameify();

            defaultValueContainer = new VisualElement
            {
                new Label("default value")
                {
                    name = "default-value-label"
                }
            };
            var field = GetTheRightField(definition.type);

            if (field != null)
            {
                // TODO: need to handle cases where we can't generate the field above
                defaultValueContainer.Add(field);
                Add(defaultValueContainer);
            }
        }
Exemplo n.º 10
0
        // 0 = Value, 1 = name, 2 = public, 3 = synced, 4 = syncType
        public UdonParameterProperty(UdonGraph graphView, UdonNodeDefinition definition, UdonNodeData nodeData)
        {
            this.graph      = graphView;
            this.definition = definition;
            this.nodeData   = nodeData;

            // Make sure the incoming nodeData has the right number of nodeValues (super old graphs didn't have sync info)
            if (this.nodeData.nodeValues.Length != 5)
            {
                this.nodeData.nodeValues = GetDefaultNodeValues();
                for (int i = 0; i < nodeData.nodeValues.Length; i++)
                {
                    this.nodeData.nodeValues[i] = nodeData.nodeValues[i];
                }
            }

            // Public Toggle
            isPublic = new Toggle
            {
                text  = "public",
                value = (bool)GetValue(ValueIndices.isPublic)
            };
#if UNITY_2019_3_OR_NEWER
            isPublic.RegisterValueChangedCallback(
#else
            isPublic.OnValueChanged(
#endif
                e => { SetNewValue(e.newValue, ValueIndices.isPublic); });
            Add(isPublic);

            // Is Synced Field
            isSynced = new Toggle
            {
                text  = "synced",
                value = (bool)GetValue(ValueIndices.isSynced),
            };

#if UNITY_2019_3_OR_NEWER
            isSynced.RegisterValueChangedCallback(
#else
            isSynced.OnValueChanged(
#endif
                e =>
            {
                SetNewValue(e.newValue, ValueIndices.isSynced);
                syncField.visible = e.newValue;
            });
            Add(isSynced);

            // Sync Field, add to isSynced
            List <string> choices = new List <string>()
            {
                "none", "linear", "smooth"
            };
            syncField = new EditorUI.PopupField <string>(choices, 0)
            {
                visible = isSynced.value
            };
#if UNITY_2019_3_OR_NEWER
            syncField.RegisterValueChangedCallback(
#else
            syncField.OnValueChanged(
#endif
                e => { SetNewValue(e.newValue, ValueIndices.syncType); });
            isSynced.Add(syncField);

            // Container to show/edit Default Value
            var friendlyName      = UdonGraphExtensions.FriendlyTypeName(definition.type).FriendlyNameify();
            defaultValueContainer = new VisualElement();
            defaultValueContainer.Add(
                new Label("default value")
            {
                name = "default-value-label"
            });

            // Generate Default Value Field
            var value   = TryGetValueObject(out object result);
            _inputField = UdonFieldFactory.CreateField(
                definition.type,
                result,
                newValue => SetNewValue(newValue, ValueIndices.value)
                );
            if (_inputField != null)
            {
                defaultValueContainer.Add(_inputField);
                Add(defaultValueContainer);
            }
        }
        // 0 = Value, 1 = name, 2 = public, 3 = synced, 4 = syncType
        public UdonParameterProperty(UdonGraph graphView, UdonNodeDefinition definition, UdonNodeData nodeData)
        {
            this.graph      = graphView;
            this.definition = definition;
            this.nodeData   = nodeData;

            string friendlyName = UdonGraphExtensions.FriendlyTypeName(definition.type).FriendlyNameify();

            // Public Toggle
            isPublic = new Toggle
            {
                text  = "public",
                value = (bool)GetValue(ValueIndices.isPublic)
            };
#if UNITY_2019_3_OR_NEWER
            isPublic.RegisterValueChangedCallback(
#else
            isPublic.OnValueChanged(
#endif
                e => { SetNewValue(e.newValue, ValueIndices.isPublic); });
            Add(isPublic);

            if (UdonNetworkTypes.CanSync(definition.type))
            {
                // Is Synced Field
                isSynced = new Toggle
                {
                    text  = "synced",
                    value = (bool)GetValue(ValueIndices.isSynced),
                    name  = "syncToggle",
                };

#if UNITY_2019_3_OR_NEWER
                isSynced.RegisterValueChangedCallback(
#else
                isSynced.OnValueChanged(
#endif
                    e =>
                {
                    SetNewValue(e.newValue, ValueIndices.isSynced);
                    syncField.visible = e.newValue;
                });

                // Sync Field, add to isSynced
                List <string> choices = new List <string>()
                {
                    "none"
                };

                if (UdonNetworkTypes.CanSyncLinear(definition.type))
                {
                    choices.Add("linear");
                }

                if (UdonNetworkTypes.CanSyncSmooth(definition.type))
                {
                    choices.Add("smooth");
                }

                syncField = new EditorUI.PopupField <string>(choices, 0)
                {
                    visible = isSynced.value,
                };
                syncField.Insert(0, new Label("smooth:"));

#if UNITY_2019_3_OR_NEWER
                syncField.RegisterValueChangedCallback(
#else
                syncField.OnValueChanged(
#endif
                    e =>
                {
                    SetNewValue(e.newValue, ValueIndices.syncType);
                });

                // Only show sync smoothing dropdown if there are choices to be made
                if (choices.Count > 1)
                {
                    isSynced.Add(syncField);
                }

                Add(isSynced);
            }
            else
            {
                // Cannot Sync
                SetNewValue(false, ValueIndices.isSynced);
                Add(new Label($"{friendlyName} cannot be synced."));
            }

            // Container to show/edit Default Value
            defaultValueContainer = new VisualElement();
            defaultValueContainer.Add(
                new Label("default value")
            {
                name = "default-value-label"
            });

            // Generate Default Value Field
            var value   = TryGetValueObject(out object result);
            _inputField = UdonFieldFactory.CreateField(
                definition.type,
                result,
                newValue => SetNewValue(newValue, ValueIndices.value)
                );
            if (_inputField != null)
            {
                defaultValueContainer.Add(_inputField);
                Add(defaultValueContainer);
            }
        }