public SumGate() { this.addendSocket0 = new InputSocket <double>(); this.addendSocket1 = new InputSocket <double>(); this.resultSocket = new OutputSocket <double>(); }
public override string GetString(OutputSocket outSocket) { return(_text); }
public OutputMap Connect <T>(ref OutputSocket socket, ref Output <T> connection) { connection = new Output <T> (null); return(new OutputMap(socket, typeof(T))); }
public abstract float GetNumber(OutputSocket outSocket, Request request);
public abstract List <UnityEngine.Vector3> GetVector3List(OutputSocket outSocket, Request request);
public static EOutputSocket Editor(this OutputSocket outputSocket) { return((EOutputSocket)(outputSocket.EObject ?? (outputSocket.EObject = new EOutputSocket(outputSocket)))); }
public override UnityEngine.Color[,] GetColorMap(OutputSocket socket, Request request) { return(_colorMap); }
public override float GetNumber(OutputSocket outSocket, Request request) { return(_number); }
public override float GetNumber(OutputSocket outSocket, Request request) { return(Mathf.PI); }
public abstract void ShowContexMenu(OutputSocket socket);
public OutputMap Connect <T> (ref OutputSocket socket, out IOutput <T> connection) { connection = GetConnection <T> (socket.Id); return(new OutputMap(socket, typeof(T), connection)); }
public abstract Code.Chunk.Chunk GetChunk(OutputSocket outSocket, Request request);
public override float GetNumber(OutputSocket outSocket, Request request) { float scale = GetInputNumber(_inputSocketScale, request); float jitter = GetInputNumber(_inputSocketJitter, request); float internalSeed = GetInputNumber(_inputSocketSeed, request); jitter = Mathf.Max(0, Mathf.Min(jitter, 1)); if (float.IsNaN(scale) || float.IsNaN(internalSeed) || scale == 0) { return(float.NaN); } int pointX = Mathf.RoundToInt(request.X / scale); int pointZ = Mathf.RoundToInt(request.Z / scale); float d1 = GetDistanceToPoint(pointX + _px[0], pointZ + _pz[0], request.X, request.Z, scale, jitter); float d2 = GetDistanceToPoint(pointX + _px[1], pointZ + _pz[1], request.X, request.Z, scale, jitter); float d3 = GetDistanceToPoint(pointX + _px[2], pointZ + _pz[2], request.X, request.Z, scale, jitter); float d4 = GetDistanceToPoint(pointX + _px[3], pointZ + _pz[3], request.X, request.Z, scale, jitter); float d5 = GetDistanceToPoint(pointX + _px[4], pointZ + _pz[4], request.X, request.Z, scale, jitter); float d6 = GetDistanceToPoint(pointX + _px[5], pointZ + _pz[5], request.X, request.Z, scale, jitter); float d7 = GetDistanceToPoint(pointX + _px[6], pointZ + _pz[6], request.X, request.Z, scale, jitter); float d8 = GetDistanceToPoint(pointX + _px[7], pointZ + _pz[7], request.X, request.Z, scale, jitter); float d9 = GetDistanceToPoint(pointX + _px[8], pointZ + _pz[8], request.X, request.Z, scale, jitter); int firstLowestIndex = GetLowestDistanceIndex(d1, d2, d3, d4, d5, d6, d7, d8, d9); if (_selectedDistanceType == 2) { // voronoi float firstLowestPointY = FlickNoise.SimplexValue2D(pointX + _px[firstLowestIndex], pointZ + _pz[firstLowestIndex]); return(firstLowestPointY); } float firstLowestDistance = GetValue(firstLowestIndex, d1, d2, d3, d4, d5, d6, d7, d8, d9); if (_selectedDistanceIndex == 0) { // first return(Norm(firstLowestDistance)); } int secondLowestIndex = GetSecondLowestDistanceIndex(firstLowestIndex, d1, d2, d3, d4, d5, d6, d7, d8, d9); float secondLowestDistance = GetValue(secondLowestIndex, d1, d2, d3, d4, d5, d6, d7, d8, d9); if (_selectedDistanceIndex == 1) { // second return(Norm(secondLowestDistance)); } float sf = secondLowestDistance - firstLowestDistance; if (_selectedDistanceIndex == 2) { return(Norm(sf)); } if (_selectedDistanceIndex == 3) { // Min(second - first); return(Norm(Mathf.Min(sf, Mathf.Min(secondLowestDistance, firstLowestDistance)))); } return(Norm(firstLowestDistance)); }
public List <Node> Deserialize(List <SerializableNode> nodes, List <SerializableEdge> edges) { if (nodes.Count == 0) { return(null); // Nothing to deserialize. } List <Node> returnValue = new List <Node>(); bool wasTriggering = TriggerEvents; TriggerEvents = false; // deserialize nodes for (var index = 0; index < nodes.Count; index++) { var sNode = nodes[index]; Type nodeType = Type.GetType(sNode.type); if (nodeType == null) { Debug.LogWarning("Unknown node type: " + sNode.type); continue; } Node n = CreateNode(nodeType, sNode.id); if (n != null) { JsonUtility.FromJsonOverwrite(sNode.data, n); n.OnDeserialization(sNode); n.X = sNode.X; n.Y = sNode.Y; for (var i = 0; i < sNode.directInputValues.Length; i++) { if (i < n.Sockets.Count) { if (n.Sockets[i].IsInput()) { InputSocket inputSocket = (InputSocket)n.Sockets[i]; inputSocket.SetDirectInputNumber(sNode.directInputValues[i], false); } } } if (sNode.Collapsed) { n.Collapse(); } returnValue.Add(n); } } // deserialize edges for (var index = 0; index < edges.Count; index++) { var sEdge = edges[index]; Node inputNode = GetNode(sEdge.InputNodeId, returnValue); Node outputNode = GetNode(sEdge.OutputNodeId, returnValue); if (inputNode == null || outputNode == null) { Log.Error("Try to create an edge but can not find the nodes."); continue; } if (sEdge.OutputSocketIndex > outputNode.Sockets.Count || sEdge.InputSocketIndex > inputNode.Sockets.Count) { Log.Error("Try to create an edge but can not find the sockets."); continue; } if (sEdge.InputSocketIndex < inputNode.Sockets.Count && sEdge.OutputSocketIndex < outputNode.Sockets.Count) { if (inputNode.Sockets[sEdge.InputSocketIndex].GetType() == typeof(InputSocket) && outputNode.Sockets[sEdge.OutputSocketIndex].GetType() == typeof(OutputSocket)) { InputSocket inputSocket = (InputSocket)inputNode.Sockets[sEdge.InputSocketIndex]; OutputSocket outputSocket = (OutputSocket)outputNode.Sockets[sEdge.OutputSocketIndex]; Edge edge = new Edge(outputSocket, inputSocket); edge.Path = sEdge.Path; inputSocket.Edge = edge; outputSocket.Edges.Add(edge); } else { Log.Error("Can not connect node " + inputNode.Id + " with node " + outputNode.Id + ". Socket type error."); } } else { Log.Error("Can not connect node " + inputNode.Id + " with node " + outputNode.Id + ". Socket index out of range."); } } TriggerEvents = wasTriggering; return(returnValue); }
public override float GetNumber(OutputSocket outSocket, Request request) { float mask = GetInputNumber(_inputSocketMask, request); if (float.IsNaN(mask)) { return(float.NaN); } if (mask < 0) { return(float.NaN); } int width = Mathf.FloorToInt(GetInputNumber(_inputSocketWidth, request)); int height = Mathf.FloorToInt(GetInputNumber(_inputSocketHeight, request)); if (float.IsNaN(width) || float.IsNaN(height) || width == 0 || height == 0) { return(float.NaN); } float halfWidth = Mathf.Ceil(width / 2f); float halfHeight = Mathf.Ceil(height / 2f); Request r = new Request(); r.X = request.X - width * 1.5f - 1; r.Y = request.Y; r.Z = request.Z - height * 1.5f - 1; r.SizeX = width * 3 + 1; r.SizeZ = height * 3 + 1; r.Seed = request.Seed; List <UnityEngine.Vector3> points = AbstractVector3Node.GetInputVector3List(_inputSocketVec, r); if (points == null) { return(float.NaN); } float value = float.NaN; bool initialized = false; Request r2 = new Request(); for (int index = 0; index < points.Count; index++) { var point = points[index]; if (!_fadeMask && !AllPositionsCoveredByMask( (int)(point.x - halfWidth), (int)(point.z - halfHeight), width, height, request.Y, request.Seed)) { continue; } int mapRelativeX = (int)(halfWidth - (point.x - request.X)); int mapRelativeZ = (int)(halfHeight - (point.z - request.Z)); if (mapRelativeX < width && mapRelativeX > 0 && mapRelativeZ < height && mapRelativeZ > 0) { r2.X = mapRelativeX; r2.Z = mapRelativeZ; r2.Seed = request.Seed; float v = GetInputNumber(_inputSocketValue, r2); if (!initialized && !float.IsNaN(v)) { value = 0; initialized = true; } if (!float.IsNaN(v)) { value = v; } } } if (_fadeMask) { value = value * mask; } return(value); }
public float GetNumber(OutputSocket socket, Request request) { return(AbstractNumberNode.GetInputNumber(_heightValueSocket, request)); }
public MultiplicationGate() { this.multiplierSocket0 = new InputSocket <double>(); this.multiplierSocket1 = new InputSocket <double>(); this.resultSocket = new OutputSocket <double>(); }
public FunctionSensor(Func <R> function) { this.outputSocket = new OutputSocket <R>(); this.SetFunction(function); }
private void DrawSockets() { Color originalColor = GUI.color; for (int i = 0; i < targetGraph.Nodes.Count; i++) { BehaviourNode node = targetGraph.Nodes[i]; if (node == null) { continue; } foreach (InputSocket thisInput in node.Inputs) { if (thisInput == null) { continue; } Rect socketRect = thisInput.SocketRect; socketRect = new Rect(socketRect.x + node.Position.x + dragging_Position.x, socketRect.y + node.Position.y + dragging_Position.y, socketRect.width, socketRect.height); thisInput.DrawSocket(socketRect); #if HOVER_EFFECTS if (connection_CanEdit) { OutputSocket linkedSocket = thisInput.SourceSocket; if (connection_Start != null) { if (IsValidAttach(connection_Start, thisInput)) { if (linkedSocket == null) { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } else { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowMinus); } } } else { if (linkedSocket == null) { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } else { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowMinus); } } } #endif if (connection_CanEdit && (currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseUp) && socketRect.Contains(currentEvent.mousePosition)) { if (currentEvent.button == 0) { if (connection_Start != null || currentEvent.type != EventType.MouseUp) { connection_End = thisInput; } if (connection_Start != null) { Attach(connection_Start, connection_End); connection_End = null; connection_Start = null; currentEvent.Use(); } } else if (currentEvent.button == 1) { Detatch(thisInput); } currentEvent.Use(); } } foreach (OutputSocket thisOutput in node.Outputs) { if (thisOutput == null) { continue; } Rect socketRect = thisOutput.socketRect; socketRect = new Rect(socketRect.x + node.Position.x + dragging_Position.x, socketRect.y + node.Position.y + dragging_Position.y, socketRect.width, socketRect.height); thisOutput.DrawSocket(socketRect); if (connection_CanEdit) { #if HOVER_EFFECTS if (connection_End != null) { if (IsValidAttach(thisOutput, connection_End)) { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } } else { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } #endif if ((currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseUp) && socketRect.Contains(currentEvent.mousePosition)) { if (currentEvent.button == 0) { if (connection_End != null || currentEvent.type != EventType.MouseUp) { connection_Start = thisOutput; } if (connection_End != null) { Attach(connection_Start, connection_End); connection_End = null; connection_Start = null; } currentEvent.Use(); } else if (currentEvent.button == 1) { Detatch(thisOutput); Repaint(); currentEvent.Use(); } } } } } GUI.color = originalColor; }
public override float GetNumber(OutputSocket outSocket, float x, float y, float z, float seed) { return(GetInputNumber(_inSocket, x, y, z, seed)); }
public abstract UnityEngine.Color[,] GetColorMap(OutputSocket socket, Request request);
public OutputMap Connect <T> (ref OutputSocket socket, out ILazyOutput <T> connection) { connection = null; return(new OutputMap(socket, typeof(T), connection)); }
public override float GetNumber(OutputSocket outSocket, Request request) { return(GetInputNumber(_inputSocketValue, request)); }
/// <summary> Returns true if the sockets can be linked.</summary> /// <param name="inSocket"> The input socket</param> /// <param name="outSocket"> The output socket</param> /// <returns>True if the sockets can be linked.</returns> public bool CanBeLinked(InputSocket inSocket, OutputSocket outSocket) { return(inSocket != null && outSocket != null && outSocket.Type == inSocket.Type); }
public int IndexOf(OutputSocket output) { return(this.Outputs.IndexOf(output)); }
/// <summary>Unity serialization callback.</summary> public void OnAfterDeserialize() { if (_serializedNodes.Count == 0) { return; // Nothing to deserialize. } bool wasTriggering = TriggerEvents; TriggerEvents = false; _nodes.Clear(); // clear original data. // deserialize nodes foreach (var sNode in _serializedNodes) { Type nodeType = Type.GetType(sNode.type); if (nodeType == null) { Debug.LogWarning("Unknown node type: " + sNode.type); continue; } Node n = CreateNode(nodeType, sNode.id); if (n != null) { JsonUtility.FromJsonOverwrite(sNode.data, n); n.OnDeserialization(sNode); n.X = sNode.X; n.Y = sNode.Y; for (var i = 0; i < sNode.directInputValues.Length; i++) { if (n.Sockets[i].IsInput()) { InputSocket inputSocket = (InputSocket)n.Sockets[i]; inputSocket.SetDirectInputNumber(sNode.directInputValues[i], false); } } if (sNode.Collapsed) { n.Collapse(); } AddNode(n); } } // deserialize edges foreach (var sEdge in _serializedEdges) { Node inputNode = GetNode(sEdge.InputNodeId); Node outputNode = GetNode(sEdge.OutputNodeId); if (inputNode == null || outputNode == null) { Debug.LogWarning("Try to create an edge but can not find at least on of the nodes."); continue; } if (sEdge.OutputSocketIndex > outputNode.Sockets.Count || sEdge.InputSocketIndex > inputNode.Sockets.Count) { Debug.LogWarning("Try to create an edge but can not find at least on of the sockets."); continue; } InputSocket inputSocket = (InputSocket)inputNode.Sockets[sEdge.InputSocketIndex]; OutputSocket outputSocket = (OutputSocket)outputNode.Sockets[sEdge.OutputSocketIndex]; Edge edge = new Edge(outputSocket, inputSocket); inputSocket.Edge = edge; outputSocket.Edges.Add(edge); } TriggerEvents = wasTriggering; }
public override UnityEngine.Color GetColor(OutputSocket outSocket, float i) { return(_color); }
public OutputMap Connect <T>(INodeInstance parent, ref OutputSocket socket, ref Output <T> connection) { connection = new Output <T>(null); return(new OutputMap(socket, typeof(T))); }
private void HandleInput() { if (currentEvent.type == EventType.KeyDown) { if (currentEvent.keyCode == KeyCode.D) { if (selectedWindow != -1) { DuplicateNode(targetGraph.AllNodes[selectedWindow]); } } else if (currentEvent.keyCode == KeyCode.Delete) { if (selectedWindow != -1) { DeleteNode(targetGraph.AllNodes[selectedWindow]); } } } else if (currentEvent.type == EventType.MouseDrag && dragging_IsDragging) { dragging_Position += currentEvent.delta; Repaint(); } else if (screenRect.Contains(currentEvent.mousePosition)) { if (currentEvent.type == EventType.MouseDown) { GUI.UnfocusWindow(); GUI.FocusControl(""); if (currentEvent.button != 2) { if (connection_Start != null || connection_End != null) { connection_Start = null; connection_End = null; currentEvent.Use(); Repaint(); } if (currentEvent.button == 1) { dragging_IsDragging = false; rightClickedPosition = currentEvent.mousePosition; BuildAddMenu(); AddNodeMenu.ShowAsContext(); } else { dragging_IsDragging = true; } } else { dragging_IsDragging = true; } currentEvent.Use(); Repaint(); } } }
public Edge(OutputSocket outputSocket, InputSocket inputSocket) { Input = inputSocket; Output = outputSocket; }