Ejemplo n.º 1
0
        protected void OnEnable()
        {
            VFXManagerEditor.CheckVFXManager();

            graphView = new VFXView();
            graphView.StretchToParentSize();
            SetupFramingShortcutHandler(graphView);

            rootVisualElement.Add(graphView);


            var currentAsset = GetCurrentResource();

            if (currentAsset != null)
            {
                LoadResource(currentAsset);
            }

            autoCompile = true;


            graphView.RegisterCallback <AttachToPanelEvent>(OnEnterPanel);
            graphView.RegisterCallback <DetachFromPanelEvent>(OnLeavePanel);

            if (rootVisualElement.panel != null)
            {
                rootVisualElement.AddManipulator(m_ShortcutHandler);
            }

            currentWindow = this;

#if USE_EXIT_WORKAROUND_FOGBUGZ_1062258
            EditorApplication.wantsToQuit += Quitting_Workaround;
#endif
        }
Ejemplo n.º 2
0
        protected void OnDisable()
        {
#if USE_EXIT_WORKAROUND_FOGBUGZ_1062258
            EditorApplication.wantsToQuit -= Quitting_Workaround;
#endif

            if (graphView != null)
            {
                graphView.UnregisterCallback <AttachToPanelEvent>(OnEnterPanel);
                graphView.UnregisterCallback <DetachFromPanelEvent>(OnLeavePanel);
                graphView.controller = null;
            }
            currentWindow = null;
        }
Ejemplo n.º 3
0
        protected void OnEnable()
        {
            VFXManagerEditor.CheckVFXManager();

            if (m_ResourceHistory == null)
            {
                m_ResourceHistory = new List <VisualEffectResource>();
            }

            graphView = new VFXView();
            graphView.StretchToParentSize();
            SetupFramingShortcutHandler(graphView);

            rootVisualElement.Add(graphView);

            // make sure we don't do something that might touch the model on the view OnEnable because
            // the models OnEnable might be called after in the case of a domain reload.
            m_OnUpdateAction = () =>
            {
                var currentAsset = GetCurrentResource();
                if (currentAsset != null)
                {
                    LoadResource(currentAsset);
                }
            };

            autoCompile = true;

            graphView.RegisterCallback <AttachToPanelEvent>(OnEnterPanel);
            graphView.RegisterCallback <DetachFromPanelEvent>(OnLeavePanel);

            if (rootVisualElement.panel != null)
            {
                rootVisualElement.AddManipulator(m_ShortcutHandler);
            }

            currentWindow = this;

#if USE_EXIT_WORKAROUND_FOGBUGZ_1062258
            EditorApplication.wantsToQuit += Quitting_Workaround;
#endif

            var icon = AssetDatabase.LoadAssetAtPath <Texture2D>(VisualEffectGraphPackageInfo.assetPackagePath + "/Editor Default Resources/VFX/" + (EditorGUIUtility.isProSkin ? "vfx_graph_icon_gray_dark.png" : "vfx_graph_icon_gray_light.png"));
            titleContent.image = icon;
        }
Ejemplo n.º 4
0
        protected void OnEnable()
        {
            VFXManagerEditor.CheckVFXManager();

            if (m_ResourceHistory == null)
            {
                m_ResourceHistory = new List <VisualEffectResource>();
            }

            graphView = new VFXView();
            graphView.StretchToParentSize();
            SetupFramingShortcutHandler(graphView);

            rootVisualElement.Add(graphView);

            // make sure we don't do something that might touch the model on the view OnEnable because
            // the models OnEnable might be called after in the case of a domain reload.
            m_OnUpdateAction = () =>
            {
                var currentAsset = GetCurrentResource();
                if (currentAsset != null)
                {
                    LoadResource(currentAsset);
                }
            };

            autoCompile = true;

            graphView.RegisterCallback <AttachToPanelEvent>(OnEnterPanel);
            graphView.RegisterCallback <DetachFromPanelEvent>(OnLeavePanel);

            if (rootVisualElement.panel != null)
            {
                rootVisualElement.AddManipulator(m_ShortcutHandler);
            }

            currentWindow = this;

#if USE_EXIT_WORKAROUND_FOGBUGZ_1062258
            EditorApplication.wantsToQuit += Quitting_Workaround;
#endif
        }
