VFXContext PasteContext(VFXViewController controller, ref Context context) { VFXContext newContext = PasteAndInitializeNode <VFXContext>(controller, ref context.node); if (newContext == null) { newContexts.Add(new KeyValuePair <VFXContext, List <VFXBlock> >(null, null)); return(null); } newContext.label = context.label; List <VFXBlock> blocks = new List <VFXBlock>(); foreach (var block in context.blocks) { var blk = block; VFXBlock newBlock = PasteAndInitializeNode <VFXBlock>(null, ref blk); newBlock.enabled = (blk.flags & Node.Flags.Enabled) == Node.Flags.Enabled; blocks.Add(newBlock); if (newBlock != null) { newContext.AddChild(newBlock); } } newContexts.Add(new KeyValuePair <VFXContext, List <VFXBlock> >(newContext, blocks)); return(newContext); }
public VFXBlockController(VFXBlock model, VFXContextController contextController) : base(model, contextController.viewController) { m_ContextController = contextController; if (model is VFXSubgraphBlock) { (model as VFXSubgraphBlock).RecreateCopy(); } }
public VFXBlockController(VFXBlock model, VFXContextController contextController) : base(model, contextController.viewController) { m_ContextController = contextController; if (model is VFXSubgraphBlock) { model.Invalidate(VFXModel.InvalidationCause.kSettingChanged); // Simulate a settings change in case the subgraph parameters has changed. } }
public void CopyPasteBlock() { var initContextDesc = VFXLibrary.GetContexts().Where(t => t.name == "Initialize").First(); var newContext = m_ViewController.AddVFXContext(new Vector2(100, 100), initContextDesc); m_ViewController.ApplyChanges(); Assert.AreEqual(m_ViewController.allChildren.Where(t => t is VFXContextController).Count(), 1); var contextController = m_ViewController.allChildren.OfType <VFXContextController>().First(); Assert.AreEqual(contextController.model, newContext); var flipBookBlockDesc = VFXLibrary.GetBlocks().First(t => t.name == "Set Tex Index "); contextController.AddBlock(0, flipBookBlockDesc.CreateInstance()); var newBlock = contextController.model.children.First(); m_ViewController.ApplyChanges(); VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>(); VFXView view = window.graphView; view.controller = m_ViewController; view.ClearSelection(); foreach (var element in view.Query().OfType <VFXBlockUI>().ToList().OfType <ISelectable>()) { view.AddToSelection(element); } VFXBlock flipBookBlock = m_ViewController.contexts.First().blockControllers.First().model; VFXSlot minValueSlot = flipBookBlock.GetInputSlot(0); float originalMinValue = 123.456f; minValueSlot.value = originalMinValue; view.CopySelectionCallback(); minValueSlot.value = 789f; view.PasteCallback(); view.controller.ApplyChanges(); var elements = view.Query().OfType <VFXBlockUI>().ToList(); var copyBlock = elements.Select(t => t.controller).First(t => t.model != newBlock).model; var copyMinSlot = copyBlock.GetInputSlot(0); Assert.AreEqual((float)copyMinSlot.value, originalMinValue); }
public static string GetLoadAttributeCode(VFXBlock block, VFXAttribute attribute, string name, string index) { var r = new VFXShaderWriter(); var layout = new StructureOfArrayProvider(); r.WriteVariable(attribute.type, name, block.GetData().GetLoadAttributeCode(attribute, VFXAttributeLocation.Current)); var result = r.builder.ToString().Replace("(index *", $"({index} *"); return(result); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (VFXViewPreference.displayExtraDebugInfo && !serializedObject.isEditingMultipleObjects) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel); VFXBlock block = serializedObject.targetObject as VFXBlock; using (new GUILayout.HorizontalScope()) { GUILayout.Label(Contents.name, Styles.header); GUILayout.Label(Contents.type, Styles.header, GUILayout.Width(80)); GUILayout.Label(Contents.mode, Styles.header, GUILayout.Width(80)); } foreach (var attribute in block.attributes) { using (new GUILayout.HorizontalScope()) { GUILayout.Label(attribute.attrib.name, Styles.cell); Styles.DataTypeLabel(attribute.attrib.type.ToString(), attribute.attrib.type, Styles.cell, GUILayout.Width(80)); Styles.AttributeModeLabel(attribute.mode.ToString(), attribute.mode, Styles.cell, GUILayout.Width(80)); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Parameters", EditorStyles.boldLabel); using (new GUILayout.HorizontalScope()) { GUILayout.Label(Contents.name, Styles.header); GUILayout.Label(Contents.type, Styles.header, GUILayout.Width(160)); } foreach (var param in block.parameters) { using (new GUILayout.HorizontalScope()) { GUILayout.Label(param.name, Styles.cell); Styles.DataTypeLabel(param.exp.valueType.ToString(), param.exp.valueType, Styles.cell, GUILayout.Width(160)); } } if (!string.IsNullOrEmpty(block.source)) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Computed Source Code", EditorStyles.boldLabel); EditorGUILayout.TextArea(block.source); } } }
public void ReorderBlock(int index, VFXBlock block) { if (block.GetParent() == base.model && model.GetIndex(block) < index) { --index; } if (index < 0 || index >= base.model.GetNbChildren()) { index = -1; } model.AddChild(block, index); }
void OnDragPerform(DragPerformEvent evt) { RemoveDragIndicator(); if (DragAndDrop.GetGenericData("DragSelection") != null) { Vector2 mousePosition = m_BlockContainer.WorldToLocal(evt.mousePosition); IEnumerable <VFXBlockUI> blocksUI = (DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>).Select(t => t as VFXBlockUI).Where(t => t != null); if (!CanDrop(blocksUI)) { return; } int blockIndex = GetDragBlockIndex(mousePosition); BlocksDropped(blockIndex, blocksUI, evt.ctrlKey); DragAndDrop.AcceptDrag(); m_DragStarted = false; RemoveFromClassList("dropping"); } else { var references = DragAndDrop.objectReferences.OfType <VisualEffectSubgraphBlock>(); if (references.Count() > 0 && (!controller.viewController.model.isSubgraph || !references.Any(t => t.GetResource().GetOrCreateGraph().subgraphDependencies.Contains(controller.viewController.model.subgraph) || t.GetResource() == controller.viewController.model))) { var context = references.First().GetResource().GetOrCreateGraph().children.OfType <VFXBlockSubgraphContext>().FirstOrDefault(); if (context != null && (context.compatibleContextType & controller.model.contextType) == controller.model.contextType) { DragAndDrop.AcceptDrag(); Vector2 mousePosition = m_BlockContainer.WorldToLocal(evt.mousePosition); int blockIndex = GetDragBlockIndex(mousePosition); VFXBlock newModel = ScriptableObject.CreateInstance <VFXSubgraphBlock>(); newModel.SetSettingValue("m_Subgraph", references.First()); controller.AddBlock(blockIndex, newModel); } evt.StopPropagation(); } } m_DragStarted = false; RemoveFromClassList("dropping"); }
public void RemoveBlock(VFXBlock block) { model.RemoveChild(block); VFXSlot slotToClean = null; do { slotToClean = block.inputSlots.Concat(block.outputSlots).FirstOrDefault(o => o.HasLink(true)); if (slotToClean) { slotToClean.UnlinkAll(true, true); } }while (slotToClean != null); }
public void AddBlock(int index, VFXBlock block, bool initSpace = false) { if (initSpace) { if (model.spaceable && block.inputSlots.Any(o => o.spaceable)) { var contextSpace = model.space; foreach (var inputSlot in block.inputSlots) { inputSlot.space = contextSpace; } } } model.AddChild(block, index); }
public VFXBlockController(VFXBlock model, VFXContextController contextController) : base(model, contextController.viewController) { m_ContextController = contextController; if (model is VFXSubgraphBlock) { // Prevent breaking the editor opening. try { (model as VFXSubgraphBlock).RecreateCopy(); } catch (Exception e) { Debug.LogException(e); } } }
private int PasteBlocks(VFXViewController viewController, Node[] blocks, VFXContext targetModelContext, int targetIndex, List <VFXBlockController> blocksInTheSameOrder = null) { newControllers.Clear(); m_NodesInTheSameOrder = new VFXNodeID[blocks.Length]; int cpt = 0; foreach (var block in blocks) { Node blk = block; VFXBlock newBlock = PasteAndInitializeNode <VFXBlock>(viewController, Vector2.zero, Rect.zero, ref blk); newBlock.enabled = (blk.flags & Node.Flags.Enabled) == Node.Flags.Enabled; if (targetModelContext.AcceptChild(newBlock, targetIndex)) { m_NodesInTheSameOrder[cpt] = new VFXNodeID(newBlock, 0); targetModelContext.AddChild(newBlock, targetIndex, false); // only notify once after all blocks have been added targetIndex++; } ++cpt; } targetModelContext.Invalidate(VFXModel.InvalidationCause.kStructureChanged); var targetContextController = viewController.GetRootNodeController(targetModelContext, 0) as VFXContextController; targetContextController.ApplyChanges(); if (blocksInTheSameOrder != null) { blocksInTheSameOrder.Clear(); for (int i = 0; i < m_NodesInTheSameOrder.Length; ++i) { blocksInTheSameOrder.Add(m_NodesInTheSameOrder[i].model != null ? targetContextController.blockControllers.First(t => t.model == m_NodesInTheSameOrder[i].model as VFXBlock) : null); } } return(targetIndex); }
static VFXBlock DuplicateBlock(VFXBlock block) { var dependencies = new HashSet <ScriptableObject>(); dependencies.Add(block); block.CollectDependencies(dependencies); var duplicated = VFXMemorySerializer.DuplicateObjects(dependencies.ToArray()); VFXBlock result = duplicated.OfType <VFXBlock>().First(); foreach (var slot in result.inputSlots) { slot.UnlinkAll(true, false); } foreach (var slot in result.outputSlots) { slot.UnlinkAll(true, false); } return(result); }
VFXContext PasteContext(VFXViewController controller, ref Context context) { VFXContext newContext = PasteAndInitializeNode <VFXContext>(controller, ref context.node); if (newContext == null) { newContexts.Add(new KeyValuePair <VFXContext, List <VFXBlock> >(null, null)); return(null); } newContext.label = context.label; VFXSystemNames.SetSystemName(newContext, context.systemName); if (newContext is VFXAbstractRenderedOutput) { PasteSubOutputs((VFXAbstractRenderedOutput)newContext, ref context); } List <VFXBlock> blocks = new List <VFXBlock>(); foreach (var block in context.blocks) { var blk = block; VFXBlock newBlock = PasteAndInitializeNode <VFXBlock>(null, ref blk); newBlock.enabled = (blk.flags & Node.Flags.Enabled) == Node.Flags.Enabled; blocks.Add(newBlock); if (newBlock != null) { newContext.AddChild(newBlock); } } newContexts.Add(new KeyValuePair <VFXContext, List <VFXBlock> >(newContext, blocks)); return(newContext); }
internal static IEnumerable <VFXNamedExpression> GetSolverDataExpressions(VFXBlock block) { var context = block.GetParent(); var data = context.GetData(); var initializeBlock = data.owners .SelectMany((c) => c.activeChildrenWithImplicit, (_, b) => b) .FirstOrDefault((b) => b.GetType() == typeof(InitializeSolver)); if (initializeBlock) { return(initializeBlock.parameters.Where((expression) => !expression.name.Contains("_Tex"))); } else { var solverData = SolverData.defaultValue; return(solverData.defaultExpressions.Select((expression) => { expression.name = $"solverData_{expression.name}"; return expression; })); } }
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(); }
internal static IEnumerable <VFXNamedExpression> GetExpressions( VFXBlock block, SolverDataParameters?solverDataParamsOverride = null ) { List <VFXNamedExpression> fluid = null; VFXExpression h = null; VFXExpression mass = null; VFXExpression density = null; VFXExpression gravity = null; var initializeBlock = block as InitializeSolver; if (initializeBlock == null) { var context = block.GetParent(); var data = context.GetData(); initializeBlock = data.owners .SelectMany((c) => c.activeChildrenWithImplicit, (_, b) => b) .FirstOrDefault((b) => b.GetType() == typeof(InitializeSolver)) as InitializeSolver; } if (initializeBlock) { fluid = new List <VFXNamedExpression>(); foreach (var expression in GetExpressionsFromSlots(initializeBlock)) { if (expression.name == $"{nameof(InputProperties.Fluid)}_{nameof(Fluid.SmoothingDistance)}") { // We use solverData_KernelSize instead h = expression.exp; continue; } else if (expression.name == $"{nameof(InputProperties.Fluid)}_{nameof(Fluid.ParticleMass)}") { mass = expression.exp; } else if (expression.name == $"{nameof(InputProperties.Fluid)}_{nameof(Fluid.Density)}") { density = expression.exp; } else if (expression.name == $"{nameof(InputProperties.Gravity)}") { // We'll add solverData_Gravity in separately gravity = expression.exp; continue; } fluid.Add(expression); } } var fluvioFxBlock = block as FluvioFXBlock; var expressions = GetExpressionsImpl( initializeBlock, solverDataParamsOverride ?? fluvioFxBlock?.solverDataParameters ?? SolverDataParameters.All, fluid, h, mass, density, gravity); foreach (var expression in expressions) { yield return(expression); } }
public void RemoveBlock(VFXBlock block) { model.RemoveChild(block); VFXModel.UnlinkModel(block); }
public VFXBlockController(VFXBlock model, VFXContextController contextController) : base(model, contextController.viewController) { m_ContextController = contextController; }
static void CopyDataEdge(Data copyData, IEnumerable <VFXDataEdgeController> dataEdges, ScriptableObject[] allSerializedObjects) { copyData.dataEdges = new DataEdge[dataEdges.Count()]; int cpt = 0; var orderedEdges = new List <VFXDataEdgeController>(); var edges = new HashSet <VFXDataEdgeController>(dataEdges); // Ensure that operators that can change shape always all their input edges created before their output edges and in the same order bool sortFailed = false; try { while (edges.Count > 0) { var edgeInputs = edges.GroupBy(t => t.input.sourceNode).ToDictionary(t => t.Key, t => t.Select(u => u)); //Select the edges that have an input node which all its input edges have an output node that have no input edge // Order them by index var edgesWithoutParent = edges.Where(t => !edgeInputs[t.input.sourceNode].Any(u => edgeInputs.ContainsKey(u.output.sourceNode))).OrderBy(t => t.input.model.GetMasterSlot().owner.GetSlotIndex(t.input.model.GetMasterSlot())).ToList(); /*foreach(var gen in edgesWithoutParent) * { * int index = gen.input.model.GetMasterSlot().owner.GetSlotIndex(gen.input.model.GetMasterSlot()); * Debug.Log("Edge with input:" + gen.input.sourceNode.title + "index"+ index); * }*/ orderedEdges.AddRange(edgesWithoutParent); int count = edges.Count; foreach (var e in edgesWithoutParent) { edges.Remove(e); } if (edges.Count >= count) { sortFailed = true; Debug.LogError("Sorting of data edges failed. Please provide a screenshot of the graph with the selected node to @tristan"); break; } //Debug.Log("------------------------------"); } } catch (Exception e) { Debug.LogError("Sorting of data edges threw. Please provide a screenshot of the graph with the selected node to @tristan" + e.Message); sortFailed = true; } IEnumerable <VFXDataEdgeController> usedEdges = sortFailed ? dataEdges : orderedEdges; foreach (var edge in usedEdges) { DataEdge copyPasteEdge = new DataEdge(); var inputController = edge.input as VFXDataAnchorController; var outputController = edge.output as VFXDataAnchorController; copyPasteEdge.input.slotPath = MakeSlotPath(inputController.model, true); if (inputController.model.owner is VFXContext) { VFXContext context = inputController.model.owner as VFXContext; copyPasteEdge.inputContext = true; copyPasteEdge.input.targetIndex = System.Array.IndexOf(allSerializedObjects, context); copyPasteEdge.inputBlockIndex = -1; } else if (inputController.model.owner is VFXBlock) { VFXBlock block = inputController.model.owner as VFXBlock; copyPasteEdge.inputContext = true; copyPasteEdge.input.targetIndex = System.Array.IndexOf(allSerializedObjects, block.GetParent()); copyPasteEdge.inputBlockIndex = block.GetParent().GetIndex(block); } else { copyPasteEdge.inputContext = false; copyPasteEdge.input.targetIndex = System.Array.IndexOf(allSerializedObjects, inputController.model.owner as VFXModel); copyPasteEdge.inputBlockIndex = -1; } if (outputController.model.owner is VFXParameter) { copyPasteEdge.outputParameter = true; copyPasteEdge.outputParameterIndex = System.Array.FindIndex(copyData.parameters, t => (IVFXSlotContainer)t.parameter == outputController.model.owner); copyPasteEdge.outputParameterNodeIndex = System.Array.IndexOf(copyData.parameters[copyPasteEdge.outputParameterIndex].infos, (outputController.sourceNode as VFXParameterNodeController).infos); } else { copyPasteEdge.outputParameter = false; } copyPasteEdge.output.slotPath = MakeSlotPath(outputController.model, false); copyPasteEdge.output.targetIndex = System.Array.IndexOf(allSerializedObjects, outputController.model.owner as VFXModel); copyData.dataEdges[cpt++] = copyPasteEdge; } // Sort the edge so the one that links the node that have the least links }
public void CopyPasteContextWithBlock() { var initContextDesc = VFXLibrary.GetContexts().Where(t => t.name == "Initialize").First(); var newContext = m_ViewController.AddVFXContext(new Vector2(100, 100), initContextDesc); m_ViewController.ApplyChanges(); Assert.AreEqual(m_ViewController.allChildren.Where(t => t is VFXContextController).Count(), 1); var contextController = m_ViewController.allChildren.OfType <VFXContextController>().First(); Assert.AreEqual(contextController.model, newContext); var flipBookBlockDesc = VFXLibrary.GetBlocks().First(t => t.name == "Set Tex Index "); contextController.AddBlock(0, flipBookBlockDesc.CreateInstance()); m_ViewController.ApplyChanges(); VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>(); VFXView view = window.graphView; view.controller = m_ViewController; view.ClearSelection(); foreach (var element in view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>()) { view.AddToSelection(element); } VFXSlot boundsSlot = newContext.GetInputSlot(0); AABox originalBounds = new AABox() { center = Vector3.one, size = Vector3.one * 10 }; boundsSlot.value = originalBounds; VFXBlock flipBookBlock = m_ViewController.contexts.First().blockControllers.First().model; VFXSlot minValueSlot = flipBookBlock.GetInputSlot(0); float originalMinValue = 123.456f; minValueSlot.value = originalMinValue; view.CopySelectionCallback(); boundsSlot.value = new AABox() { center = Vector3.zero, size = Vector3.zero }; minValueSlot.value = 789f; view.PasteCallback(); var elements = view.Query().OfType <GraphElement>().ToList(); var contexts = elements.OfType <VFXContextUI>().ToArray(); var copyContext = elements.OfType <VFXContextUI>().Select(t => t.controller).First(t => t.model != newContext).model; var copyBoundsSlot = copyContext.GetInputSlot(0); var copyMinSlot = copyContext[0].GetInputSlot(0); Assert.AreEqual((AABox)copyBoundsSlot.value, originalBounds); Assert.AreEqual((float)copyMinSlot.value, originalMinValue); Assert.AreNotEqual(copyContext.position, newContext.position); view.PasteCallback(); elements = view.Query().OfType <GraphElement>().ToList(); contexts = elements.OfType <VFXContextUI>().ToArray(); var copy2Context = contexts.First(t => t.controller.model != newContext && t.controller.model != copyContext).controller.model; Assert.AreNotEqual(copy2Context.position, newContext.position); Assert.AreNotEqual(copy2Context.position, copyContext.position); }
void PasteBlocks(VFXView view, ref SerializableGraph serializableGraph) { var selectedContexts = view.selection.OfType <VFXContextUI>(); var selectedBlocks = view.selection.OfType <VFXBlockUI>(); VFXBlockUI targetBlock = null; VFXContextUI targetContext = null; if (selectedBlocks.Count() > 0) { targetBlock = selectedBlocks.OrderByDescending(t => t.context.controller.model.GetIndex(t.controller.model)).First(); targetContext = targetBlock.context; } else if (selectedContexts.Count() == 1) { targetContext = selectedContexts.First(); } else { Debug.LogError(m_BlockPasteError.text); return; } VFXContext targetModelContext = targetContext.controller.model; int targetIndex = -1; if (targetBlock != null) { targetIndex = targetModelContext.GetIndex(targetBlock.controller.model) + 1; } var newBlocks = new HashSet <VFXBlock>(); newControllers.Clear(); foreach (var block in serializableGraph.operatorsOrBlocks) { Node blk = block; VFXBlock newBlock = PasteAndInitializeNode <VFXBlock>(view.controller, ref blk); if (targetModelContext.AcceptChild(newBlock, targetIndex)) { newBlocks.Add(newBlock); targetModelContext.AddChild(newBlock, targetIndex, false); // only notify once after all blocks have been added targetIndex++; } } targetModelContext.Invalidate(VFXModel.InvalidationCause.kStructureChanged); //TODO fill infos.indexToController for when external links will be optionally copied. view.ClearSelection(); foreach (var uiBlock in targetContext.Query().OfType <VFXBlockUI>().Where(t => newBlocks.Contains(t.controller.model)).ToList()) { view.AddToSelection(uiBlock); } }
public void AddBlock(int index, VFXBlock block) { model.AddChild(block, index); }