예제 #1
0
파일: NodeDrawer.cs 프로젝트: keijiro/SSE
 public static Vector2 GetAbsoluteInputChannelPosition( Node node, uint channelId )
 {
     var inputChannel = node.GetInputChannel( channelId );
     var result = new Vector2( node.NodePositionInGraph.x, node.NodePositionInGraph.y);
     result += new Vector2( inputChannel.Position.x, inputChannel.Position.y );
     result += new Vector2( inputChannel.Position.width / 2, inputChannel.Position.height / 2 );
     return result;
 }
예제 #2
0
 public override string GetDefaultInput( Node parent )
 {
     string result = "float4 " + GetDefaultInputName( parent ) + " = ";
     result += "float4(";
     result += defaultValue.X + ",";
     result += defaultValue.Y + ",";
     result += defaultValue.Z + ",";
     result += defaultValue.W + ");\n";
     return result;
 }
예제 #3
0
 public ChannelQueryResult ChannelInput(Node parent)
 {
     ChannelQueryResult result;
     if( IncomingConnection == null )
     {
         result.AdditionalFields = GetDefaultInput( parent );
         result.QueryResult = GetDefaultInputName( parent );
     }
     else
     {
         result.AdditionalFields = "";
         var outputNode = parent.Owner.GetNode( IncomingConnection.NodeIdentifier );
         result.QueryResult = outputNode.GetExpression( IncomingConnection.ChannelId );
     }
     return result;
 }
예제 #4
0
 public override string GetDefaultInput( Node parent )
 {
     string result = "float4x4 " + GetDefaultInputName( parent ) + " = ";
     result += "float4x4(";
     result += defaultValue.m00 + ",";
     result += defaultValue.m01 + ",";
     result += defaultValue.m02 + ",";
     result += defaultValue.m03 + ",";
     result += defaultValue.m10 + ",";
     result += defaultValue.m11 + ",";
     result += defaultValue.m12 + ",";
     result += defaultValue.m13 + ",";
     result += defaultValue.m20 + ",";
     result += defaultValue.m21 + ",";
     result += defaultValue.m22 + ",";
     result += defaultValue.m23 + ",";
     result += defaultValue.m30 + ",";
     result += defaultValue.m31 + ",";
     result += defaultValue.m32 + ",";
     result += defaultValue.m33 + ");\n";
     return result;
 }
예제 #5
0
		public override string GetDefaultInput( Node parent )
		{
			throw new UnityException( "Default not supported on: " + GetType() );
		}
예제 #6
0
 protected string GetDefaultInputName( Node parent )
 {
     return parent.UniqueNodeIdentifier +  "_" + channelId + "_NoInput";
 }
예제 #7
0
 public abstract string GetDefaultInput( Node parent );
