コード例 #1
0
	public bool DrawGraph (NavGraph graph, GraphEditor graphEditor) {
		
		Color tmp1 = GUI.color;
		EditorGUILayoutx.FadeArea topFadeArea = GUILayoutx.BeginFadeArea (graph.open,"","graph_"+graph.guid,graphBoxStyle);


		Color tmp2 = GUI.color;
		GUI.color = tmp1;
		
		GUILayout.BeginHorizontal ();
		string graphNameControl = "graph_"+graph.guid+"_name";
		if (graph.name == null) graph.name = graphEditorTypes[graph.GetType ().Name].displayName;
		
		GUI.SetNextControlName (graphNameControl);
		graph.name = GUILayout.TextField (graph.name, EditorGUILayoutx.defaultLabelStyle, GUILayout.ExpandWidth(false),GUILayout.ExpandHeight(false));
		
		if (graph.name == "" && Event.current.type == EventType.Repaint && GUI.GetNameOfFocusedControl() != graphNameControl) {
			graph.name = graphEditorTypes[graph.GetType ().Name].displayName;
		}
		
		if (GUILayout.Button ("",EditorGUILayoutx.defaultLabelStyle)) {
			graph.open = !graph.open;
			if (!graph.open) {
				graph.infoScreenOpen = false;
			}
			RepaintSceneView ();
			return true;
		}
		
		if (script.prioritizeGraphs) {
			if (GUILayout.Button (new GUIContent ("Up","Increase the graph priority"),GUILayout.Width (40))) {
				int index = script.astarData.GetGraphIndex (graph);
				
				//Find the next non null graph
				int next = index-1;
				for (;next >= 0;next--) if (script.graphs[next] != null) break;
				
				if (next >= 0) {
					NavGraph tmp = script.graphs[next];
					script.graphs[next] = graph;
					script.graphs[index] = tmp;
					
					GraphEditor tmpEditor = graphEditors[next];
					graphEditors[next] = graphEditors[index];
					graphEditors[index] = tmpEditor;
				}
				CheckGraphEditors ();
				Repaint ();
			}
			if (GUILayout.Button (new GUIContent ("Down","Decrease the graph priority"),GUILayout.Width (40))) {
				int index = script.astarData.GetGraphIndex (graph);
				
				//Find the next non null graph
				int next = index+1;
				for (;next<script.graphs.Length;next++) if (script.graphs[next] != null) break;
				
				if (next < script.graphs.Length) {
					NavGraph tmp = script.graphs[next];
					script.graphs[next] = graph;
					script.graphs[index] = tmp;
					
					GraphEditor tmpEditor = graphEditors[next];
					graphEditors[next] = graphEditors[index];
					graphEditors[index] = tmpEditor;
				}
				CheckGraphEditors ();
				Repaint ();
			}
		}
		
		bool drawGizmos = GUILayout.Toggle (graph.drawGizmos,"Draw Gizmos",graphGizmoButtonStyle);
		if (drawGizmos != graph.drawGizmos) {
			graph.drawGizmos = drawGizmos;
			RepaintSceneView ();
		}
		
		if (GUILayout.Toggle (graph.infoScreenOpen,"Info",graphInfoButtonStyle)) {
			if (!graph.infoScreenOpen) {
				graph.infoScreenOpen = true;
				graph.open = true;
			}
		} else {
			graph.infoScreenOpen = false;
		}
		
		if (GUILayout.Button ("Delete",graphDeleteButtonStyle)) {
			RemoveGraph (graph);
			return true;
		}
		GUILayout.EndHorizontal ();


		if (topFadeArea.Show () ) {
			EditorGUILayoutx.FadeArea fadeArea = GUILayoutx.BeginFadeArea (graph.infoScreenOpen,"graph_info_"+graph.guid,0);
			if (fadeArea.Show ()) {
				
				bool nodenull = false;
				int total = 0;
				int numWalkable = 0;

				KeyValuePair<float,KeyValuePair<int,int>> pair;
				if ( graphNodeCounts == null ) graphNodeCounts = new Dictionary<NavGraph, KeyValuePair<float, KeyValuePair<int, int>>>();

				if ( !graphNodeCounts.TryGetValue ( graph, out pair ) || (Time.realtimeSinceStartup-pair.Key) > 2 ) {
					GraphNodeDelegateCancelable counter = delegate (GraphNode node) {
						if (node == null) {
							nodenull = true;
							return true;
						}
						total++;
						if (node.Walkable) numWalkable++;
						return true;
					};
					graph.GetNodes (counter);
					pair = new KeyValuePair<float, KeyValuePair<int, int>> (Time.realtimeSinceStartup, new KeyValuePair<int,int>( total, numWalkable ) );
					graphNodeCounts[graph] = pair;
				}

				total = pair.Value.Key;
				numWalkable = pair.Value.Value;

			
				EditorGUI.indentLevel++;
				
				if (nodenull) {
					//EditorGUILayout.HelpBox ("Some nodes in the graph are null. Please report this error.", MessageType.Info);
					Debug.LogError ("Some nodes in the graph are null. Please report this error.");
				}
				
				EditorGUILayout.LabelField ("Nodes",total.ToString());
				EditorGUILayout.LabelField ("Walkable",numWalkable.ToString ());
				EditorGUILayout.LabelField ("Unwalkable",(total-numWalkable).ToString ());
				if (total == 0) EditorGUILayout.HelpBox ("The number of nodes in the graph is zero. The graph might not be scanned",MessageType.Info);
				
				EditorGUI.indentLevel--;
			}
			GUILayoutx.EndFadeArea ();
			
			GUI.color = tmp2;
			
			graphEditor.OnInspectorGUI (graph);
			graphEditor.OnBaseInspectorGUI (graph);
		}

		GUILayoutx.EndFadeArea ();
		
		return false;
	}
