예제 #1
0
        protected void FillExposedParameters(VisualElement parameterContainer)
        {
            if (graph.exposedParameters.Count != 0)
            {
                parameterContainer.Add(new Label("Exposed Parameters:"));
            }

            foreach (var param in graph.exposedParameters)
            {
                if (param.settings.isHidden)
                {
                    continue;
                }

                VisualElement prop = new VisualElement();
                prop.style.display = DisplayStyle.Flex;
                Type paramType = Type.GetType(param.type);
                var  field     = FieldFactory.CreateField(paramType, param.serializedValue.value, (newValue) => {
                    Undo.RegisterCompleteObjectUndo(graph, "Changed Parameter " + param.name + " to " + newValue);
                    param.serializedValue.value = newValue;
                }, param.name);
                prop.Add(field);
                parameterContainer.Add(prop);
            }
        }
        void DrawParameter(ExposedParameter param, VisualElement paramContainer)
        {
            VisualElement prop = new VisualElement();

            prop.style.display = DisplayStyle.Flex;
            Type paramType = Type.GetType(param.type);

            if (!supportedTypes.Contains(paramType))
            {
                var label = new Label {
                    text = param.name + "     (" + paramType.Name + ")"
                };
                label.style.marginLeft   = 3;
                label.style.marginTop    = 1;
                label.style.marginBottom = 1;
                prop.Add(label);
            }
            else
            {
                var field = FieldFactory.CreateField(paramType, param.serializedValue.value, (newValue) =>
                {
                    Undo.RegisterCompleteObjectUndo(graph, "Changed Parameter " + param.name + " to " + newValue);
                    param.serializedValue.value = newValue;
                }, param.name);
                prop.Add(field);
            }

            paramContainer.Add(prop);
        }
예제 #3
0
        protected void AddControlField(FieldInfo field, string label = null)
        {
            if (field == null)
            {
                return;
            }

            var element = FieldFactory.CreateField(field.FieldType, field.GetValue(nodeTarget), (newValue) => {
                owner.RegisterCompleteObjectUndo("Updated " + newValue);
                field.SetValue(nodeTarget, newValue);
            }, label);

            if (element != null)
            {
                controlsContainer.Add(element);
            }
        }
예제 #4
0
        public virtual void DrawDefaultInspector()
        {
            var fields = nodeTarget.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (var field in fields)
            {
                //skip if the field is not serializable
                if (!field.IsPublic && field.GetCustomAttribute(typeof(SerializeField)) == null)
                {
                    continue;
                }

                //skip if the field is an input/output and not marked as SerializedField
                if (field.GetCustomAttribute(typeof(SerializeField)) == null && (field.GetCustomAttribute(typeof(InputAttribute)) != null || field.GetCustomAttribute(typeof(OutputAttribute)) != null))
                {
                    continue;
                }

                //skip if marked with NonSerialized or HideInInspector
                if (field.GetCustomAttribute(typeof(System.NonSerializedAttribute)) != null || field.GetCustomAttribute(typeof(HideInInspector)) != null)
                {
                    continue;
                }

                var controlLabel = new Label(field.Name);
                controlsContainer.Add(controlLabel);

                var element = FieldFactory.CreateField(field, field.GetValue(nodeTarget), (newValue) => {
                    field.SetValue(nodeTarget, newValue);
                    owner.RegisterCompleteObjectUndo("Updated " + newValue);
                });

                if (element != null)
                {
                    controlsContainer.Add(element);
                }
            }
        }