예제 #8
0
파일: NodeEditor.cs 프로젝트: JuanJSAR/SSE
		private void HandleEvents() // Texel added parent input for drag and drop
		{
			switch( Event.current.type )
			{
			case EventType.DragUpdated:
			case EventType.DragPerform :
			{
				if (position.Contains(_currentMousePosition)) {
					var path = DragAndDrop.paths[0];
					if (path.EndsWith("sgraph"))
					{
						DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
						if (Event.current.type == EventType.dragPerform)
						{
							_shouldLoadGraph = true;
							_overrideLoadPath = path;
							_lastGraphPath = path;
							_markDirtyOnLoad = true;
						}
						Event.current.Use();
					}
				}
				break;
			}

			case EventType.MouseDown:
			{
				if (Event.current.button == 0 )
				{
					if( LeftMouseDown() )
					{
						Event.current.Use();
						return;
					}
				}
				break;
			}
				
			case EventType.ContextClick:
			{
				if( RightMouseDown() )
				{
					Event.current.Use();
					return;
				}
				break;
			}
			//Handle drag
			case EventType.MouseDrag:
			{
				_currentMousePosition.x = Event.current.mousePosition.x;
				_currentMousePosition.y = Event.current.mousePosition.y;
				
				//If Left click drag...
				if (Event.current.button == 0 )
				{
					if( LeftMouseDragged() )
					{
						Event.current.Use();
					}
				}
				
				if( Event.current.button == 2 )
				{
					_middleMouseDrag = true;
					_selectedGraph.CurrentSubGraph.DrawOffset += Event.current.delta;
					
					Event.current.Use();
				}
				break;
			}
			case EventType.MouseUp:
			{
				//Mouse button released, unmark hot
				_selectedGraph.UnmarkSelectedHot();

				if( _focusChanged )
				{
					_focusChangedUpdate = true;
					_focusChanged = false;
				}
				
				//Selection box
				if( _doingSelectBox )
				{
					_doingSelectBox = false;
					
					if( _selectedGraph.Select( GetSelectionArea(), Event.current.modifiers == EventModifiers.Shift ) )
					{
						NextSelectedNode = _selectedGraph.FirstSelected;
						_updateSelection = true;
						MarkDirty();
					}
					Event.current.Use();
				}
				
				if( _movingNodes )
				{
					_movingNodes = false;
					MarkDirty();
					Event.current.Use();
				}
				
				if( _middleMouseDrag )
				{
					_middleMouseDrag = false;
					MarkDirty();
					Event.current.Use();
				}
				break;
			}
			case EventType.Layout:
			{
				if (_nextGraph != null && _nextGraph != _selectedGraph)
				{
					_selectedGraph = _nextGraph;
					if( _markDirtyOnLoad )
					{
						MarkDirty();
						_markDirtyOnLoad = false;
					}
					_selectedNode = null;
				}
				if( _selectedGraph.CurrentSubGraphType != _currentSubGraphType )
				{
					_selectedGraph.CurrentSubGraphType = _currentSubGraphType;
					_selectedGraph.Deselect();
					MarkDirty();
					_selectedNode = null;
				}
				if( _updateSelection )
				{
					_focusChanged = true;
					_selectedNode = NextSelectedNode;
					_updateSelection = false;
				}
				break;
			}
			case EventType.ValidateCommand:
			{
				if( Event.current.commandName == "Copy"
					|| Event.current.commandName == "Paste"
					|| Event.current.commandName == "Duplicate"
					|| Event.current.commandName == "SelectAll")
				{
					Event.current.Use();
				}
				break;
			}
			case EventType.ExecuteCommand:
			{
				if( Event.current.commandName == "Copy" )
				{
					CopySelectedNodes();
					Event.current.Use();
				}

				if( Event.current.commandName == "Paste" )
				{
					PasteNodes();
					Event.current.Use();
				}
				
				if( Event.current.commandName == "Duplicate" )
				{
					CopySelectedNodes();
					PasteNodes();
					MarkDirty();
					Event.current.Use();
				}
				
				if( Event.current.commandName == "SelectAll" )
				{
					_selectedGraph.SelectAll();
					NextSelectedNode = _selectedGraph.FirstSelected;
					_updateSelection = true;
					MarkDirty();
					Event.current.Use();
				}
				break;
			}
			}
			return;
		}
