Beispiel #1
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);
            }
        }