Action FocusParticleSystem(string systemName) { var visibleSystems = m_View.systems; Func <Experimental.GraphView.GraphElement, Action> focus = (elt) => { return(() => { Rect rectToFit = elt.GetPosition(); var frameTranslation = Vector3.zero; var frameScaling = Vector3.one; if (rectToFit.width <= 50 || rectToFit.height <= 50) { return; } VFXView.CalculateFrameTransform(rectToFit, m_View.layout, 30, out frameTranslation, out frameScaling); Matrix4x4.TRS(frameTranslation, Quaternion.identity, frameScaling); m_View.UpdateViewTransform(frameTranslation, frameScaling); m_View.contentViewContainer.MarkDirtyRepaint(); }); }; foreach (var system in visibleSystems) { if (system.controller.title == systemName) { return(focus(system)); } } var subgraphs = m_View.GetAllContexts().Where(c => c.controller.model.contextType == VFXContextType.Subgraph); var models = new HashSet <ScriptableObject>(); foreach (var subgraph in subgraphs) { models.Clear(); subgraph.controller.model.CollectDependencies(models, false); var subSystems = models.OfType <VFXContext>() .Where(c => c.contextType == VFXContextType.Spawner || c.GetData() != null) .Select(c => c.contextType == VFXContextType.Spawner ? c as VFXModel : c.GetData()) .Distinct().ToList(); foreach (var subSystem in subSystems) { if (m_View.controller.graph.systemNames.GetUniqueSystemName(subSystem) == systemName) { return(focus(subgraph)); } } } return(() => {}); }
public void RefreshInitializeErrors() { var viewContexts = m_View.GetAllContexts(); List <VFXContextUI> contextsToRefresh = new List <VFXContextUI>(); foreach (var context in viewContexts) { if (context.controller.model is VFXBasicInitialize) { contextsToRefresh.Add(context); } } foreach (var context in contextsToRefresh) { context.controller.model.RefreshErrors(m_View.controller.graph); } }
public IEnumerator CopyPast_Context_And_Relink([ValueSource("cutBeforeSource")] CutBefore cutBeforeEncapsultor) { VFXTaskType curBeforeSource = cutBeforeEncapsultor.taskType; EditorApplication.ExecuteMenuItem("Window/General/Game"); var graph = MakeTemporaryGraph(); var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var basicInitialize = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var basicUpdate = ScriptableObject.CreateInstance <VFXBasicUpdate>(); var quadOutput = ScriptableObject.CreateInstance <VFXQuadOutput>(); var arrayOfContext = new VFXContext[] { spawnerContext, basicInitialize, basicUpdate, quadOutput }; quadOutput.SetSettingValue("blendMode", VFXAbstractParticleOutput.BlendMode.Additive); var setPosition = ScriptableObject.CreateInstance <SetAttribute>(); //only needed to allocate a minimal attributeBuffer setPosition.SetSettingValue("attribute", "position"); basicInitialize.AddChild(setPosition); var capacity = 2u; //(basicInitialize.GetData() as VFXDataParticle).capacity = capacity; //voluntary overflow in case of capacity is not correctly copied basicInitialize.SetSettingValue("capacity", 2u); // pass through regular way to change capacity to have initialize and data up to date var spawnerBurst = ScriptableObject.CreateInstance <VFXSpawnerBurst>(); spawnerBurst.inputSlots[0].value = 4.0f; spawnerContext.AddChild(spawnerBurst); graph.AddChild(spawnerContext); graph.AddChild(basicInitialize); graph.AddChild(basicUpdate); graph.AddChild(quadOutput); basicInitialize.LinkFrom(spawnerContext); basicUpdate.LinkFrom(basicInitialize); quadOutput.LinkFrom(basicUpdate); m_ViewController.NotifyUpdate(); Assert.AreEqual(4, m_View.GetAllContexts().Count()); //Copy partially in two passes var indexOffset = cutBeforeSource.Select((o, i) => new { o = o, i = i }).Where(o => o.o.taskType == curBeforeSource).Select(o => o.i).First(); var contextToCopy_A = arrayOfContext.Skip(indexOffset).Select(o => m_View.GetAllContexts().Where(u => u.controller.model == o).First() as UnityEditor.Experimental.GraphView.GraphElement); foreach (var graphElement in contextToCopy_A) { m_View.AddToSelection(graphElement); } m_View.DuplicateSelectionCallback(); m_View.ClearSelection(); m_ViewController.NotifyUpdate(); if (indexOffset > 0) { var contextToCopy_B = arrayOfContext.Take(indexOffset).Select(o => m_View.GetAllContexts().Where(u => u.controller.model == o).First() as UnityEditor.Experimental.GraphView.GraphElement); foreach (var graphElement in contextToCopy_B) { m_View.AddToSelection(graphElement); } m_View.DuplicateSelectionCallback(); m_View.ClearSelection(); } m_ViewController.NotifyUpdate(); Assert.AreEqual(8, m_View.GetAllContexts().Count()); //Restore missing link var allContext = m_View.GetAllContexts().Select(o => o.controller.model).ToArray(); if (indexOffset > 0) { var from = allContext.Last(); var to = allContext[4]; to.LinkFrom(from); } VFXBasicInitialize[] initializes = graph.children.OfType <VFXBasicInitialize>().ToArray(); Assert.AreEqual(2, initializes.Length); Assert.AreEqual(2, (initializes[0].GetData() as VFXDataParticle).capacity); Assert.AreEqual(2, (initializes[1].GetData() as VFXDataParticle).capacity); Assert.AreEqual(2, initializes[0].GetType().GetField("capacity", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(initializes[0])); Assert.AreEqual(2, initializes[1].GetType().GetField("capacity", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(initializes[1])); graph.RecompileIfNeeded(); var gameObj = new GameObject("CreateAssetAndComponentToCopyPastPerfomedWell"); var vfxComponent = gameObj.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; var cameraObj = new GameObject("CreateAssetAndComponentToCopyPastPerfomedWell_Camera"); var camera = cameraObj.AddComponent <Camera>(); camera.transform.localPosition = Vector3.one; camera.transform.LookAt(vfxComponent.transform); int maxFrame = 512; while (vfxComponent.culled && --maxFrame > 0) { yield return(null); } Assert.IsTrue(maxFrame > 0); yield return(null); //wait for exactly one more update if visible Assert.AreEqual(capacity * 2, vfxComponent.aliveParticleCount); //Excepted to have two viable equivalent particles system UnityEngine.Object.DestroyImmediate(vfxComponent); UnityEngine.Object.DestroyImmediate(cameraObj); }
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.currentWindow, Event.current.mousePosition - new Vector2(376 * 0.5f * VFXViewWindow.currentWindow.graphView.scale, 0), view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedContext, ProviderFilter, new Type[] { typeof(VFXContext) })); } }