예제 #9
0
파일: NodeEditor.cs 프로젝트: JuanJSAR/SSE
		public void OnGUI()
		{
			if (!_isInstructionCountCached) 
				CacheCount();
			GUI.Label(new Rect(5,0,95,45),new GUIContent(_instructionCountDetails,_instructionCountTooltip));
			
			_reservedArea.Clear();
			_drawArea = new Rect( 0, 0, Screen.width-300, Screen.height-23 );
			_detailsBox = new Rect(Screen.width - 300,0, 300, Screen.height - 40);
			_optionsBox = new Rect(Screen.width - 300,Screen.height - 40, 300 , 25);
			
			//Mouse clicks in the reserved area do not attemp to select on graph
			_reservedArea.Add( _detailsBox );
			_reservedArea.Add( _optionsBox );
			
			_currentMousePosition.x = Event.current.mousePosition.x;
			_currentMousePosition.y = Event.current.mousePosition.y;
			
			// Handle Minimap! (Texel)
			if (_middleMouseDrag) {
				var oldColor = GUI.color;
				var trans = GUI.color * new Vector4(1,1,1,0.3f); // Fairly transparent
				// First, draw the bounds of the graph. This requires min/maxing the graph
				var drawCenter = new Vector2((_drawArea.x + (_drawArea.width * 0.5f)),_drawArea.y + (_drawArea.height * 0.5f));
				drawCenter.x -= _drawArea.width * 0.1f;
				drawCenter.y -= _drawArea.height * 0.1f;
				
				var redSize = new Vector2(_drawArea.width,_drawArea.height) * 0.2f;
				
				GUI.color = trans;
				GUI.Box(new Rect(drawCenter.x,drawCenter.y,redSize.x,redSize.y),"");
				GUI.color = oldColor;
				var oldBkg = GUI.backgroundColor;
				
				// Now we will draw the graph centered around the offset (Scaled down ten times)
				//Rect[] rects = _selectedGraph.CurrentSubGraph.nodePositions;
				foreach(Node node in _selectedGraph.CurrentSubGraph.Nodes) {
					var rect = node.NodePositionInGraph;
					
					var delta = new Vector2(rect.x,rect.y);// - offset;
					var size = new Vector2(rect.width,rect.height);
					delta *= 0.2f; size *= 0.2f;
					delta += drawCenter;
					
					switch (node.CurrentState) {
						case (NodeState.Valid):
							GUI.color = Color.white;
							break;
						case (NodeState.NotConnected):
							GUI.color = new Color (0.8f, 0.8f, 1f);
							break;
						case (NodeState.CircularReferenceInGraph):
							GUI.color = new Color (0.8f, 0.8f, 0f);
							break;
						case (NodeState.Error):
							GUI.color = Color.red;
							break;
					}
					
					if( node == _selectedNode )
						GUI.backgroundColor = Color.Lerp(GUI.backgroundColor,Color.green,0.5f);
					
					GUI.Box(new Rect(delta.x,delta.y,size.x,size.y),"");
					GUI.color = oldColor;
					GUI.backgroundColor = oldBkg;
				}
			}
			
			HandleEvents();
			
			//GUI fixup for changed focus
			GUI.SetNextControlName("FocusFixup");
			EditorGUI.Toggle(new Rect(-100, -100, 1, 1), false);

			if (_focusChangedUpdate)
			{
				GUI.FocusControl("FocusFixup");
				_focusChangedUpdate = false;
			}
			
			//Update each node and draw them
			_selectedGraph.UpdateErrorState();
			GUILayout.BeginArea( _drawArea );
			_selectedGraph.Draw( this, _showComments, _drawArea );
			UpdateIOChannels();
			DrawIOLines(_drawArea);
			GUILayout.EndArea( );
			
			if( _doingSelectBox )
			{
				var oldColor = GUI.color;
				var newColor = GUI.color;
				newColor.a = 0.4f;
				GUI.color = newColor;
				GUI.Box( GetSelectionArea(), "" );
				GUI.color = oldColor;
			}
			
			DrawSettings();
			
			//Handle node delete / undo and redo
			if( !GUI.changed && Event.current.type == EventType.KeyDown ) 
			{
				if (Event.current.keyCode == KeyCode.Z 
					&& ( Event.current.modifiers == EventModifiers.Alt ) )
				{
					var graph = _undoChain.Undo();
					if( graph != null )
					{
						_nextGraph = graph;
						_nextGraph.Initialize( new Rect( 0, 0, Screen.width, Screen.height ), false);
						_graphNeedsUpdate = true;
						NextSelectedNode = _nextGraph.FirstSelected;
						_updateSelection = true;
						Event.current.Use();
					}
					return;
				}
				if (Event.current.keyCode == KeyCode.Z
					&& ( Event.current.modifiers == (EventModifiers.Alt | EventModifiers.Shift ) ) )
				{
					var graph = _undoChain.Redo();
					if( graph != null )
					{
						_nextGraph = graph;
						_nextGraph.Initialize( new Rect( 0, 0, Screen.width, Screen.height ), false);
						_graphNeedsUpdate = true;
						NextSelectedNode = _nextGraph.FirstSelected;
						_updateSelection = true;
						Event.current.Use();
					}
					return;
				}
					
				if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace)
				{
					_selectedGraph.CurrentSubGraph.DeleteSelected();
					NextSelectedNode = null;
					_graphNeedsUpdate = true;
					_updateSelection = true;

					SelectedInputChannel = null;
					SelectedOutputChannel = null;
					MarkDirty();
					Event.current.Use();
				}
			}
			
			//Draw the current subgraph type
			var oldFontSize = GUI.skin.label.fontSize;
			var oldFontStyle = GUI.skin.label.fontStyle;
			GUI.skin.label.fontSize = 30;
			GUI.skin.label.fontStyle = FontStyle.BoldAndItalic;
			GUILayout.BeginArea( _drawArea );
			GUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();
			GUILayout.Label( _currentSubGraphType.DisplayName(), GUI.skin.label );
			GUILayout.Space( 10 );
			GUILayout.EndHorizontal();
			GUILayout.EndArea();
			GUI.skin.label.fontSize = oldFontSize;
			GUI.skin.label.fontStyle = oldFontStyle;
			
			DrawOptions();
		}
