本文整理汇总了C#中GraphNode类的典型用法代码示例。如果您正苦于以下问题:C# GraphNode类的具体用法?C# GraphNode怎么用?C# GraphNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphNode类属于命名空间,在下文中一共展示了GraphNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawGraphNodeGizmo
public static void DrawGraphNodeGizmo(GraphNode node, GizmoType type)
{
using (new GizmosColor(GraphEditorWindow.GetGraphColor(node.graph))) {
if (node.graph == null) {
Vector3 nodePinPosition = node.transform.position + GraphEditorWindow.GetGraphNodePinShift(node);
Gizmos.DrawLine(node.transform.position, nodePinPosition);
Gizmos.DrawWireSphere(nodePinPosition, GraphEditorWindow.GraphNodePinRadius * 1.1f);
return;
}
if ((type & GizmoType.Selected) != 0) {
GraphEditor.DrawGraphGizmo(node.graph, GizmoType.NonSelected);
Vector3 pinShift = GraphEditorWindow.GetGraphNodePinShift(node);
Vector3 nodePinPosition = node.transform.position + pinShift;
Gizmos.DrawLine(node.transform.position, nodePinPosition);
Gizmos.DrawWireSphere(nodePinPosition, GraphEditorWindow.GraphNodePinRadius * 1.1f);
foreach (GraphNode linkedNode in node.EnumLinkedNodes()) {
Gizmos.DrawLine(nodePinPosition, linkedNode.transform.position + pinShift);
}
}
else if (type == GizmoType.NonSelected) {
Vector3 pinShift = GraphEditorWindow.GetGraphNodePinShift(node);
Vector3 nodePinPosition = node.transform.position + pinShift;
Gizmos.DrawLine(node.transform.position, nodePinPosition);
Gizmos.DrawSphere(nodePinPosition, GraphEditorWindow.GraphNodePinRadius);
}
}
}
示例2: SetCurrentNode
public void SetCurrentNode(GraphNode gn) {
if(currentNode != null)
currentNode.SetActive(false);
currentNode = gn;
currentNode.SetActive(true);
}
示例3: GraphEdge
public GraphEdge(GraphNode source, GraphNode destination)
{
this._source = source;
this._destination = destination;
source.AdjecentEdges.Add(this);
}
示例4: findLinkV5
public static bool findLinkV5(GraphNode start, GraphNode end)
{
System.Collections.Generic.Queue<GraphNode> searched = new System.Collections.Generic.Queue<GraphNode>();
searched.Enqueue(start);
start.state = Visiting;
while (searched.Count!=0)
{
GraphNode gn = searched.Dequeue();
if (gn!=null)
{
gn.state = Visited;
foreach (GraphNode node in gn.Nodes)
{
if (node.state == Unvisitied)
{
if (node == end)
{
return true;
}
node.state = Visiting;
searched.Enqueue(node);
}
}
}
}
return false;
}
示例5: ShouldFindShortesPathWhen1PathExists
public void ShouldFindShortesPathWhen1PathExists()
{
//http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
var one = new GraphNode<int>(1);
var two = new GraphNode<int>(2);
var three = new GraphNode<int>(3);
var four = new GraphNode<int>(4);
var five = new GraphNode<int>(5);
var six = new GraphNode<int>(6);
one.AddNeighbour(six, 14);
one.AddNeighbour(three, 9);
one.AddNeighbour(two, 7);
two.AddNeighbour(three, 10);
two.AddNeighbour(four, 15);
three.AddNeighbour(six, 2);
three.AddNeighbour(four, 11);
four.AddNeighbour(five, 6);
five.AddNeighbour(six, 9);
var graph = new List<GraphNode<int>> {one, two, three, four, five, six};
var dijkstra = new Dijkstra<int>(graph);
var path = dijkstra.FindShortestPathBetween(one, five);
path[0].Value.ShouldBe(1);
path[1].Value.ShouldBe(3);
path[2].Value.ShouldBe(6);
path[3].Value.ShouldBe(5);
}
示例6: TestMatrixGraph
public void TestMatrixGraph()
{
var emptyGraph = new MatrixGraph<int>();
var root = new GraphNode<int>(10);
var expandedGraph = root.MakeEdges<int>(null);
}
示例7: PopulateMapsForFileInputNode
private void PopulateMapsForFileInputNode(GraphNode inputNode)
{
using (_gate.DisposableWait())
{
var projectPath = inputNode.Id.GetNestedValueByName<Uri>(CodeGraphNodeIdName.Assembly);
var filePath = inputNode.Id.GetNestedValueByName<Uri>(CodeGraphNodeIdName.File);
if (projectPath == null || filePath == null)
{
return;
}
var project = _solution.Projects.FirstOrDefault(
p => string.Equals(p.FilePath, projectPath.OriginalString, StringComparison.OrdinalIgnoreCase));
if (project == null)
{
return;
}
_nodeToContextProjectMap.Add(inputNode, project);
var document = project.Documents.FirstOrDefault(
d => string.Equals(d.FilePath, filePath.OriginalString, StringComparison.OrdinalIgnoreCase));
if (document == null)
{
return;
}
_nodeToContextDocumentMap.Add(inputNode, document);
}
}
示例8: ConstructDependencyGraph
/// <summary>
/// Construct a depdenency graph of the <see cref="Character"/>'s <see cref="ModifierSource"/>s.
/// </summary>
/// <param name="character">
/// The <see cref="Character"/> to generate the dependency graph for. This cannot be null.
/// </param>
/// <param name="modifierSources">
/// The already extracted list of <see cref="ModifierSource"/>s to use. This cannot be null.
/// </param>
/// <returns>
/// A <see cref="GraphNode{ModifierSource}"/> that is the root node of a dependency graph. The root
/// node can be ignored and is not part of the graph itself.
/// </returns>
/// <exception cref="ArgumentNullException">
/// No argument can be null.
/// </exception>
internal static GraphNode<ModifierSource> ConstructDependencyGraph(Character character, IList<ModifierSource> modifierSources)
{
if (character == null)
{
throw new ArgumentNullException("character");
}
if (modifierSources == null)
{
throw new ArgumentNullException("modifierSources");
}
GraphNode<ModifierSource> root;
IEqualityComparer<ModifierSource> comparer;
Dictionary<ModifierSource, GraphNode<ModifierSource>> graphNodeLookup;
// Rather than use "EqualityComparer<ModifierSource>.Default", use identity equality.
// This allows two instances of the same modifier source with the same name to be used
// within the graph. This can occur frequently with powers.
comparer = new IdentityEqualityComparer<ModifierSource>();
// Optimization for GraphNode.Find().
graphNodeLookup = new Dictionary<ModifierSource, GraphNode<ModifierSource>>();
// Construct a dependency graph.
root = new GraphNode<ModifierSource>(new NullModifierSource(), comparer);
foreach (ModifierSource modifierSource in modifierSources)
{
List<KeyValuePair<ModifierSource, ModifierSource>> dependencies;
GraphNode<ModifierSource> parentGraphNode;
GraphNode<ModifierSource> childGraphNode;
// Get the dependencies
dependencies = modifierSource.GetDependencies(character);
// For each dependency, find the source ModifierSource and add
// the destination under it.
foreach (KeyValuePair<ModifierSource, ModifierSource> dependency in dependencies)
{
// Find the parent of the dependency
if (!graphNodeLookup.TryGetValue(dependency.Key, out parentGraphNode))
{
parentGraphNode = new GraphNode<ModifierSource>(dependency.Key, comparer);
root.AddChild(parentGraphNode);
graphNodeLookup[dependency.Key] = parentGraphNode;
}
// Find the child of the dependency
if (!graphNodeLookup.TryGetValue(dependency.Value, out childGraphNode))
{
childGraphNode = new GraphNode<ModifierSource>(dependency.Value, comparer);
graphNodeLookup[dependency.Value] = childGraphNode;
}
// Add the child to the parent
parentGraphNode.AddChild(childGraphNode);
}
}
return root;
}
示例9: Save
public static void Save(PlanerCore planer, GraphNode node, int direction, bool onPlaySave)
{
//Debug.Log("OnSave");
//PlayerPrefs.DeleteAll();
PlayerPrefs.SetInt("MineCount", planer.MineController.Mines.Count);
//Debug.Log(Application.loadedLevelName);
string currentLevel = Application.loadedLevelName;
if (currentLevel == "GlobalMap")
currentLevel = Creator.PreviousLevel;
PlayerPrefs.SetString("CurrentLevel", currentLevel);
for (int i = 0; i < planer.MineController.Mines.Count; i++)
{
PlayerPrefs.SetInt("Mine" + i, Armory.WeaponIndex(planer.MineController.Mines[i].GetType().Name));
}
if (onPlaySave)
{
PlayerPrefs.SetInt("XCoord", node.X);
PlayerPrefs.SetInt("YCoord", node.Y);
PlayerPrefs.SetInt("IndexCoord", node.Index);
PlayerPrefs.SetInt("LevelCoord", node.Level);
if(direction<0)
direction=planer.Direction;
PlayerPrefs.SetInt("Direction", direction);
}
}
示例10: AStarNode
public AStarNode(GraphNode<StateConfig> state, AStarNode parent, float pathCost, float estCost)
{
this.state = state;
this.parent = parent;
this.pathCost = pathCost;
this.estCost = estCost;
}
示例11: Main
static void Main(string[] args)
{
GraphNode rootGraph = new GraphNode(null, "Root");
GraphNode child1 = new GraphNode(null, "Child1");
GraphNode child2 = new GraphNode(null, "Child2");
rootGraph.AddChildNode(child1);
rootGraph.AddChildNode(child2);
// physics update frame 1 ----------------------------
Console.WriteLine("*** Frame 1 ***");
child2.SetTransform(new Transform(child2.Local.Name)); // simulates some kind of physical force
Console.WriteLine("----- Simple traversal -----");
rootGraph.SimpleRender(Transform.Origin);
Console.WriteLine();
Console.WriteLine("----- Dirty-flag traversal -----");
rootGraph.DirtyFlagRender(Transform.Origin, rootGraph.Dirty);
Console.WriteLine();
Console.WriteLine();
// physics update frame 2 ----------------------------
Console.WriteLine("*** Frame 2 ***");
child1.SetTransform(new Transform(child1.Local.Name)); // simulates some kind of physical force
Console.WriteLine();
Console.WriteLine("----- Simple traversal -----");
rootGraph.SimpleRender(Transform.Origin);
Console.WriteLine();
Console.WriteLine("----- Dirty-flag traversal -----");
rootGraph.DirtyFlagRender(Transform.Origin, rootGraph.Dirty);
Console.WriteLine();
Console.WriteLine();
// physics update frame 3 ----------------------------
Console.WriteLine("*** Frame 3 ***");
rootGraph.SetTransform(new Transform(rootGraph.Local.Name)); // simulates some kind of physical force
Console.WriteLine();
Console.WriteLine("----- Simple traversal -----");
rootGraph.SimpleRender(Transform.Origin);
Console.WriteLine();
Console.WriteLine("----- Dirty-flag traversal -----");
rootGraph.DirtyFlagRender(Transform.Origin, rootGraph.Dirty);
Console.ReadLine();
}
示例12: AddNode
public void AddNode(Vector3 neighborPoint, ref GraphNode currentNode, ref Queue<GraphNode> q )
{
RaycastHit hitInfo;
Vector3 rayDirection = Vector3.zero;
#if USE_XZ
rayDirection = new Vector3(0, -1, 0);
#else
rayDirection = new Vector3(0, 0, 1);
#endif //USE_XZ
int layerMask = 1 << 8;
layerMask = ~layerMask;
if ( Physics.Raycast(neighborPoint, rayDirection, out hitInfo, Mathf.Infinity, layerMask) )
{
if (hitInfo.transform.tag == "Ground")
{
GraphNode newNode = new GraphNode(mNumOfNodes, hitInfo.point); // make a new node for this point
GraphEdge newEdge = new GraphEdge(currentNode.GetIndex(), newNode.GetIndex()); // creat a new edge
int index = 0;
bool nodeFound = false;
while ( !nodeFound && index <= mNumOfNodes )
{
//Debug.Log (index + " out of " + NavigationGraph.Length + " thinks there's only" + mNumOfNodes);
nodeFound = ( NavigationGraph[index] == hitInfo.point );
++index;
}
if ( !nodeFound ) // if we have not found this node before, add it
{
Nodes.Add(newNode);
NavigationGraph[mNumOfNodes] = hitInfo.point;
++mNumOfNodes;
q.Enqueue(newNode);
}
else
{
newEdge.SetToIndex(index-1);
}
// If the raycast hit then we will always want to add the edge, since we want edges
// in both directions and there won't ever be duplicates.
// check if there is a clear path to add an edge
Vector3 heightOffset = Vector3.zero;
#if USE_XZ
heightOffset = new Vector3(0, 0.5f, 0);
#else
heightOffset = new Vector3(0, 0, -0.5f);
#endif // USE_XZ
if ( !Physics.Linecast(currentNode.GetPosition() + heightOffset, newNode.GetPosition() + heightOffset, out hitInfo, layerMask) )
{
Edges.Add(newEdge);
currentNode.AddEdge(newEdge);
}
}
}
}
示例13: AddNode
public int AddNode(Vector3 position)
{
Nodes.Add(new GraphNode(NextNodeIndex, position));
Edges.Add(new List<GraphEdge>());
GraphNode n = new GraphNode(NextNodeIndex, position);
NextNodeIndex++;
return NextNodeIndex - 1;
}
示例14: SetState
public void SetState(MshipState s, GraphNode n) {
state = s;
gn = n;
if(s == MshipState.TRAVEL)
travelDist = (gn.transform.position - transform.position).magnitude - orbitDist;
}
示例15: Awake
void Awake()
{
foreach (Anchor anchor in GetComponentsInChildren<Anchor>()) {
anchorList.Add(anchor);
}
graphNode = GetComponentInChildren<GraphNode> ();
renderers = GetComponentsInChildren<Renderer> ();
}