コード例 #1
0
        protected override void SelfChange()
        {
            base.SelfChange();

            Profiler.BeginSample("VFXContextUI.CreateBlockProvider");
            if (m_BlockProvider == null)
            {
                m_BlockProvider = new VFXBlockProvider(controller, (d, mPos) =>
                {
                    if (d is VFXBlockProvider.NewBlockDescriptor)
                    {
                        AddBlock(mPos, (d as VFXBlockProvider.NewBlockDescriptor).newBlock);
                    }
                    else
                    {
                        var subgraphBlock = AssetDatabase.LoadAssetAtPath <VisualEffectSubgraphBlock>((d as VFXBlockProvider.SubgraphBlockDescriptor).item.path);

                        int blockIndex    = GetDragBlockIndex(mPos);
                        VFXBlock newModel = ScriptableObject.CreateInstance <VFXSubgraphBlock>();

                        newModel.SetSettingValue("m_Subgraph", subgraphBlock);

                        controller.AddBlock(blockIndex, newModel);
                    }
                });
            }
            Profiler.EndSample();

            if (inputContainer.childCount == 0 && !hasSettings)
            {
                mainContainer.AddToClassList("empty");
            }
            else
            {
                mainContainer.RemoveFromClassList("empty");
            }

            m_Divider.visible = hasSettings;

            m_HeaderIcon.image   = GetIconForVFXType(controller.model.inputType);
            m_HeaderIcon.visible = m_HeaderIcon.image != null;


            Profiler.BeginSample("VFXContextUI.SetAllStyleClasses");

            VFXContextType contextType = controller.model.contextType;

            foreach (VFXContextType value in System.Enum.GetValues(typeof(VFXContextType)))
            {
                if (value != contextType)
                {
                    RemoveFromClassList(ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList(ContextEnumToClassName(contextType.ToString()));

            var inputType = controller.model.inputType;

            if (inputType == VFXDataType.None)
            {
                inputType = controller.model.ownedType;
            }
            foreach (VFXDataType value in System.Enum.GetValues(typeof(VFXDataType)))
            {
                if (inputType != value)
                {
                    RemoveFromClassList("inputType" + ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList("inputType" + ContextEnumToClassName(inputType.ToString()));

            var outputType = controller.model.outputType;

            foreach (VFXDataType value in System.Enum.GetValues(typeof(VFXDataType)))
            {
                if (value != outputType)
                {
                    RemoveFromClassList("outputType" + ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList("outputType" + ContextEnumToClassName(outputType.ToString()));

            var type = controller.model.ownedType;

            foreach (VFXDataType value in System.Enum.GetValues(typeof(VFXDataType)))
            {
                if (value != type)
                {
                    RemoveFromClassList("type" + ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList("type" + ContextEnumToClassName(type.ToString()));

            var space = controller.model.space;

            foreach (VFXCoordinateSpace val in System.Enum.GetValues(typeof(VFXCoordinateSpace)))
            {
                if (val != space || !controller.model.spaceable)
                {
                    m_HeaderSpace.RemoveFromClassList("space" + val.ToString());
                }
            }
            if (controller.model.spaceable)
            {
                m_HeaderSpace.AddToClassList("space" + (controller.model.space).ToString());
            }

            Profiler.EndSample();
            if (controller.model.outputType == VFXDataType.None)
            {
                if (m_Footer.parent != null)
                {
                    m_Footer.RemoveFromHierarchy();
                }
            }
            else
            {
                if (m_Footer.parent == null)
                {
                    mainContainer.Add(m_Footer);
                }
                m_FooterTitle.text   = controller.model.outputType.ToString();
                m_FooterIcon.image   = GetIconForVFXType(controller.model.outputType);
                m_FooterIcon.visible = m_FooterIcon.image != null;
            }

            Profiler.BeginSample("VFXContextUI.CreateInputFlow");
            HashSet <VisualElement> newInAnchors = new HashSet <VisualElement>();

            foreach (var inanchorcontroller in controller.flowInputAnchors)
            {
                var existing = m_FlowInputConnectorContainer.Children().Select(t => t as VFXFlowAnchor).FirstOrDefault(t => t.controller == inanchorcontroller);
                if (existing == null)
                {
                    var anchor = VFXFlowAnchor.Create(inanchorcontroller);
                    m_FlowInputConnectorContainer.Add(anchor);
                    newInAnchors.Add(anchor);
                }
                else
                {
                    newInAnchors.Add(existing);
                }
            }

            foreach (var nonLongerExistingAnchor in m_FlowInputConnectorContainer.Children().Where(t => !newInAnchors.Contains(t)).ToList()) // ToList to make a copy because the enumerable will change when we delete
            {
                m_FlowInputConnectorContainer.Remove(nonLongerExistingAnchor);
            }
            Profiler.EndSample();

            Profiler.BeginSample("VFXContextUI.CreateInputFlow");
            HashSet <VisualElement> newOutAnchors = new HashSet <VisualElement>();

            foreach (var outanchorcontroller in controller.flowOutputAnchors)
            {
                var existing = m_FlowOutputConnectorContainer.Children().Select(t => t as VFXFlowAnchor).FirstOrDefault(t => t.controller == outanchorcontroller);
                if (existing == null)
                {
                    var anchor = VFXFlowAnchor.Create(outanchorcontroller);
                    m_FlowOutputConnectorContainer.Add(anchor);
                    newOutAnchors.Add(anchor);
                }
                else
                {
                    newOutAnchors.Add(existing);
                }
            }

            foreach (var nonLongerExistingAnchor in m_FlowOutputConnectorContainer.Children().Where(t => !newOutAnchors.Contains(t)).ToList()) // ToList to make a copy because the enumerable will change when we delete
            {
                m_FlowOutputConnectorContainer.Remove(nonLongerExistingAnchor);
            }
            Profiler.EndSample();

            m_Label.text = controller.model.label;
            if (string.IsNullOrEmpty(m_Label.text))
            {
                m_Label.AddToClassList("empty");
            }
            else
            {
                m_Label.RemoveFromClassList("empty");
            }

            foreach (var inEdge in m_FlowInputConnectorContainer.Children().OfType <VFXFlowAnchor>().SelectMany(t => t.connections))
            {
                inEdge.UpdateEdgeControl();
            }
            foreach (var outEdge in m_FlowOutputConnectorContainer.Children().OfType <VFXFlowAnchor>().SelectMany(t => t.connections))
            {
                outEdge.UpdateEdgeControl();
            }

            RefreshContext();
        }
コード例 #2
0
        protected override void SelfChange()
        {
            base.SelfChange();

            Profiler.BeginSample("VFXContextUI.CreateBlockProvider");
            if (m_BlockProvider == null)
            {
                m_BlockProvider = new VFXBlockProvider(controller, (d, mPos) =>
                {
                    AddBlock(mPos, d);
                });
            }
            Profiler.EndSample();

            if (inputContainer.childCount == 0 && !hasSettings)
            {
                mainContainer.AddToClassList("empty");
            }
            else
            {
                mainContainer.RemoveFromClassList("empty");
            }

            m_HeaderIcon.image   = GetIconForVFXType(controller.model.inputType);
            m_HeaderIcon.visible = m_HeaderIcon.image != null;


            Profiler.BeginSample("VFXContextUI.SetAllStyleClasses");

            VFXContextType contextType = controller.model.contextType;

            foreach (VFXContextType value in System.Enum.GetValues(typeof(VFXContextType)))
            {
                if (value != contextType)
                {
                    RemoveFromClassList(ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList(ContextEnumToClassName(contextType.ToString()));

            var inputType = controller.model.inputType;

            if (inputType == VFXDataType.kNone)
            {
                inputType = controller.model.ownedType;
            }
            foreach (VFXDataType value in System.Enum.GetValues(typeof(VFXDataType)))
            {
                if (inputType != value)
                {
                    RemoveFromClassList("inputType" + ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList("inputType" + ContextEnumToClassName(inputType.ToString()));

            var outputType = controller.model.outputType;

            foreach (VFXDataType value in System.Enum.GetValues(typeof(VFXDataType)))
            {
                if (value != outputType)
                {
                    RemoveFromClassList("outputType" + ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList("outputType" + ContextEnumToClassName(outputType.ToString()));

            var type = controller.model.ownedType;

            foreach (VFXDataType value in System.Enum.GetValues(typeof(VFXDataType)))
            {
                if (value != type)
                {
                    RemoveFromClassList("type" + ContextEnumToClassName(value.ToString()));
                }
            }
            AddToClassList("type" + ContextEnumToClassName(type.ToString()));

            var space = controller.model.space;

            foreach (VFXCoordinateSpace val in System.Enum.GetValues(typeof(VFXCoordinateSpace)))
            {
                if (val != space || !controller.model.spaceable)
                {
                    m_HeaderSpace.RemoveFromClassList("space" + val.ToString());
                }
            }
            if (controller.model.spaceable)
            {
                m_HeaderSpace.AddToClassList("space" + (controller.model.space).ToString());
            }

            Profiler.EndSample();
            if (controller.model.outputType == VFXDataType.kNone)
            {
                if (m_Footer.parent != null)
                {
                    m_Footer.RemoveFromHierarchy();
                }
            }
            else
            {
                if (m_Footer.parent == null)
                {
                    mainContainer.Add(m_Footer);
                }
                m_FooterTitle.text   = controller.model.outputType.ToString().Substring(1);
                m_FooterIcon.image   = GetIconForVFXType(controller.model.outputType);
                m_FooterIcon.visible = m_FooterIcon.image != null;
            }

            Profiler.BeginSample("VFXContextUI.CreateInputFlow");
            HashSet <VisualElement> newInAnchors = new HashSet <VisualElement>();

            foreach (var inanchorcontroller in controller.flowInputAnchors)
            {
                var existing = m_FlowInputConnectorContainer.Children().Select(t => t as VFXFlowAnchor).FirstOrDefault(t => t.controller == inanchorcontroller);
                if (existing == null)
                {
                    var anchor = VFXFlowAnchor.Create(inanchorcontroller);
                    m_FlowInputConnectorContainer.Add(anchor);
                    newInAnchors.Add(anchor);
                }
                else
                {
                    newInAnchors.Add(existing);
                }
            }

            foreach (var nonLongerExistingAnchor in m_FlowInputConnectorContainer.Children().Where(t => !newInAnchors.Contains(t)).ToList()) // ToList to make a copy because the enumerable will change when we delete
            {
                m_FlowInputConnectorContainer.Remove(nonLongerExistingAnchor);
            }
            Profiler.EndSample();

            Profiler.BeginSample("VFXContextUI.CreateInputFlow");
            HashSet <VisualElement> newOutAnchors = new HashSet <VisualElement>();

            foreach (var outanchorcontroller in controller.flowOutputAnchors)
            {
                var existing = m_FlowOutputConnectorContainer.Children().Select(t => t as VFXFlowAnchor).FirstOrDefault(t => t.controller == outanchorcontroller);
                if (existing == null)
                {
                    var anchor = VFXFlowAnchor.Create(outanchorcontroller);
                    m_FlowOutputConnectorContainer.Add(anchor);
                    newOutAnchors.Add(anchor);
                }
                else
                {
                    newOutAnchors.Add(existing);
                }
            }

            foreach (var nonLongerExistingAnchor in m_FlowOutputConnectorContainer.Children().Where(t => !newOutAnchors.Contains(t)).ToList()) // ToList to make a copy because the enumerable will change when we delete
            {
                m_FlowOutputConnectorContainer.Remove(nonLongerExistingAnchor);
            }
            Profiler.EndSample();

            m_Label.text = controller.model.label;
            if (string.IsNullOrEmpty(m_Label.text))
            {
                m_Label.AddToClassList("empty");
            }
            else
            {
                m_Label.RemoveFromClassList("empty");
            }

            RefreshContext();
        }