예제 #10
0
파일: NodeEditor.cs 프로젝트: JuanJSAR/SSE
		private void PasteNodes()
		{
			if( _copiedNodes == null )
			{
				return;
			}
			
			var copied = _copiedNodes.CopiedNodes;
			if( copied == null )
			{
				return;
			}
			
			//Add the nodes into the new graph
			var nameMap = new Dictionary<string, string>();
			foreach( var node in copied )
			{
				var oldName = node.UniqueNodeIdentifier;
				_selectedGraph.CurrentSubGraph.AddNode(node);
				node.Initialize();
				var newName = node.UniqueNodeIdentifier;
				
				nameMap.Add( oldName, newName );
			}
			
			//Patch up the channel references...
			foreach( var node in copied )
			{
				foreach( var channel in node.GetInputChannels() )
				{
					if( channel.IncomingConnection != null && nameMap.ContainsKey( channel.IncomingConnection.NodeIdentifier ) )
					{
						channel.IncomingConnection.NodeIdentifier = nameMap[channel.IncomingConnection.NodeIdentifier];
					}
					else
					{
						channel.IncomingConnection = null;
					}
					
				}
			}
			
			//Mark these nodes as selected
			_selectedGraph.Deselect();
			foreach( var node in copied )
			{
				_selectedGraph.Select( node, true );
			}
			NextSelectedNode = _selectedGraph.FirstSelected;
			_updateSelection = true;
			
			MarkDirty();
		}
예제 #11
0
파일: NodeEditor.cs 프로젝트: JuanJSAR/SSE
		private bool LeftMouseDown()
		{
			if( InsideReservedArea( _currentMousePosition ) )
			{
				return false;
			}
			if( Event.current.modifiers == EventModifiers.Alt ||  Event.current.modifiers == EventModifiers.Command )
			{
				return true;
			}
				
			//We have clicked on an already selected node...
			var clickedNode = _selectedGraph.NodeAt( _currentMousePosition );
			if( clickedNode != null && _selectedGraph.IsSelected( clickedNode ) )
			{
				//If shift is held down deselect that node
				if( Event.current.modifiers == EventModifiers.Shift )
				{
					_selectedGraph.Deselect( clickedNode );
					MarkDirty();
					return true;
				}
				//just mark hot
				_selectedGraph.MarkSelectedHot();
				return true;
			}
				
			if( _selectedGraph.Select( _currentMousePosition, Event.current.modifiers == EventModifiers.Shift ) )
			{
				_selectedGraph.MarkSelectedHot();
				
				NextSelectedNode = _selectedGraph.FirstSelected;
				_updateSelection = true;
				
				MarkDirty();
				return true;
			}
			
			if( _selectedGraph.ButtonAt( _currentMousePosition ) )
			{
				return false;
			}
			
			if( Event.current.modifiers != EventModifiers.Shift )
			{
				_selectedGraph.Deselect();
				NextSelectedNode = null;
				MarkDirty();
				_updateSelection = true;
			}
			
			//Nothing is selected... start a drag
			_doingSelectBox = true;
			_selectBoxStart = Event.current.mousePosition;
			
			return false;
		}