Пример #1
0
        // Node creation when validate a choice
        public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
        {
            // window to graph position
            var windowRoot          = window.rootVisualElement;
            var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, context.screenMousePosition - window.position.position);
            var graphMousePosition  = graphView.contentViewContainer.WorldToLocal(windowMousePosition);

            var nodeType = searchTreeEntry.userData is Type ? (Type)searchTreeEntry.userData : ((NodeProvider.PortDescription)searchTreeEntry.userData).nodeType;

            graphView.RegisterCompleteObjectUndo("Added " + nodeType);
            var view = graphView.AddNode(BaseNode.CreateFromType(nodeType, graphMousePosition));

            if (searchTreeEntry.userData is NodeProvider.PortDescription desc)
            {
                var targetPort = view.GetPortViewFromFieldName(desc.portFieldName, desc.portIdentifier);
                if (inputPortView == null)
                {
                    graphView.Connect(targetPort, outputPortView);
                }
                else
                {
                    graphView.Connect(inputPortView, targetPort);
                }
            }

            return(true);
        }
Пример #2
0
        protected void AddControlField(FieldInfo field, string label = null, Action valueChangedCallback = null)
        {
            if (field == null)
            {
                return;
            }

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

            if (element != null)
            {
                controlsContainer.Add(element);
            }
        }
Пример #3
0
        // Node creation when validate a choice
        public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
        {
            // window to graph position
            var windowRoot          = window.rootVisualElement;
            var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, context.screenMousePosition - window.position.position);
            var graphMousePosition  = graphView.contentViewContainer.WorldToLocal(windowMousePosition);

            graphView.RegisterCompleteObjectUndo("Added " + searchTreeEntry.userData);
            graphView.AddNode(BaseNode.CreateFromType((Type)searchTreeEntry.userData, graphMousePosition));
            return(true);
        }
Пример #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);
                }
            }
        }
Пример #5
0
        void OnDragPerformEvent(DragPerformEvent evt)
        {
            bool updateList = false;

            int newIndex = GetInsertIndexFromMousePosition(evt.mousePosition);

            foreach (var obj in DragAndDrop.GetGenericData("DragSelection") as List <ISelectable> )
            {
                if (obj is ExposedParameterFieldView view)
                {
                    if (!updateList)
                    {
                        graphView.RegisterCompleteObjectUndo("Moved parameters");
                    }

                    int oldIndex  = graphView.graph.exposedParameters.FindIndex(e => e == view.parameter);
                    var parameter = graphView.graph.exposedParameters[oldIndex];
                    graphView.graph.exposedParameters.RemoveAt(oldIndex);

                    // Patch new index after the remove operation:
                    if (newIndex > oldIndex)
                    {
                        newIndex--;
                    }

                    graphView.graph.exposedParameters.Insert(newIndex, parameter);

                    updateList = true;
                }
            }

            if (updateList)
            {
                graphView.graph.NotifyExposedParameterListChanged();
                evt.StopImmediatePropagation();
                UpdateParameterList();
            }
        }