static VFXUI CopyGroupNodesAndStickyNotes(IEnumerable <Controller> elements, VFXContext[] copiedContexts, VFXModel[] copiedSlotContainers) { VFXGroupNodeController[] groupNodes = elements.OfType <VFXGroupNodeController>().ToArray(); VFXStickyNoteController[] stickyNotes = elements.OfType <VFXStickyNoteController>().ToArray(); VFXUI copiedGroupUI = null; if (groupNodes.Length > 0 || stickyNotes.Length > 0) { copiedGroupUI = ScriptableObject.CreateInstance <VFXUI>(); var stickyNodeIndexToCopiedIndex = new Dictionary <int, int>(); if (stickyNotes.Length > 0) { copiedGroupUI.stickyNoteInfos = new VFXUI.StickyNoteInfo[stickyNotes.Length]; for (int i = 0; i < stickyNotes.Length; ++i) { VFXStickyNoteController stickyNote = stickyNotes[i]; stickyNodeIndexToCopiedIndex[stickyNote.index] = i; VFXUI.StickyNoteInfo info = stickyNote.model.stickyNoteInfos[stickyNote.index]; copiedGroupUI.stickyNoteInfos[i] = new VFXUI.StickyNoteInfo(info); } } if (groupNodes.Length > 0) { copiedGroupUI.groupInfos = new VFXUI.GroupInfo[groupNodes.Length]; for (int i = 0; i < groupNodes.Length; ++i) { VFXGroupNodeController groupNode = groupNodes[i]; VFXUI.GroupInfo info = groupNode.model.groupInfos[groupNode.index]; copiedGroupUI.groupInfos[i] = new VFXUI.GroupInfo(info); // only keep nodes and sticky notes that are copied because a element can not be in two groups at the same time. if (info.contents != null) { var groupInfo = copiedGroupUI.groupInfos[i]; groupInfo.contents = info.contents.Where(t => copiedContexts.Contains(t.model) || copiedSlotContainers.Contains(t.model) || (t.isStickyNote && stickyNodeIndexToCopiedIndex.ContainsKey(t.id))).ToArray(); for (int j = 0; j < groupInfo.contents.Length; ++j) { if (groupInfo.contents[j].isStickyNote) { groupInfo.contents[j].id = stickyNodeIndexToCopiedIndex[groupInfo.contents[j].id]; } } } } } } return(copiedGroupUI); }
void CopyGroupNodesAndStickyNotes(ref SerializableGraph serializableGraph, IEnumerable <Controller> elements) { VFXGroupNodeController[] groupNodes = elements.OfType <VFXGroupNodeController>().ToArray(); VFXStickyNoteController[] stickyNotes = elements.OfType <VFXStickyNoteController>().ToArray(); if (groupNodes.Length > 0 || stickyNotes.Length > 0) { var stickyNodeIndexToCopiedIndex = new Dictionary <int, int>(); if (stickyNotes.Length > 0) { serializableGraph.stickyNotes = new VFXUI.StickyNoteInfo[stickyNotes.Length]; for (int i = 0; i < stickyNotes.Length; ++i) { VFXStickyNoteController stickyNote = stickyNotes[i]; stickyNodeIndexToCopiedIndex[stickyNote.index] = i; VFXUI.StickyNoteInfo info = stickyNote.model.stickyNoteInfos[stickyNote.index]; serializableGraph.stickyNotes[i] = new VFXUI.StickyNoteInfo(info); } } if (groupNodes.Length > 0) { serializableGraph.groupNodes = new GroupNode[groupNodes.Length]; for (int i = 0; i < groupNodes.Length; ++i) { VFXGroupNodeController groupNode = groupNodes[i]; VFXUI.GroupInfo info = groupNode.model.groupInfos[groupNode.index]; serializableGraph.groupNodes[i] = new GroupNode { infos = new VFXUI.UIInfo(info) }; // only keep nodes and sticky notes that are copied because a element can not be in two groups at the same time. if (info.contents != null) { var nodeIndices = groupNode.nodes.OfType <VFXNodeController>().Where(t => contexts.Contains(t) || operators.Contains(t) || parameters.Contains(t)).Select(t => modelIndices[t]); var stickNoteIndices = info.contents.Where(t => t.isStickyNote && stickyNodeIndexToCopiedIndex.ContainsKey(t.id)).Select(t => (uint)stickyNodeIndexToCopiedIndex[t.id]); serializableGraph.groupNodes[i].contents = nodeIndices.Concat(stickNoteIndices).ToArray(); serializableGraph.groupNodes[i].stickNodeCount = stickNoteIndices.Count(); } } } } }