• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# AstarPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AstarPath的典型用法代码示例。如果您正苦于以下问题:C# AstarPath类的具体用法?C# AstarPath怎么用?C# AstarPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AstarPath类属于命名空间,在下文中一共展示了AstarPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PathThreadInfo

 public PathThreadInfo(int index, AstarPath astar, PathHandler runData)
 {
     this.threadIndex = index;
     this.astar = astar;
     this.runData = runData;
     this.lockObject = new object();
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:7,代码来源:PathThreadInfo.cs


示例2: PathThreadInfo

 public PathThreadInfo(int index, AstarPath astar, NodeRunData runData)
 {
     this.threadIndex = index;
     this.astar = astar;
     this.runData = runData;
     _lock = new object();
 }
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:7,代码来源:astarclasses.cs


示例3: OnComplete

	//This function will be called when the pathfinding is complete, it will be called when the pathfinding returned an error too.
	public void OnComplete (AstarPath.Path p) {
		
		//If the script was already calculating a path when a new path started calculating, then it would have canceled the first path, that will generate an OnComplete message from the first path, this makes sure we only get OnComplete messages from the path we started calculating latest.
		if (path != p) {
			return;
		}
		
		//What should we do if the path returned an error (there is no available path to the target).
		if (path.error) {
			switch (onError) {
				case OnError.None:
					return;
				case OnError.ErrorMessage:
					SendMessage("PathError",new Vector3[0],SendMessageOptions.DontRequireReceiver);
					break;
				case OnError.EmptyArray:
					SendMessage("PathComplete",new Vector3[0],SendMessageOptions.DontRequireReceiver);
					break;
			} 
			return;
		}
		
		if (path.path == null) {
			Debug.LogError ("The 'Path' array is not assigned - System Error - Please send a bug report - Include the following info:\nError = "+p.error+"\nStart = "+startpos+"\nEnd = "+endpos+"\nFound End = "+p.foundEnd+"\nError = "+p.error);
		}
		
		if(path.path.Length > 1) {
			//Convert the Node array to a Vector3 array, subract one from the array if Remove First is true and add one to the array if Use Real End is set to Add
			Vector3[] a = new Vector3[path.path.Length - (removeFirst ? 1 : 0) + (endPoint == RealEnd.AddExact ? 1 : 0)];
			
			for (int i=0;i<path.path.Length;i++) {
				//Ignore the first node if Remove First is set to True
				if (removeFirst && i==0) {
					continue;
				}
				
				a[i - (removeFirst ? 1 : 0)] = path.path[i].vectorPos;
			}
			
			if (startPoint == RealStart.Exact) {
				a[0] = startpos;
			}
			
			//Assign the endpoint
			if (endPoint == RealEnd.AddExact || endPoint == RealEnd.Exact) {
				a[a.Length-1] = endpos;
			}
			
			//Store the path in a variable so it can be drawn in the scene view for debugging
			pathPoints = a;
			
			//Send the Vector3 array to a movement script attached to this gameObject
			SendMessage("PathComplete",a,SendMessageOptions.DontRequireReceiver);
		} else {
			Vector3[] a2 = new Vector3[1] {(endPoint == RealEnd.AddExact || endPoint == RealEnd.Exact ? endpos : startpos)};
			pathPoints = a2;
			SendMessage("PathComplete",a2,SendMessageOptions.DontRequireReceiver);
		}
		
	}
开发者ID:salomonT,项目名称:gamedevelhorse,代码行数:61,代码来源:Seeker.cs


示例4: CreateGraph

    void CreateGraph(AstarPath astar)
    {
        if (!points)
        {
            Debug.LogWarning("missing points root for autopointgraph " + name);
        }

        var graphs = new List<NavGraph>(astar.graphs);
        if (graphs.Contains(graph))
        {
            return;
        }

        graph = new PointGraph();
        graph.active = astar;
        graph.name = "AutoPointGraph (" + name + ")";
        graph.root = points;
        graph.raycast = true;
        graph.maxDistance = 0;
        graph.recursive = true;
        graph.mask = -1;
        
        graphs.Add(graph);
        astar.graphs = graphs.ToArray();
    }
开发者ID:spriest487,项目名称:spacetrader-unity,代码行数:25,代码来源:AutoPointGraph.cs


示例5: GraphNode

		/** Constructor for a graph node. */
		protected GraphNode (AstarPath astar) {
			if (!System.Object.ReferenceEquals(astar, null)) {
				this.nodeIndex = astar.GetNewNodeIndex();
				astar.InitializeNode(this);
			} else {
				throw new System.Exception("No active AstarPath object to bind to");
			}
		}
开发者ID:CCGLP,项目名称:Fast,代码行数:9,代码来源:GraphNode.cs


示例6: Start

    protected override void Start()
    {
        base.Start();

        if(Pathfinding == null) {
            Pathfinding = (AstarPath)GameObject.FindObjectOfType(typeof(AstarPath));
        }
    }
开发者ID:smarthaert,项目名称:talimare,代码行数:8,代码来源:ResourceNode.cs


示例7: InitializeAstarPath

 private void InitializeAstarPath() {
     _astarPath = AstarPath.active;
     _astarPath.scanOnStartup = false;
     // IMPROVE max distance from a worldspace position to a node from my experimentation
     // assuming points surrounding obstacles are set at 0.05 grids away (0.5 * 0.1) from obstacle center
     // and interior sector points are 0.25 grids away from sector center (0.5 * 0.5)
     _astarPath.maxNearestNodeDistance = 600F;
     // TODO other settings
 }
开发者ID:Maxii,项目名称:UnityEntry,代码行数:9,代码来源:AStarPathManager.cs


示例8: GraphNode

		// End of fallback
		
		/** Constructor for a graph node. */
		public GraphNode (AstarPath astar) {
			//this.nodeIndex = NextNodeIndex++;
			if (astar != null) {
				this.nodeIndex = astar.GetNewNodeIndex();
				astar.InitializeNode (this);
			} else {
				throw new System.Exception ("No active AstarPath object to bind to");
			}
		}
开发者ID:henryj41043,项目名称:TheUnseen,代码行数:12,代码来源:GraphNode.cs


示例9: OnGraphScansCompleted

 private void OnGraphScansCompleted(AstarPath astarPath) {
     //if (GameManager.Instance.GameState == GameState.GeneratingPathGraphs) {
     //GameManager.Instance.__ProgressToRunning();
     // TODO need to tell GameManager that it is OK to progress the game state
     // WARNING: I must not directly cause the game state to change as the other subscribers to 
     // GameStateChanged may not have been called yet. This GraphScansCompletedEvent occurs 
     // while we are still processing OnGameStateChanged
     //}
 }
开发者ID:Maxii,项目名称:UnityEntry,代码行数:9,代码来源:AStarPathManager.cs


示例10: CreateGraphIfItNull

 /// <summary>
 /// Editor only!!!
 /// </summary>
 public static void CreateGraphIfItNull(AstarPath path)
 {
     if (path == null)
     {
         Debug.LogWarning("AstarPath not found");
         return;
     }
     if (path.astarData == null || path.astarData.gridGraph == null)
         AstarPath.MenuScan();
 }
开发者ID:upsky,项目名称:domru,代码行数:13,代码来源:AstarPathUtils.cs


示例11: Start

    int zFront = 0; //forward

    #endregion Fields

    #region Methods

    // Use this for initialization
    void Start()
    {
        dropDownMenuObject = GameObject.Find("Panel").GetComponent<DropDownMenu>();
        missionReader = GameObject.FindGameObjectWithTag("Grid").GetComponent<MissionReader>();
        astarPath = GameObject.FindGameObjectWithTag("Grid").GetComponent<AstarPath>();
        xLeft = -27;
        xRight = 27;
        zFront = -110;
        zBack = -140;
    }
开发者ID:Kitsuneenvy,项目名称:MajorProject,代码行数:17,代码来源:CameraMovement.cs


示例12: DoStuff

        public void DoStuff()
        {
            if (!astarPath.IsNone && astarPath.Value != null)
            { astarp = FsmConverter.GetAstarPath(astarPath); }
            else
            { astarp = AstarPath.active; }

            if(!isScanning.IsNone)
            { isScanning.Value = astarp.isScanning;	}

            if(!showGraphs.IsNone)
            { showGraphs.Value = astarp.showGraphs;	}

            if(!IsUsingMultithreading.IsNone)
            { IsUsingMultithreading.Value = AstarPath.IsUsingMultithreading; }

            if(!IsAnyGraphUpdatesQueued.IsNone)
            { IsAnyGraphUpdatesQueued.Value = astarp.IsAnyGraphUpdatesQueued; }

            if(!lastUniqueAreaIndex.IsNone)
            { lastUniqueAreaIndex.Value = astarp.lastUniqueAreaIndex; }

            if(!ActiveThreadsCount.IsNone)
            { ActiveThreadsCount.Value = AstarPath.ActiveThreadsCount; }

            if(!NumParallelThreads.IsNone)
            { NumParallelThreads.Value = AstarPath.NumParallelThreads;	}

            if(!Version.IsNone)
            { Version.Value = AstarPath.Version.ToString(); }

            if(!graphs.IsNone)
            { graphs.Value = FsmConverter.SetNavGraphs(astarp.graphs); }

            if(!activeAstarPath.IsNone)
            { activeAstarPath.Value = FsmConverter.SetAstarPath(AstarPath.active);	}

            if (!astarData.IsNone)
            { astarData.Value = FsmConverter.SetNavGraphs(astarp.graphs); }
            return;
        }
开发者ID:kiriri,项目名称:playmaker-astar-actions,代码行数:41,代码来源:getAStarPathInfo.cs


示例13: DoStuff

        public void DoStuff()
        {
            if (!astarPath.IsNone && astarPath.Value != null)
            { astarp = FsmConverter.GetAstarPath(astarPath); }
            else
            { astarp = AstarPath.active; }

            if(!isScanning.IsNone)
            { astarp.isScanning = isScanning.Value;	}

            if(!showGraphs.IsNone)
            { astarp.showGraphs = showGraphs.Value; }

            if(!lastUniqueAreaIndex.IsNone)
            { astarp.lastUniqueAreaIndex = lastUniqueAreaIndex.Value; }

            if (!astarData.IsNone)
            { astarp.graphs = FsmConverter.GetNavGraphs(astarData.Value); }

            return;
        }
开发者ID:kiriri,项目名称:playmaker-astar-actions,代码行数:21,代码来源:setAStarPathInfo.cs


示例14: PathProcessor

		public PathProcessor (AstarPath astar, PathReturnQueue returnQueue, int processors, bool multithreaded) {
			this.astar = astar;
			this.returnQueue = returnQueue;

			if (processors < 0) {
				throw new System.ArgumentOutOfRangeException("processors");
			}

			if (!multithreaded && processors != 1) {
				throw new System.Exception("Only a single non-multithreaded processor is allowed");
			}

			// Set up path queue with the specified number of receivers
			queue = new ThreadControlQueue(processors);
			threadInfos = new PathThreadInfo[processors];

			for (int i = 0; i < processors; i++) {
				threadInfos[i] = new PathThreadInfo(i, astar, new PathHandler(i, processors));
			}

			if (multithreaded) {
				threads = new Thread[processors];

				// Start lots of threads
				for (int i = 0; i < processors; i++) {
					var threadIndex = i;
					var thread = new Thread (() => CalculatePathsThreaded(threadInfos[threadIndex]));
					thread.Name = "Pathfinding Thread " + i;
					thread.IsBackground = true;
					threads[i] = thread;
					thread.Start();
				}
			} else {
				// Start coroutine if not using multithreading
				threadCoroutine = CalculatePaths(threadInfos[0]);
			}
		}
开发者ID:legionaryu,项目名称:Atom-defender,代码行数:37,代码来源:PathProcessor.cs


示例15: SerializeSettings

        /** Called to serialize a graphs settings. \note Before calling this, setting #sPrefix to something unique for the graph is a good idea to avoid collisions in variable names */
        public void SerializeSettings(NavGraph graph, AstarPath active)
        {
            ISerializableGraph serializeGraph = graph as ISerializableGraph;

            if (serializeGraph == null) {
                Debug.LogError ("The graph specified is not serializable, the graph is of type "+graph.GetType());
                return;
            }

            serializeGraph.SerializeSettings (this);
        }
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:12,代码来源:AstarSerialize.cs


示例16: AstarSerializer

 public AstarSerializer(AstarPath script)
 {
     active = script;
     astarData = script.astarData;
     mask = -1;
     mask -= SMask.SaveNodes;
 }
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:7,代码来源:AstarSerialize.cs


示例17: SerializeNodes

        /** Serializes the nodes in the graph.
         * \astarpro */
        public void SerializeNodes(NavGraph graph, AstarPath active)
        {
            if (mask == SMask.SaveNodes) {

                ISerializableGraph serializeGraph = graph as ISerializableGraph;

                if (serializeGraph == null) {
                    Debug.LogError ("The graph specified is not serializable, the graph is of type "+graph.GetType());
                    return;
                }

                if (graph.nodes == null || graph.nodes.Length == 0) {
                    writerStream.Write (0);
                    //Debug.LogWarning ("No nodes to serialize");
                    return;
                }

                writerStream.Write (graph.nodes.Length);

                //writerStream.Write (savingToFile ? 753 : 1337);
                Debug.Log ("Stored nodes "+" "+writerStream.BaseStream.Position);

                SizeProfiler.Begin ("Graph specific nodes",writerStream);

                AddVariableAnchor ("DeserializeGraphNodes");
                serializeGraph.SerializeNodes (graph.nodes,this);

                SizeProfiler.End ("Graph specific nodes",writerStream);

                AddVariableAnchor ("DeserializeNodes");

                if (mask == SMask.RunLengthEncoding) {

                    SizeProfiler.Begin ("RLE Penalty",writerStream);
                    //Penalties
                    int lastValue = (int)graph.nodes[0].penalty;
                    int lastEntry = 0;

                    for (int i=1;i<graph.nodes.Length;i++) {
                        if (graph.nodes[i].penalty != lastValue || (i-lastEntry) >= byte.MaxValue-1) {
                            writerStream.Write ((byte)(i-lastEntry));
                            writerStream.Write (lastValue);
                            lastValue = (int)graph.nodes[i].penalty;
                            lastEntry = i;
                        }
                    }

                    writerStream.Write ((byte)(graph.nodes.Length-lastEntry));
                    writerStream.Write (lastValue);

                    SizeProfiler.Begin ("RLE Flags",writerStream);

                    //Flags
                    lastValue = graph.nodes[0].flags;
                    lastEntry = 0;

                    for (int i=1;i<graph.nodes.Length;i++) {
                        if (graph.nodes[i].flags != lastValue || (i-lastEntry) >= byte.MaxValue) {
                            writerStream.Write ((byte)(i-lastEntry));
                            writerStream.Write (lastValue);
                            lastValue = graph.nodes[i].flags;
                            lastEntry = i;
                        }
                    }
                    writerStream.Write ((byte)(graph.nodes.Length-lastEntry));
                    writerStream.Write (lastValue);

                    SizeProfiler.End ("RLE Flags",writerStream);
                }

                SizeProfiler.Begin ("Nodes, other",writerStream);

                for (int i=0;i<graph.nodes.Length;i++) {
                    SerializeNode (graph.nodes[i], writerStream);
                }

                SizeProfiler.End ("Nodes, other",writerStream);
            }
        }
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:81,代码来源:AstarSerialize.cs


示例18: SerializeEditorSettings

        public void SerializeEditorSettings(NavGraph graph, ISerializableGraphEditor editor, AstarPath active)
        {
            if (editor == null) {
                Debug.LogError ("The editor specified is Null");
                return;
            }

            //The script will return to this value and write the number of variables serialized with the simple serializer
            positionAtCounter = (int)writerStream.BaseStream.Position;
            writerStream.Write (0);//This will be overwritten
            counter = 0;

            editor.SerializeSettings (graph,this);
        }
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:14,代码来源:AstarSerialize.cs


示例19: FindTagNames

	/** Tries to find an AstarPath object and return tag names.
	 * If an AstarPath object cannot be found, it returns an array of length 1 with an error message.
	 * \see AstarPath.GetTagNames
	 */
	public static string[] FindTagNames () {
		if (active != null) return active.GetTagNames ();
		else {
			AstarPath a = GameObject.FindObjectOfType (typeof (AstarPath)) as AstarPath;
			if (a != null) { active = a; return a.GetTagNames (); }
			else {
				return new string[1] {"There is no AstarPath component in the scene"};
			}
		}
	}
开发者ID:JackHR,项目名称:WaveIncoming,代码行数:14,代码来源:AstarPath.cs


示例20: OnDestroy

	/** Clears up variables and other stuff, destroys graphs.
	 * Note that when destroying an AstarPath object, all static variables such as callbacks will be cleared.
	 */
	public void OnDestroy () {
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("+++ AstarPath Component Destroyed - Cleaning Up Pathfinding Data +++");
		
		if ( active != this ) return;
		
		
		//Don't accept any more path calls to this AstarPath instance.
		//This will cause all eventual multithreading threads to exit
		pathQueue.TerminateReceivers();

		BlockUntilPathQueueBlocked();
		FlushWorkItems ();

		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Processing Eventual Work Items");
		
		// Process work items until done 
		// Nope, don't do this
		//PerformBlockingActions (true);
		
		//Resume graph update thread, will cause it to terminate
		graphUpdateAsyncEvent.Set();
		
		//Try to join pathfinding threads
		if (threads != null) {
			for (int i=0;i<threads.Length;i++) {
#if UNITY_WEBPLAYER
				if (!threads[i].Join(200)) {
					Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 200ms." +
						"Not good.\nUnity webplayer does not support Thread.Abort\nHoping that it will be terminated by Unity WebPlayer");
				}
#else
				if (!threads[i].Join (50)) {
					Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 50ms, trying Thread.Abort");
					threads[i].Abort ();
				}
#endif
			}
		}
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Returning Paths");
		
		
		//Return all paths
		ReturnPaths (false);
		//Just in case someone happened to request a path in ReturnPath() (even though they should get canceled)
		pathReturnStack.PopAll ();
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Destroying Graphs");

		
		//Clean graphs up
		astarData.OnDestroy ();
		
		if (logPathResults == PathLog.Heavy)
			Debug.Log ("Cleaning up variables");
		
		//Clear variables up, static variables are good to clean up, otherwise the next scene might get weird data
		floodStack = null;
		graphUpdateQueue = null;
		
		//Clear all callbacks
		OnDrawGizmosCallback	= null;
		OnAwakeSettings			= null;
		OnGraphPreScan			= null;
		OnGraphPostScan			= null;
		OnPathPreSearch			= null;
		OnPathPostSearch		= null;
		OnPreScan				= null;
		OnPostScan				= null;
		OnLatePostScan			= null;
		On65KOverflow			= null;
		OnGraphsUpdated			= null;
		OnSafeCallback			= null;
		OnThreadSafeCallback	= null;
		
		threads = null;
		threadInfos = null;
		
		PathsCompleted = 0;
		
		active = null;
		
	}
开发者ID:JackHR,项目名称:WaveIncoming,代码行数:91,代码来源:AstarPath.cs



注:本文中的AstarPath类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AsymmetricAlgorithm类代码示例发布时间:2022-05-24
下一篇:
C# AstType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap