public ToggleControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node         = node;
            m_PropertyInfo = propertyInfo;
            AddStyleSheetPath("Styles/Controls/ToggleControlView");

            if (propertyInfo.PropertyType != typeof(Toggle))
            {
                throw new ArgumentException("Property must be a Toggle.", "propertyInfo");
            }

            label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);

            var value = (Toggle)m_PropertyInfo.GetValue(m_Node, null);
            var panel = new VisualElement {
                name = "togglePanel"
            };

            if (!string.IsNullOrEmpty(label))
            {
                panel.Add(new Label(label));
            }
            Action changedToggle = () => { OnChangeToggle(); };

            m_Toggle = new UnityEngine.Experimental.UIElements.Toggle(changedToggle);
            m_Toggle.SetEnabled(value.isEnabled);
            m_Toggle.on = value.isOn;
            panel.Add(m_Toggle);
            Add(panel);
        }
        public BooleanSlotControlView(BooleanMaterialSlot slot)
        {
            m_Slot = slot;
            Action changedToggle = () => { OnChangeToggle(); };
            var    toggleField   = new UnityEngine.Experimental.UIElements.Toggle(changedToggle);

            Add(toggleField);
        }
Пример #3
0
 static public int get_on(IntPtr l)
 {
     try {
         UnityEngine.Experimental.UIElements.Toggle self = (UnityEngine.Experimental.UIElements.Toggle)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.on);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #4
0
 static public int set_on(IntPtr l)
 {
     try {
         UnityEngine.Experimental.UIElements.Toggle self = (UnityEngine.Experimental.UIElements.Toggle)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.on = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #5
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Experimental.UIElements.Toggle o;
         System.Action a1;
         LuaDelegation.checkDelegate(l, 2, out a1);
         o = new UnityEngine.Experimental.UIElements.Toggle(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #6
0
        public BlackboardFieldPropertyView(AbstractMaterialGraph graph, IShaderProperty property)
        {
            AddStyleSheetPath("Styles/ShaderGraphBlackboard");
            m_Graph    = graph;
            m_Property = property;

            m_ExposedToogle = new Toggle(() =>
            {
                property.generatePropertyBlock = m_ExposedToogle.value;
                DirtyNodes(ModificationScope.Graph);
            });
            m_ExposedToogle.value = property.generatePropertyBlock;
            AddRow("Exposed", m_ExposedToogle);

            m_ReferenceNameField = new TextField(512, false, false, ' ');
            m_ReferenceNameField.AddStyleSheetPath("Styles/PropertyNameReferenceField");
            AddRow("Reference", m_ReferenceNameField);
            m_ReferenceNameField.value     = property.referenceName;
            m_ReferenceNameField.isDelayed = true;
            m_ReferenceNameField.OnValueChanged(newName =>
            {
                string newReferenceName        = m_Graph.SanitizePropertyReferenceName(newName.newValue, property.guid);
                property.overrideReferenceName = newReferenceName;
                m_ReferenceNameField.value     = property.referenceName;

                if (string.IsNullOrEmpty(property.overrideReferenceName))
                {
                    m_ReferenceNameField.RemoveFromClassList("modified");
                }
                else
                {
                    m_ReferenceNameField.AddToClassList("modified");
                }

                DirtyNodes(ModificationScope.Graph);
                UpdateReferenceNameResetMenu();
            });

            if (!string.IsNullOrEmpty(property.overrideReferenceName))
            {
                m_ReferenceNameField.AddToClassList("modified");
            }

            if (property is Vector1ShaderProperty)
            {
                VisualElement floatRow   = new VisualElement();
                VisualElement intRow     = new VisualElement();
                VisualElement modeRow    = new VisualElement();
                VisualElement minRow     = new VisualElement();
                VisualElement maxRow     = new VisualElement();
                FloatField    floatField = null;

                var floatProperty = (Vector1ShaderProperty)property;

                if (floatProperty.floatType == FloatType.Integer)
                {
                    var field = new IntegerField {
                        value = (int)floatProperty.value
                    };
                    field.OnValueChanged(intEvt =>
                    {
                        floatProperty.value = (float)intEvt.newValue;
                        DirtyNodes();
                    });
                    intRow = AddRow("Default", field);
                }
                else
                {
                    floatField = new FloatField {
                        value = floatProperty.value
                    };
                    floatField.OnValueChanged(evt =>
                    {
                        floatProperty.value = (float)evt.newValue;
                        DirtyNodes();
                    });
                    floatRow = AddRow("Default", floatField);
                }

                var floatModeField = new EnumField((Enum)floatProperty.floatType);
                floatModeField.value = floatProperty.floatType;
                floatModeField.OnValueChanged(evt =>
                {
                    if (floatProperty.floatType == (FloatType)evt.newValue)
                    {
                        return;
                    }
                    floatProperty           = (Vector1ShaderProperty)property;
                    floatProperty.floatType = (FloatType)evt.newValue;
                    switch (floatProperty.floatType)
                    {
                    case FloatType.Slider:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var field = new FloatField {
                            value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x)
                        };
                        floatProperty.value = (float)field.value;
                        field.OnValueChanged(defaultEvt =>
                        {
                            floatProperty.value = Mathf.Max(Mathf.Min((float)defaultEvt.newValue, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value         = floatProperty.value;
                            DirtyNodes();
                        });
                        floatRow     = AddRow("Default", field);
                        field.value  = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        modeRow      = AddRow("Mode", floatModeField);
                        var minField = new FloatField {
                            value = floatProperty.rangeValues.x
                        };
                        minField.OnValueChanged(minEvt =>
                        {
                            floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y);
                            floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value = floatProperty.value;
                            DirtyNodes();
                        });
                        minRow       = AddRow("Min", minField);
                        var maxField = new FloatField {
                            value = floatProperty.rangeValues.y
                        };
                        maxField.OnValueChanged(maxEvt =>
                        {
                            floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue);
                            floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value = floatProperty.value;
                            DirtyNodes();
                        });
                        maxRow = AddRow("Max", maxField);
                        break;

                    case FloatType.Integer:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var intField = new IntegerField {
                            value = (int)floatProperty.value
                        };
                        intField.OnValueChanged(intEvt =>
                        {
                            floatProperty.value = (float)intEvt.newValue;
                            DirtyNodes();
                        });
                        intRow  = AddRow("Default", intField);
                        modeRow = AddRow("Mode", floatModeField);
                        break;

                    default:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        field = new FloatField {
                            value = floatProperty.value
                        };
                        field.OnValueChanged(defaultEvt =>
                        {
                            floatProperty.value = (float)defaultEvt.newValue;
                            DirtyNodes();
                        });
                        floatRow = AddRow("Default", field);
                        modeRow  = AddRow("Mode", floatModeField);
                        break;
                    }
                    DirtyNodes();
                });
                modeRow = AddRow("Mode", floatModeField);

                if (floatProperty.floatType == FloatType.Slider)
                {
                    var minField = new FloatField {
                        value = floatProperty.rangeValues.x
                    };
                    minField.OnValueChanged(minEvt =>
                    {
                        floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y);
                        floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        floatField.value          = floatProperty.value;
                        DirtyNodes();
                    });
                    minRow = AddRow("Min", minField);
                    var maxField = new FloatField {
                        value = floatProperty.rangeValues.y
                    };
                    maxField.OnValueChanged(maxEvt =>
                    {
                        floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue);
                        floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        floatField.value          = floatProperty.value;
                        DirtyNodes();
                    });
                    maxRow = AddRow("Max", maxField);
                }
            }
            else if (property is Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector3ShaderProperty)
            {
                var vectorProperty = (Vector3ShaderProperty)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector4ShaderProperty)
            {
                var vectorProperty = (Vector4ShaderProperty)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ColorShaderProperty)
            {
                var colorProperty = (ColorShaderProperty)property;
                var colorField    = new ColorField {
                    value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR
                };
                colorField.OnValueChanged(evt =>
                {
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                colorModeField.OnValueChanged(evt =>
                {
                    if (colorProperty.colorMode == (ColorMode)evt.newValue)
                    {
                        return;
                    }
                    colorProperty.colorMode = (ColorMode)evt.newValue;
                    colorField.hdr          = colorProperty.colorMode == ColorMode.HDR;
                    colorField.MarkDirtyRepaint();
                    DirtyNodes();
                });
                AddRow("Mode", colorModeField);
            }
            else if (property is TextureShaderProperty)
            {
                var textureProperty = (TextureShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture2DArrayShaderProperty)
            {
                var textureProperty = (Texture2DArrayShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.textureArray = (Texture2DArray)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture3DShaderProperty)
            {
                var textureProperty = (Texture3DShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture3D)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value.texture = (Texture3D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is CubemapShaderProperty)
            {
                var cubemapProperty = (CubemapShaderProperty)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap)
                };
                field.OnValueChanged(evt =>
                {
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var    booleanProperty  = (BooleanShaderProperty)property;
                Action onBooleanChanged = () =>
                {
                    booleanProperty.value = !booleanProperty.value;
                    DirtyNodes();
                };
                var field = new Toggle(onBooleanChanged);
                field.SetValue(booleanProperty.value);
                AddRow("Default", field);
            }
//            AddRow("Type", new TextField());
//            AddRow("Exposed", new Toggle(null));
//            AddRow("Range", new Toggle(null));
//            AddRow("Default", new TextField());
//            AddRow("Tooltip", new TextField());


            AddToClassList("sgblackboardFieldPropertyView");

            UpdateReferenceNameResetMenu();
        }
Пример #7
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);
            }
        }
        public BlackboardFieldPropertyView(AbstractNodeGraph graph, INodeProperty property)
        {
            AddStyleSheetPath("Styles/NodeGraphBlackboard");
            m_Graph = graph;

            m_Reference = new TextField();
            m_Reference.OnValueChanged(evt =>
            {
                property.reference = evt.newValue;
                DirtyNodes(ModificationScope.Graph);
            });
            m_Reference.value = property.reference;
            AddRow("Reference", m_Reference);

            if (property is ValueProperty <float> )
            {
                var        floatProperty = (ValueProperty <float>)property;
                FloatField floatField    = new FloatField {
                    value = floatProperty.value
                };
                floatField.OnValueChanged(evt =>
                {
                    floatProperty.value = (float)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", floatField);

                /*if (floatProperty.floatType == FloatType.Slider)
                 * {
                 *  var minField = new FloatField { value = floatProperty.rangeValues.x };
                 *  minField.OnValueChanged(minEvt =>
                 *      {
                 *          floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y);
                 *          floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                 *          floatField.value = floatProperty.value;
                 *          DirtyNodes();
                 *      });
                 *  minRow = AddRow("Min", minField);
                 *  var maxField = new FloatField { value = floatProperty.rangeValues.y };
                 *  maxField.OnValueChanged(maxEvt =>
                 *      {
                 *          floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue);
                 *          floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                 *          floatField.value = floatProperty.value;
                 *          DirtyNodes();
                 *      });
                 *  maxRow = AddRow("Max", maxField);
                 * }*/
            }
            else if (property is ValueProperty <int> )
            {
                var intProperty = (ValueProperty <int>)property;

                var field = new IntegerField {
                    value = intProperty.value
                };
                field.OnValueChanged(intEvt =>
                {
                    intProperty.value = intEvt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Vector2> )
            {
                var vectorProperty = (ValueProperty <Vector2>)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Vector3> )
            {
                var vectorProperty = (ValueProperty <Vector3>)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Vector4> )
            {
                var vectorProperty = (ValueProperty <Vector4>)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.OnValueChanged(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Color> )
            {
                var colorProperty = (ValueProperty <Color>)property;
                //todo add HDR
                var colorField = new ColorField {
                    value = (Color)property.defaultValue, showEyeDropper = false
                };
                colorField.OnValueChanged(evt =>
                {
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
            }
            else if (property is ValueProperty <Texture2D> )
            {
                var textureProperty = (ValueProperty <Texture2D>)property;
                var field           = new ObjectField {
                    value = textureProperty.value, objectType = typeof(Texture2D)
                };
                field.OnValueChanged(evt =>
                {
                    textureProperty.value = (Texture2D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <Cubemap> )
            {
                var cubemapProperty = (ValueProperty <Cubemap>)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value, objectType = typeof(Cubemap)
                };
                field.OnValueChanged(evt =>
                {
                    cubemapProperty.value = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ValueProperty <bool> )
            {
                var booleanProperty = (ValueProperty <bool>)property;
                EventCallback <ChangeEvent <bool> > onBooleanChanged = evt =>
                {
                    booleanProperty.value = evt.newValue;
                    DirtyNodes();
                };
                var field = new Toggle();
                field.OnValueChanged(onBooleanChanged);
                field.value = booleanProperty.value;
                AddRow("Default", field);
            }
//            AddRow("Type", new TextField());
//            AddRow("Exposed", new Toggle(null));
//            AddRow("Range", new Toggle(null));
//            AddRow("Default", new TextField());
//            AddRow("Tooltip", new TextField());


            AddToClassList("sgblackboardFieldPropertyView");
        }