Ejemplo n.º 5
0
        void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position)
        {
            VFXSlot startSlot = controller.model;

            VFXView           view           = this.GetFirstAncestorOfType <VFXView>();
            VFXViewController viewController = view.controller;


            List <VisualElement> picked = new List <VisualElement>();

            panel.PickAll(position, picked);
            VFXNodeUI endNode = null;

            foreach (var element in picked)
            {
                if (element is VFXNodeUI node)
                {
                    endNode = node;
                    break;
                }
            }


            VFXDataEdge dataEdge = edge as VFXDataEdge;
            bool        exists   = false;

            if (dataEdge.controller != null)
            {
                exists = true;
                view.controller.RemoveElement(dataEdge.controller);
            }

            if (endNode != null)
            {
                VFXNodeController nodeController = endNode.controller;

                if (nodeController != null)
                {
                    IVFXSlotContainer slotContainer = nodeController.slotContainer;
                    if (controller.direction == Direction.Input)
                    {
                        foreach (var output in nodeController.outputPorts.Where(t => t.model == null || t.model.IsMasterSlot()))
                        {
                            if (viewController.CreateLink(controller, output))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var input in nodeController.inputPorts.Where(t => t.model == null || t.model.IsMasterSlot() && !t.model.HasLink(true)))
                        {
                            if (viewController.CreateLink(input, controller))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else if (controller.direction == Direction.Input && Event.current.modifiers == EventModifiers.Alt)
            {
                var targetType = controller.portType;

                var attribute = VFXLibrary.GetAttributeFromSlotType(controller.portType);
                VFXModelDescriptorParameters parameterDesc;
                if (attribute != null && attribute.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty))
                {
                    parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t =>
                    {
                        if (!t.model.outputSlots[0].CanLink(controller.model))
                        {
                            return(false);
                        }
                        var attributeCandidate = VFXLibrary.GetAttributeFromSlotType(t.model.type);
                        return(attributeCandidate == null || !attributeCandidate.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty));
                    });
                }
                else
                {
                    parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t =>
                    {
                        return(t.model.type == targetType);
                    });
                }

                if (parameterDesc != null)
                {
                    Vector2 pos = view.contentViewContainer.GlobalToBound(position) - new Vector2(140, 20);
                    view.UpdateSelectionWithNewNode();
                    VFXParameter parameter = viewController.AddVFXParameter(pos, parameterDesc, false);
                    parameter.SetSettingValue("m_Exposed", true);
                    startSlot.Link(parameter.outputSlots[0]);

                    CopyValueToParameter(parameter);

                    viewController.AddVFXModel(pos, parameter);
                }
            }
            else if (!exists)
            {
                var window = VFXViewWindow.GetWindow(view);

                if (direction == Direction.Input || viewController.model.visualEffectObject is VisualEffectSubgraphOperator || viewController.model.visualEffectObject is VisualEffectSubgraphBlock) // no context for subgraph operators.
                {
                    VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter) }));
                }
                else
                {
                    VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter), typeof(VFXContext) }));
                }
            }
        }
Ejemplo n.º 6
0
        void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position)
        {
            VFXView           view           = this.GetFirstAncestorOfType <VFXView>();
            VFXViewController viewController = view.controller;


            VFXContextUI endContext = null;

            foreach (var node in view.GetAllContexts())
            {
                if (node.worldBound.Contains(position))
                {
                    endContext = node;
                }
            }

            VFXFlowEdge flowEdge = edge as VFXFlowEdge;
            bool        exists   = false;

            if (flowEdge.controller != null)
            {
                view.controller.RemoveElement(flowEdge.controller);
                exists = true;
            }

            if (endContext != null)
            {
                VFXContextController nodeController = endContext.controller;

                var compatibleAnchors = viewController.GetCompatiblePorts(controller, null);

                if (controller.direction == Direction.Input)
                {
                    foreach (var outputAnchor in nodeController.flowOutputAnchors)
                    {
                        if (compatibleAnchors.Contains(outputAnchor))
                        {
                            VFXFlowEdgeController edgeController = new VFXFlowEdgeController(controller, outputAnchor);

                            viewController.AddElement(edgeController);
                            break;
                        }
                    }
                }
                else
                {
                    foreach (var inputAnchor in nodeController.flowInputAnchors)
                    {
                        if (compatibleAnchors.Contains(inputAnchor))
                        {
                            VFXFlowEdgeController edgeController = new VFXFlowEdgeController(inputAnchor, controller);

                            viewController.AddElement(edgeController);
                            break;
                        }
                    }
                }
            }
            else if (!exists)
            {
                VFXFilterWindow.Show(
                    VFXViewWindow.GetWindow(view),
                    Event.current.mousePosition - new Vector2(376 * 0.5f * view.scale, 0),
                    view.ViewToScreenPosition(Event.current.mousePosition),
                    new VFXNodeProvider(viewController, AddLinkedContext, ProviderFilter, new Type[] { typeof(VFXContext) }));
            }
        }
Ejemplo n.º 7
0
 void OnToggleAutoCompile(ChangeEvent <bool> evt)
 {
     VFXViewWindow.GetWindow(m_VFXView).autoCompile = evt.newValue;
 }
Ejemplo n.º 8
0
 protected override void OnOpenPopup()
 {
     m_AutoCompileToggle.value      = VFXViewWindow.GetWindow(m_VFXView).autoCompile;
     m_RuntimeModeToggle.value      = m_VFXView.GetIsRuntimeMode();
     m_ShaderValidationToggle.value = m_VFXView.GetShaderValidation();
 }