コード例 #2
0
	/** Creates a GraphEditor for a graph */
	public GraphEditor CreateGraphEditor (string graphType) {
		
		if (graphEditorTypes.ContainsKey (graphType)) {
			GraphEditor ge = System.Activator.CreateInstance (graphEditorTypes[graphType].editorType) as GraphEditor;
			ge.editor = this;
			return ge;
		} else {
			Debug.LogError ("Couldn't find an editor for the graph type '"+graphType+"' There are "+graphEditorTypes.Count+" available graph editors");
		}
		
		GraphEditor def = new GraphEditor ();
		def.editor = this;
		return def;
	}
コード例 #3
0
	public bool DrawGraph (NavGraph graph, GraphEditor graphEditor) {
		
		Color tmp1 = GUI.color;
		GUILayoutx.BeginFadeArea (graph.open,"","graph_"+graph.guid,graphBoxStyle);
		Color tmp2 = GUI.color;
		GUI.color = tmp1;
		
		GUILayout.BeginHorizontal ();
		string graphNameControl = "graph_"+graph.guid+"_name";
		if (graph.name == null) graph.name = graphEditorTypes[graph.GetType ().Name].displayName;
		
		GUI.SetNextControlName (graphNameControl);
		graph.name = GUILayout.TextField (graph.name, EditorGUILayoutx.defaultLabelStyle, GUILayout.ExpandWidth(false),GUILayout.ExpandHeight(false));
		
		if (graph.name == "" && Event.current.type == EventType.Repaint && GUI.GetNameOfFocusedControl() != graphNameControl) {
			graph.name = graphEditorTypes[graph.GetType ().Name].displayName;
		}
		
		if (GUILayout.Button ("",EditorGUILayoutx.defaultLabelStyle)) {
			graph.open = !graph.open;
			if (!graph.open) {
				graph.infoScreenOpen = false;
			}
			RepaintSceneView ();
			return true;
		}
		
		if (script.prioritizeGraphs) {
			if (GUILayout.Button (new GUIContent ("Up","Increase the graph priority"),GUILayout.Width (40))) {
				int index = script.astarData.GetGraphIndex (graph);
				
				//Find the next non null graph
				int next = index-1;
				for (;next >= 0;next--) if (script.graphs[next] != null) break;
				
				if (next >= 0) {
					NavGraph tmp = script.graphs[next];
					script.graphs[next] = graph;
					script.graphs[index] = tmp;
					
					GraphEditor tmpEditor = graphEditors[next];
					graphEditors[next] = graphEditors[index];
					graphEditors[index] = tmpEditor;
				}
				CheckGraphEditors ();
				Repaint ();
			}
			if (GUILayout.Button (new GUIContent ("Down","Decrease the graph priority"),GUILayout.Width (40))) {
				int index = script.astarData.GetGraphIndex (graph);
				
				//Find the next non null graph
				int next = index+1;
				for (;next<script.graphs.Length;next++) if (script.graphs[next] != null) break;
				
				if (next < script.graphs.Length) {
					NavGraph tmp = script.graphs[next];
					script.graphs[next] = graph;
					script.graphs[index] = tmp;
					
					GraphEditor tmpEditor = graphEditors[next];
					graphEditors[next] = graphEditors[index];
					graphEditors[index] = tmpEditor;
				}
				CheckGraphEditors ();
				Repaint ();
			}
		}
		
		bool drawGizmos = GUILayout.Toggle (graph.drawGizmos,"Draw Gizmos",graphGizmoButtonStyle);
		if (drawGizmos != graph.drawGizmos) {
			graph.drawGizmos = drawGizmos;
			RepaintSceneView ();
		}
		
		if (GUILayout.Toggle (graph.infoScreenOpen,"Info",graphInfoButtonStyle)) {
			if (!graph.infoScreenOpen) {
				graph.infoScreenOpen = true;
				graph.open = true;
			}
		} else {
			graph.infoScreenOpen = false;
		}
		
		if (GUILayout.Button ("Delete",graphDeleteButtonStyle)) {
			RemoveGraph (graph);
			return true;
		}
		GUILayout.EndHorizontal ();
		
		//if (graph.infoScreenOpen) {
			EditorGUILayoutx.FadeArea fadeArea = GUILayoutx.BeginFadeArea (graph.infoScreenOpen,"graph_info_"+graph.guid,0);
			
			if (fadeArea.Show ()) {
				EditorGUILayout.LabelField ("Nodes",graph.nodes == null ? "null" : graph.nodes.Length.ToString ());
				
				int numWalkable = 0;
				
				if (Event.current.type == EventType.Repaint) {
					if (graph.nodes != null) {
						for (int i=0;i<graph.nodes.Length;i++) {
							if (graph.nodes[i] != null && graph.nodes[i].walkable) numWalkable++;
						}
					}
				}
			
				EditorGUI.indentLevel++;
				
				EditorGUILayout.LabelField ("Walkable",graph.nodes != null ? numWalkable.ToString () : "undefined");
				EditorGUILayout.LabelField ("Unwalkable",graph.nodes != null ? (graph.nodes.Length-numWalkable).ToString () : "undefined");
				
				EditorGUI.indentLevel--;
			}
			GUILayoutx.EndFadeArea ();
		//}
		
		GUI.color = tmp2;
		
		graphEditor.OnInspectorGUI (graph);
		graphEditor.OnBaseInspectorGUI (graph);
		
		GUILayoutx.EndFadeArea ();
		
		return false;
	}
