static IEnumerable <CreateAllBlockParam> GenerateCreateBlockParams(VFXContextType type) { VFXModelDescriptor <VFXContext> destContext; if (type == VFXContextType.Output) { //Exception: VFXStaticMeshOutput doesn't accept any block, fallback on VFXPlanarPrimitiveOutput destContext = VFXLibrary.GetContexts().Where(t => t.model is VFXPlanarPrimitiveOutput).First(); } else { destContext = VFXLibrary.GetContexts().Where(t => t.model.contextType == type).First(); } var allBlocks = VFXLibrary.GetBlocks().Where(t => t.AcceptParent(destContext.model)); var batchCount = (uint)Math.Ceiling((double)allBlocks.Count() / kMaximumBlockPerContext); for (var batch = 0u; batch < batchCount; batch++) { yield return(new CreateAllBlockParam() { name = string.Format("{0}_Batch_{1}", type, batch.ToString()), destContext = destContext, blocks = allBlocks.Skip((int)batch * (int)kMaximumBlockPerContext).Take((int)kMaximumBlockPerContext) }); } }
private static bool IsExclusiveLink(VFXContextType from, VFXContextType to) { if (from == to) { return(false); } if (from == VFXContextType.Spawner) { return(false); } return(true); }
private static bool CanMixingFrom(VFXContextType from, VFXContextType to, VFXContextType lastFavoriteTo) { if (from == VFXContextType.Init || from == VFXContextType.Update) { if (lastFavoriteTo == VFXContextType.Update) { return(to == VFXContextType.Update); } if (lastFavoriteTo == VFXContextType.Output) { return(to == VFXContextType.Output); } } //No special case outside init output which can't be mixed with output & update return(true); }
private static bool CanMixingTo(VFXContextType from, VFXContextType to, VFXContextType lastFavoriteFrom) { if (to == VFXContextType.Init) { //Init is exclusive either {event, spawner} xor {spawnerGPU}, not both if (lastFavoriteFrom == VFXContextType.Event || lastFavoriteFrom == VFXContextType.Spawner) { return(from == VFXContextType.Event || from == VFXContextType.Spawner); } if (lastFavoriteFrom == VFXContextType.SpawnerGPU) { return(from == VFXContextType.SpawnerGPU); } } else if (to == VFXContextType.Spawner || to == VFXContextType.OutputEvent) { //No special constraint on spawner or output event (gpuEvent isn't allowed anyway) return(true); } //Default case, type transfer aren't expected return(from == to && to == lastFavoriteFrom); }
VFXContextController CreateAllBlocks(VFXContextType type) { var initContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == type).First(); var newContext = m_ViewController.AddVFXContext(new Vector2(300, 2000), initContextDesc); m_ViewController.ApplyChanges(); var contextController = m_ViewController.nodes.Where(t => t is VFXContextController && (t as VFXContextController).model == newContext).First() as VFXContextController; Assert.AreEqual(contextController.model, newContext); // Adding every block compatible with an init context var newBlocks = new List <VFXBlock>(); foreach (var block in VFXLibrary.GetBlocks().Where(t => t.AcceptParent(newContext))) { var newBlock = block.CreateInstance(); contextController.AddBlock(0, newBlock); newBlocks.Add(newBlock); } m_ViewController.ApplyChanges(); foreach (var newBlock in newBlocks) { Assert.AreEqual(contextController.blockControllers.Where(t => t.model == newBlock).Count(), 1, "Failing Block" + newBlock.name + "in context" + newContext.name); var blockController = contextController.blockControllers.Where(t => t.model == newBlock).First() as VFXBlockController; Assert.NotNull(blockController); } return(contextController); }
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(); }
private void CheckContext(VFXContext context, VFXContextType expectedType) { Assert.AreEqual(expectedType, context.contextType); }
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(); }
public VFXContext(VFXContextType contextType) : this(contextType, VFXDataType.None, VFXDataType.None) { }
} // Used by serialization public VFXContext(VFXContextType contextType, VFXDataType inputType, VFXDataType outputType) { m_ContextType = contextType; m_InputType = inputType; m_OutputType = outputType; }
protected ContextTest(VFXContextType type) : base(type, VFXDataType.kParticle, VFXDataType.kParticle) { }