void NodeCountChangedCallback(PWNode n) { if (OnGraphStructureChanged != null) { OnGraphStructureChanged(); } }
List <BiomeSwitchData> GetPrecedentSwitchDatas(PWNode currentNode, PWNode rootNode) { var precedentSwitchDatas = new List <BiomeSwitchData>(); PWNode n = currentNode; while (n != rootNode) { PWNode prevNode = n; n = n.GetInputNodes().First(); if (n.GetType() != typeof(PWNodeBiomeSwitch)) { break; } var switches = (n as PWNodeBiomeSwitch).switchList; int index = n.outputAnchors.ToList().FindIndex(a => a.links.Any(l => l.toNode == prevNode)); if (index == -1) { throw new Exception("[PWBiomeSwitchGraph] IMPOSSIBRU !!!!! check your node API !"); } precedentSwitchDatas.Add(switches[index]); } precedentSwitchDatas.Reverse(); return(precedentSwitchDatas); }
public List <PWNode> GetNodeChildsRecursive(PWNode begin) { var nodeStack = new Stack <PWNode>(); var nodesMap = new HashSet <PWNode>(); var nodesList = new List <PWNode>(); nodeStack.Push(begin); while (nodeStack.Count != 0) { var node = nodeStack.Pop(); foreach (var outputNode in node.GetOutputNodes()) { nodeStack.Push(outputNode); } if (node != begin) { if (!nodesMap.Contains(node)) { nodesList.Add(node); } nodesMap.Add(node); } } nodesList.Sort((n1, n2) => n1.computeOrder.CompareTo(n2.computeOrder)); return(nodesList); }
//init defaut values void Init() { isMouseClickOutside = false; isSelecting = false; selectionStartPoint = Vector2.zero; isDraggingSelectedNodes = false; isPanning = false; isZooming = false; isDraggingNewLink = false; startedLinkAnchor = null; selectedNodeCount = 0; isMouseClickOnNode = false; isMouseOverNodeFrame = false; isDraggingNode = false; mouseOverNode = null; isMouseClickOnLink = false; isMouseOverLinkFrame = false; isDraggingLink = false; mouseOverLink = null; isMouseClickOnAnchor = false; isMouseOverAnchorFrame = false; mouseOverAnchor = null; isMouseClickOnOrderingGroup = false; isMouseOverOrderingGroupFrame = false; isDraggingOrderingGroup = false; isResizingOrderingGroup = false; mouseOverOrderingGroup = null; }
float ProcessNode(PWNode node, bool realMode) { float calculTime = 0; //if you are in editor mode, update the process time of the node if (!realMode) { Profiler.BeginSample("[PW] Process node " + node); Stopwatch st = new Stopwatch(); st.Start(); node.Process(); st.Stop(); node.processTime = (float)st.Elapsed.TotalMilliseconds; calculTime = node.processTime; } else { node.Process(); } ProcessNodeLinks(node, realMode); if (!realMode) { Profiler.EndSample(); } return(calculTime); }
//this function will be called twiced, from the two linked anchors // and so will receive two different anchor in parameter public void OnAfterDeserialize(PWAnchor anchor) { if (anchor.anchorType == PWAnchorType.Output) { fromAnchor = anchor; } else { toAnchor = anchor; } if (fromAnchor != null) { fromNode = fromAnchor.nodeRef; } if (toAnchor != null) { toNode = toAnchor.nodeRef; } //update link color: if (fromAnchor != null) { colorSchemeName = fromAnchor.colorSchemeName; } }
//called once (when link is created only) public void Initialize(PWAnchor fromAnchor, PWAnchor toAnchor) { this.fromAnchor = fromAnchor; this.toAnchor = toAnchor; fromNode = fromAnchor.nodeRef; toNode = toAnchor.nodeRef; GUID = System.Guid.NewGuid().ToString(); }
void InsertNodeIfNotExists(List <PWNodeProcessInfo> toComputeList, PWNode node) { if (toComputeList.Any(i => i.node.nodeId == node.nodeId)) { return; } toComputeList.Insert(0, new PWNodeProcessInfo(node, FindGraphNameFromExternalNode(node))); }
void Init(PWAnchorField anchorField) { if (anchorField == null) { Debug.LogWarning("Null anchor field passed to Anchor at deserialization"); } anchorFieldRef = anchorField; color = anchorField.color; nodeRef = anchorField.nodeRef; }
public void AddInitializedNode(PWNode newNode, bool raiseEvents = true) { nodes.Add(newNode); nodesDictionary[newNode.id] = newNode; if (OnNodeAdded != null && raiseEvents) { OnNodeAdded(newNode); } }
public void OpenNodeScript(PWNode node) { var monoScript = MonoScript.FromScriptableObject(node); string filePath = AssetDatabase.GetAssetPath(monoScript); if (File.Exists(filePath)) { UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(filePath, 21); } }
//Check errors when transferring values from a node to another bool CheckProcessErrors(PWNodeLink link, PWNode node, bool realMode) { if (!realMode) { if (link.fromAnchor == null || link.toAnchor == null) { Debug.LogError("[PW Process] null anchors in link: " + link + ", from node: " + node + ", trying to removing this link"); currentGraph.RemoveLink(link, false); return(true); } var fromType = Type.GetType(link.fromNode.classAQName); var toType = Type.GetType(link.toNode.classAQName); if (!nodesDictionary.ContainsKey(link.toNode.id)) { Debug.LogError("[PW Process] " + "node id (" + link.toNode.id + ") not found in nodes dictionary"); return(true); } if (nodesDictionary[link.toNode.id] == null) { Debug.LogError("[PW Process] " + "node id (" + link.toNode.id + ") is null in nodes dictionary"); return(true); } if (!bakedNodeFields.ContainsKey(link.fromNode.classAQName) || !bakedNodeFields[link.fromNode.classAQName].ContainsKey(link.fromAnchor.fieldName)) { Debug.LogError("[PW Process] Can't find field: " + link.fromAnchor.fieldName + " in " + fromType); return(true); } if (!bakedNodeFields.ContainsKey(link.toNode.classAQName) || !bakedNodeFields[link.toNode.classAQName].ContainsKey(link.toAnchor.fieldName)) { Debug.LogError("[PW Process] Can't find field: " + link.toAnchor.fieldName + " in " + toType); return(true); } if (bakedNodeFields[link.fromNode.classAQName][link.fromAnchor.fieldName].GetValue(node) == null) { Debug.Log("[PW Process] tring to assign null value from " + fromType + "." + link.fromAnchor.fieldName); return(true); } } return(false); }
public void NotifyNodeReady(PWNode node) { //if one node isn't ready, return if (nodes.Any(n => !n.ready)) { return; } if (OnAllNodeReady != null) { OnAllNodeReady(); } }
void OnReloadCallback(PWNode from) { BuildBiomeSwitchGraph(); var biomeData = GetBiomeData(); //if the reload does not comes from the editor if (from != null) { FillBiomeMap(biomeData); updateBiomeMap = true; } }
static void GetNodes(PWGraph graph, PWGraphCommand command, out PWNode fromNode, out PWNode toNode, string inputCommand) { fromNode = graph.FindNodeByName(command.fromNodeName); toNode = graph.FindNodeByName(command.toNodeName); if (fromNode == null) { throw new Exception("Node " + command.fromNodeName + " not found in graph while parsing: '" + inputCommand + "'"); } if (toNode == null) { throw new Exception("Node " + command.toNodeName + " not found in graph while parsing: '" + inputCommand + "'"); } }
void ReloadCallback(PWNode from) { //load the new sampler if there it was modified if (inputBiome != null) { currentSampler = inputBiome.GetSampler(samplerName); } UpdateRelativeBounds(); switchList.UpdateMinMax(relativeMin, relativeMax); switchList.UpdateSampler(samplerName, currentSampler); switchList.UpdateBiomeRepartitionPreview(inputBiome); }
void RenderNodeLinks(PWNode node) { Handles.BeginGUI(); foreach (var anchorField in node.outputAnchorFields) { foreach (var anchor in anchorField.anchors) { foreach (var link in anchor.links) { DrawNodeCurve(link); } } } Handles.EndGUI(); }
void TrySetValue(FieldInfo field, object val, PWNode target, PWNode from, bool realMode) { if (realMode) { field.SetValue(target, val); } else { try { field.SetValue(target, val); } catch (Exception e) { Debug.LogError("[PWGraph Processor] " + e); } } }
public string FindGraphNameFromExternalNode(PWNode node) { if (node.GetType() != typeof(PWNodeGraphExternal)) { return(null); } return(subgraphReferences.FirstOrDefault(gName => { var g = FindGraphByName(gName); if (g.externalGraphNode.nodeId == node.nodeId) { return true; } return false; })); }
void TryBuildGraphPart(PWNode leadNode, List <PWNodeProcessInfo> toComputeList, int depth = 0) { InsertNodeIfNotExists(toComputeList, leadNode); foreach (var dep in leadNode.GetDependencies()) { var depNode = FindNodebyId(dep.nodeId); if (depNode.processMode == PWNodeProcessMode.RequestForProcess) { InsertNodeIfNotExists(toComputeList, depNode); TryBuildGraphPart(depNode, toComputeList, depth++); } } }
public void OnAfterDeserialize(PWNode node) { if (anchors.Count == 0) { Debug.LogWarning("Zero length anchors in anchorField in node " + nodeRef); } Init(node); foreach (var anchor in anchors) { deserializedAnchors.Add(anchor.GUID); anchor.OnAfterDeserialized(this); } UpdateAnchors(); }
public PWNode CreateNewNode(System.Type nodeType, Vector2 position, string name = null, bool raiseEvents = true) { PWNode newNode = ScriptableObject.CreateInstance(nodeType) as PWNode; position.x = Mathf.RoundToInt(position.x); position.y = Mathf.RoundToInt(position.y); newNode.rect.position = position; newNode.Initialize(this); AddInitializedNode(newNode, raiseEvents); if (name != null) { newNode.name = name; } return(newNode); }
static void CreateNode(PWGraph graph, PWGraphCommand command, string inputCommand) { Vector2 position = command.position; PWNode node = null; //if we receive a CreateNode with input/output graph nodes, we assign them so we don't have multiple inout/output nodes if (command.nodeType == typeof(PWNodeGraphInput) || command.nodeType == typeof(PWNodeBiomeGraphInput)) { node = graph.inputNode; } else if (command.nodeType == typeof(PWNodeGraphOutput) || command.nodeType == typeof(PWNodeBiomeGraphOutput)) { node = graph.outputNode; } else { node = graph.CreateNewNode(command.nodeType, position); } //set the position again for input/output nodes node.rect.position = position; Type nodeType = node.GetType(); if (!String.IsNullOrEmpty(command.attributes)) { foreach (var attr in PWJson.Parse(command.attributes)) { FieldInfo attrField = nodeType.GetField(attr.first, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); if (attrField != null) { attrField.SetValue(node, attr.second); } else { Debug.LogError("Attribute " + attr.first + " can be found in node " + node); } } } node.name = command.name; }
void RenderDecaledNode(int id, PWNode node) { //node grid snapping when pressing cmd/crtl if (node.isDragged && e.command) { Vector2 pos = node.rect.position; //aproximative grid cell size float snapPixels = 25.6f; pos.x = Mathf.RoundToInt(Mathf.RoundToInt(pos.x / snapPixels) * snapPixels); pos.y = Mathf.RoundToInt(Mathf.RoundToInt(pos.y / snapPixels) * snapPixels); node.rect.position = pos; } //move the node if panPosition changed: node.rect = PWUtils.DecalRect(node.rect, graph.panPosition); Rect decaledRect = GUILayout.Window(id, node.rect, node.OnWindowGUI, node.name, (node.isSelected) ? nodeSelectedStyle : nodeStyle, GUILayout.Height(node.viewHeight)); node.visualRect = decaledRect; node.rect = PWUtils.DecalRect(decaledRect, -graph.panPosition); //draw node header: //Draw the node header using the color scheme: if (e.type == EventType.Repaint) { float h = nodeStyle.border.top; float w = decaledRect.width - nodeStyle.border.right - nodeStyle.border.left; GUI.color = PWColorTheme.GetNodeColor(node.colorSchemeName); // GUI.DrawTexture(new Rect(0, 0, w, h), nodeHeaderStyle.normal.background); nodeHeaderStyle.Draw(new Rect(decaledRect.x, decaledRect.y, w, h), false, false, false, false); GUI.color = Color.white; } if (node.debug) { Rect debugRect = decaledRect; debugRect.y -= 20; EditorGUI.LabelField(debugRect, "id: " + node.id); debugRect.y -= 20; EditorGUI.LabelField(debugRect, "comp order: " + node.computeOrder + " | can work: " + node.canWork); } }
public void BuildTree(PWNode node) { biomeIdCount = 0; Stopwatch st = new Stopwatch(); st.Start(); root = new BiomeSwitchNode(); biomeCoverage.Clear(); foreach (var switchMode in Enum.GetValues(typeof(BiomeSwitchMode))) { biomeCoverage[(BiomeSwitchMode)switchMode] = 0; } BuildTreeInternal(node, root, 0); st.Stop(); Debug.Log("built tree time: " + st.ElapsedMilliseconds + "ms"); // DumpBuiltTree(); isBuilt = true; }
void RenderNode(int id, PWNode node) { RenderDecaledNode(id, node); //check if the mouse is over this node if (node.rect.Contains(e.mousePosition - graph.panPosition)) { graph.editorEvents.mouseOverNode = node; graph.editorEvents.isMouseOverNodeFrame = true; } //display the process time of the window (if > .1ms) if (node.processTime > .1f) { GUIStyle gs = new GUIStyle(); Rect msRect = PWUtils.DecalRect(node.rect, graph.panPosition); msRect.position += new Vector2(msRect.size.x / 2 - 10, msRect.size.y + 5); gs.normal.textColor = greenRedGradient.Evaluate(node.processTime / 20); //20ms ok, after is red GUI.Label(msRect, node.processTime.ToString("F1") + " ms", gs); } }
public bool RemoveNode(PWNode removeNode, bool raiseEvents = true) { //can't delete an input/output node if (removeNode == inputNode || removeNode == outputNode) { return(false); } int id = removeNode.id; nodes.Remove(removeNode); if (OnNodeRemoved != null && raiseEvents) { OnNodeRemoved(removeNode); } bool success = nodesDictionary.Remove(id); removeNode.RemoveSelf(); return(success); }
void ReloadCallback(PWNode from) { UpdateGraph(); }
public void InitExternalNode(PWNode ex) { upperNode = ex as PWNodeGraphExternal; }
//called each time the anchorField is deserialized; public void Init(PWNode node) { nodeRef = node; }