コード例 #4
0
ファイル: NodeEditor.cs プロジェクト: Avatarchik/leylines
        public static void DrawNode(GraphEditor editor, Node node)
        {
            EditorGUI.BeginChangeCheck();

            if (Util.IsNull(node))
            {
                return;
            }

            var serializedObject = new SerializedObject(node);

            var inputs  = node.GetInputSockets();
            var outputs = node.GetOutputSockets();

            var inputWidth   = GetContentWidth(node, inputs);
            var inputHeight  = GetPropertyHeights(serializedObject, node, inputs);
            var outputWidth  = GetContentWidth(node, outputs);
            var outputHeight = GetPropertyHeights(serializedObject, node, outputs);
            var height       = Mathf.Max(inputHeight, outputHeight);

            // Draw box
            var rect = new Rect();

            rect.width = inputWidth + outputWidth + BOX_PADDING * 2
                         + SOCKET_RADIUS * 4 + SOCKET_PADDING * 2 + MIDDLE_PADDING;
            if (inputWidth == 0 || outputWidth == 0)
            {
                rect.width -= MIDDLE_PADDING + SOCKET_RADIUS * 2
                              + SOCKET_PADDING;
            }
            rect.height = height + BOX_PADDING * 2;
            rect.center = new Vector2(node.XPos, -node.YPos) + editor.Offset;

            var labelRect = new Rect(rect);

            labelRect.height = EditorGUIUtility.singleLineHeight;
            labelRect.y     -= labelRect.height + LINE_PADDING;
            GUI.Label(labelRect, node.DisplayName);

            var fullRect = new Rect(rect);

            GUI.Box(rect, GUIContent.none);

            rect.x += BOX_PADDING;
            if (inputWidth != 0)
            {
                rect.x += SOCKET_RADIUS * 2 + SOCKET_PADDING;
            }
            rect.y    += BOX_PADDING;
            rect.width = inputWidth;
            var leftRect = new Rect(rect);

            if (inputWidth != 0)
            {
                rect.x += inputWidth + MIDDLE_PADDING;
            }
            rect.width = outputWidth;
            var rightRect = new Rect(rect);

            DrawMembers(true, editor, node, leftRect, serializedObject, inputs);
            DrawMembers(false, editor, node, rightRect, serializedObject, outputs);

            rect = fullRect;
            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (rect.Contains(Event.current.mousePosition))
                {
                    editor.Target = node;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (ReferenceEquals(editor.Target, node))
                {
                    Undo.RecordObject(node, "Move " + node.GetType().Name);

                    if (editor.Snap <= 0)
                    {
                        node.XPos += (int)Event.current.delta.x;
                        node.YPos -= (int)Event.current.delta.y;
                    }
                    else
                    {
                        var graphPos = editor.GraphPosition;
                        node.XPos = Mathf.RoundToInt(graphPos.x / editor.Snap) * editor.Snap;
                        node.YPos = Mathf.RoundToInt(graphPos.y / editor.Snap) * editor.Snap;
                    }

                    Event.current.Use();
                }
                break;

            case EventType.KeyDown:
                switch (Event.current.keyCode)
                {
                case KeyCode.Delete:
                    if (!ReferenceEquals(editor.Target, node))
                    {
                        break;
                    }

                    using (new UndoStack("Remove " + node.DisplayName + " Node"))
                    {
                        Undo.RegisterCompleteObjectUndo(editor.Graph, null);
                        Undo.DestroyObjectImmediate(node);
                    }
                    editor.Graph.Links.RemoveAllWith(node);
                    editor.Graph.Nodes.Remove(node);
                    editor.Target = null;
                    Event.current.Use();
                    break;
                }
                break;
            }

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #5
0
    public bool DrawGraph(NavGraph graph, GraphEditor graphEditor)
    {
        //GUILayout.Label (graph.guid.ToString ());
        //GUILayoutx.BeginFadeArea (graph.open,"","graph_"+graph.guid,graphBoxStyle);

        /*Rect r = EditorGUILayout.BeginVertical (graphBoxStyle);
        GUI.Box (r,"",graphBoxStyle);*/

        Color tmp1 = GUI.color;
        GUILayoutx.BeginFadeArea (graph.open,"","graph_"+graph.guid,graphBoxStyle);
        Color tmp2 = GUI.color;
        GUI.color = tmp1;

        GUILayout.BeginHorizontal ();
        if (GUILayout.Button (graphEditorTypes[graph.GetType ().Name].displayName,EditorGUILayoutx.defaultLabelStyle)) {
            graph.open = !graph.open;
            if (!graph.open) {
                graph.infoScreenOpen = false;
            }
            Repaint ();
        }

        if (script.prioritizeGraphs) {
            if (GUILayout.Button (new GUIContent ("Up","Increase the graph priority"),GUILayout.Width (40))) {
                int index = script.astarData.GetGraphIndex (graph);
                if (index > 0) {
                    NavGraph tmp = script.graphs[index-1];
                    script.graphs[index-1] = graph;
                    script.graphs[index] = tmp;
                }
                Repaint ();
            }
            if (GUILayout.Button (new GUIContent ("Down","Decrease the graph priority"),GUILayout.Width (40))) {
                int index = script.astarData.GetGraphIndex (graph);
                if (index < script.graphs.Length-1) {
                    NavGraph tmp = script.graphs[index+1];
                    script.graphs[index+1] = graph;
                    script.graphs[index] = tmp;
                }
                Repaint ();
            }
        }
        if (GUILayout.Toggle (graph.infoScreenOpen,"Info",graphInfoButtonStyle)) {
            if (!graph.infoScreenOpen) {
                graph.infoScreenOpen = true;
                graph.open = true;
            }
        } else {
            graph.infoScreenOpen = false;
        }

        //GUILayout.FlexibleSpace ();
        if (GUILayout.Button ("Delete",graphDeleteButtonStyle)) {
            RemoveGraph (graph);
            return true;
        }
        GUILayout.EndHorizontal ();

        //if (graph.infoScreenOpen) {
            EditorGUILayoutx.FadeArea fadeArea = GUILayoutx.BeginFadeArea (graph.infoScreenOpen,"graph_info_"+graph.guid,0);

            if (fadeArea.Show ()) {
                EditorGUILayout.LabelField ("Nodes",graph.nodes == null ? "null" : graph.nodes.Length.ToString ());

                int numWalkable = 0;

                if (Event.current.type == EventType.Repaint) {
                    if (graph.nodes != null) {
                        for (int i=0;i<graph.nodes.Length;i++) {
                            if (graph.nodes[i].walkable) numWalkable++;
                        }
                    }
                }

                EditorGUI.indentLevel++;

                EditorGUILayout.LabelField ("Walkable",graph.nodes != null ? numWalkable.ToString () : "undefined");
                EditorGUILayout.LabelField ("Unwalkable",graph.nodes != null ? (graph.nodes.Length-numWalkable).ToString () : "undefined");

                EditorGUI.indentLevel--;
            }
            GUILayoutx.EndFadeArea ();
        //}

        GUI.color = tmp2;

        //if (GUILayoutx.DrawID ("graph_"+graph.guid)) {
            /*if (graph.sourceModifier == null) {
                graph.sourceModifier = new ModifierHolder ();
            }
            graph.sourceModifier.activeModifier = EditorGUILayout.IntField("Modifier",graph.sourceModifier.activeModifier);*/

            //graphEditor.HandleUndo (graph);
            graphEditor.OnInspectorGUI (graph);
        //}

        GUILayoutx.EndFadeArea ();

        return false;
    }
コード例 #6
0
ファイル: EDITOR_Node.cs プロジェクト: BrunoS3D/FastPlay
        public void EDITOR_DrawNode()
        {
            if (!is_ready)
            {
                return;
            }
            gui_color         = GUI.color;
            gui_back_color    = GUI.backgroundColor;
            gui_content_color = GUI.contentColor;

            if (is_active || is_selected || GraphEditor.hover_node == this || (GraphEditor.drag_port && GraphEditor.drag_port.node == this))
            {
            }
            else
            {
                GUI.color = new Color(gui_color.r, gui_color.g, gui_color.b, 0.5f);
            }

            // for better performance
            if (is_occluded)
            {
                foreach (Port port in portValues)
                {
                    if (!port.display_port)
                    {
                        continue;
                    }
                    IPlugIn plug_in = port as IPlugIn;
                    if (plug_in == null || !plug_in.IsPlugged())
                    {
                        continue;
                    }
                    port.node = this;

                    Vector2 start = GetPortPoint(port).center;
                    Vector2 end   = GetPortPoint((Port)plug_in.GetPluggedPort()).center;
                    if (port is ActionPort)
                    {
                        end   = GetPortPoint(port).center;
                        start = GetPortPoint((Port)plug_in.GetPluggedPort()).center;
                    }

                    Node.DrawConnection(start, end, GetPortColor(port), false);
                    if (Application.isPlaying)
                    {
                        if (port.flow_state == FlowState.Active)
                        {
                            port.unit_delta_size = 1.0f;
                            port.flow_state      = FlowState.Idle;
                        }
                        else
                        {
                            port.unit_delta_size = Mathf.MoveTowards(port.unit_delta_size, 0.0f, EditorTime.deltaTime / 2.0f);
                        }

                        GUI.backgroundColor = GetPortColor(port);
                        float distance = FPMath.SnapValue(Vector3.Distance(start, end) / 100.0f, 1);
                        for (int id = 0; id < Mathf.RoundToInt(distance); id++)
                        {
                            float   t         = 1.0f - (((EditorTime.time / distance) + (1.0f / distance) * id) % 1.0f);
                            Vector2 unit_size = V2x16y16 * port.unit_delta_size;
                            GUI.Box(new Rect(LerpUnit(start, end, t) - V2x0y2 - unit_size / 2.0f, unit_size), "", styles.unit);
                        }
                        GUI.backgroundColor = gui_back_color;
                    }
                    else
                    {
                        if (GUI.Button(new Rect(MiddleOfConnection(end, start) - V2x8y9, V2x16y16), "x", styles.unplug_button))
                        {
                            GraphEditor.UnplugPort(port);
                        }
                    }
                }
            }
            else
            {
                if (is_selected)
                {
                    GUI.Box(nodeRect, string.Empty, styles.highlight_node);
                }

                is_active = GraphEditor.makeAllNodesActive || this is EventNode || this is InputNode || this is OutputNode;
                //Draw Node with custom color
                GUI.backgroundColor = node_color;
                if (slim)
                {
                    DrawSlimNode();
                }
                else
                {
                    DrawNode();
                }
                GUI.backgroundColor = gui_back_color;

                // Color gui_color = GUI.color;
                foreach (Port input in inputValues)
                {
                    input.node = this;
                    if (!input.display_port)
                    {
                        continue;
                    }
                    IPlug       plug        = input as IPlug;
                    IPlugIn     plug_in     = input as IPlugIn;
                    bool        on          = plug != null && plug.IsPlugged();
                    IInputValue input_value = input as IInputValue;
                    Rect        port_rect   = GetPortPoint(input);

                    if (plug_in != null)
                    {
                        if (plug_in.IsPlugged())
                        {
                            Vector2 start = port_rect.center;
                            Vector2 end   = GetPortPoint((Port)plug_in.GetPluggedPort()).center;

                            Node.DrawConnection(start, end, GetPortColor(input), false);

                            if (Application.isPlaying)
                            {
                                if (input.flow_state == FlowState.Active)
                                {
                                    input.unit_delta_size = 1.0f;
                                    input.flow_state      = FlowState.Idle;
                                }
                                else
                                {
                                    input.unit_delta_size = Mathf.MoveTowards(input.unit_delta_size, 0.0f, EditorTime.deltaTime / 2.0f);
                                }

                                GUI.backgroundColor = GetPortColor(input);
                                float distance = FPMath.SnapValue(Vector3.Distance(start, end) / 100.0f, 1);
                                for (int id = 0; id < Mathf.RoundToInt(distance); id++)
                                {
                                    float   t         = 1.0f - (((EditorTime.time / distance) + (1.0f / distance) * id) % 1.0f);
                                    Vector2 unit_size = V2x16y16 * input.unit_delta_size;
                                    GUI.Box(new Rect(LerpUnit(start, end, t) - V2x0y2 - unit_size / 2.0f, unit_size), "", styles.unit);
                                }
                                GUI.backgroundColor = gui_back_color;
                            }
                            else
                            {
                                if (GUI.Button(new Rect(MiddleOfConnection(start, end) - V2x8y9, V2x16y16), "x", styles.unplug_button))
                                {
                                    GraphEditor.UnplugPort(input);
                                }
                            }
                        }
                        else if (input_value != null)
                        {
                            if (GraphEditor.showPortValues)
                            {
                                object value = input_value.GetDefaultValue();
                                Rect   value_label_rect;
                                string value_content     = "NO INFO";
                                float  value_label_width = 0.0f;
                                if (value == null)
                                {
                                    if (typeof(UnityEngine.Component).IsAssignableFrom(input_value.valueType) || typeof(Graph).IsAssignableFrom(input_value.valueType) || typeof(UnityEngine.GameObject).IsAssignableFrom(input_value.valueType))
                                    {
                                        if (EditorGUIUtility.isProSkin)
                                        {
                                            value_content = string.Format("<b><color=#0667FF>SELF: {0}</color></b>", input_value.valueType.GetTypeName());
                                        }
                                        else
                                        {
                                            value_content = string.Format("<b><color=#458fff>SELF: {0}</color></b>", input_value.valueType.GetTypeName());
                                        }
                                    }
                                    else
                                    {
                                        value_content = input_value.valueType.GetTypeName(true);
                                    }
                                }
                                else
                                {
                                    if (typeof(string).IsAssignableFrom(input_value.valueType))
                                    {
                                        value_content = string.Format("<color=#FFA06396>\"{0}\"</color>", value);
                                    }
                                    else if (typeof(UnityEngine.Component).IsAssignableFrom(input_value.valueType) || typeof(UnityEngine.GameObject).IsAssignableFrom(input_value.valueType) || typeof(Graph).IsAssignableFrom(input_value.valueType))
                                    {
                                        value_content = string.Format("<b><color=#0667FF>{0}</color></b>", value);
                                    }
                                    else if (typeof(Type).IsAssignableFrom(input_value.valueType))
                                    {
                                        value_content = ReflectionUtils.GetTypeName((Type)value, true);
                                    }
                                    else
                                    {
                                        if (input_value.valueType.IsGenericType)
                                        {
                                            value_content = input_value.valueType.GetTypeName(true);
                                        }
                                        else
                                        {
                                            value_content = value.ToString();
                                        }
                                    }
                                }
                                value_label_width = GUIUtils.GetTextWidth(value_content, styles.input_label);
                                value_label_rect  = new Rect(port_rect.x - (value_label_width + 15.0f), port_rect.y, value_label_width, 18.0f);
                                GUI.Label(value_label_rect, value_content, styles.input_label);
                            }
                        }
                    }

                    port_rect = GraphEditor.ZoomedRect(GetPortPoint(input));
                    if (port_rect.Contains(GraphEditor.mouse_position))
                    {
                        GraphEditor.hover_port = input;
                    }
                    else
                    {
                        GUI.backgroundColor = GetPortColor(input);
                    }
                    port_rect = GetPortPoint(input);

                    if (input is ActionPort)
                    {
                        if (!is_active && ((IPlug)input).IsPlugged())
                        {
                            List <IPlugIn> list = ((IPlugOut)input).GetPluggedPorts();
                            if (list != null && list.Any(p => ((Port)p).node && ((Port)p).node.is_active))
                            {
                                is_active = true;
                            }
                        }
                        GUI.Box(port_rect, slim ? string.Empty : input.name, on ? styles.on_input_action : styles.input_action);
                    }
                    else
                    {
                        GUI.Box(port_rect, slim ? string.Empty : input.name, on ? styles.on_input_port : styles.input_port);
                    }

                    GUI.backgroundColor = gui_back_color;
                }

                foreach (Port output in outputValues)
                {
                    output.node = this;
                    if (!output.display_port)
                    {
                        continue;
                    }
                    IPlug   plug      = output as IPlug;
                    IPlugIn plug_in   = output as IPlugIn;
                    bool    on        = plug != null && plug.IsPlugged();
                    Rect    port_rect = GetPortPoint(output);

                    if (plug_in != null)
                    {
                        if (plug_in.IsPlugged())
                        {
                            Vector2 start = port_rect.center;
                            Vector2 end   = GetPortPoint((Port)plug_in.GetPluggedPort()).center;

                            Node.DrawConnection(end, start, GetPortColor(output), false);

                            if (Application.isPlaying)
                            {
                                if (output.flow_state == FlowState.Active)
                                {
                                    output.unit_delta_size = 1.0f;
                                    output.flow_state      = FlowState.Idle;
                                }
                                else
                                {
                                    output.unit_delta_size = Mathf.MoveTowards(output.unit_delta_size, 0.0f, EditorTime.deltaTime / 2.0f);
                                }

                                float distance = FPMath.SnapValue(Vector3.Distance(start, end) / 100.0f, 1);
                                GUI.backgroundColor = GetPortColor(output);
                                for (int id = 0; id < Mathf.RoundToInt(distance); id++)
                                {
                                    float   t         = 1.0f - (((EditorTime.time / distance) + (1.0f / distance) * id) % 1.0f);
                                    Vector2 unit_size = V2x16y16 * output.unit_delta_size;
                                    GUI.Box(new Rect(LerpUnit(end, start, t) - V2x0y2 - unit_size / 2.0f, unit_size), "", styles.unit);
                                }
                                GUI.backgroundColor = gui_back_color;
                            }
                            else
                            {
                                if (GUI.Button(new Rect(MiddleOfConnection(start, end) - V2x8y9, V2x16y16), "x", styles.unplug_button))
                                {
                                    GraphEditor.UnplugPort(output);
                                }
                            }
                        }
                    }
                    port_rect = GraphEditor.ZoomedRect(GetPortPoint(output));
                    if (port_rect.Contains(GraphEditor.mouse_position))
                    {
                        GraphEditor.hover_port = output;
                    }
                    else
                    {
                        GUI.backgroundColor = GetPortColor(output);
                    }
                    port_rect = GetPortPoint(output);

                    if (output is ActionPort)
                    {
                        GUI.Box(port_rect, slim ? string.Empty : output.name, on ? styles.on_output_action : styles.output_action);
                    }
                    else
                    {
                        if (!is_active && ((IPlug)output).IsPlugged() && ((IPlugOut)output).GetPluggedPorts().Any(p => ((Port)p).node.is_active))
                        {
                            is_active = true;
                        }
                        GUI.Box(port_rect, slim ? string.Empty : output.name, on ? styles.on_output_port : styles.output_port);
                    }
                    GUI.backgroundColor = gui_back_color;
                }
                GUI.backgroundColor = gui_back_color;
            }
            GUI.color           = gui_color;
            GUI.backgroundColor = gui_back_color;
            GUI.contentColor    = gui_content_color;
        }
コード例 #7
0
 public override void Show(GraphEditor graphEditor, GraphPin sourcePin, Vector2 mouseWorld)
 {
     Show(graphEditor);
 }