当前位置: 首页>>代码示例>>C#>>正文


C# Seeker.StartCoroutine方法代码示例

本文整理汇总了C#中Seeker.StartCoroutine方法的典型用法代码示例。如果您正苦于以下问题:C# Seeker.StartCoroutine方法的具体用法?C# Seeker.StartCoroutine怎么用?C# Seeker.StartCoroutine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Seeker的用法示例。


在下文中一共展示了Seeker.StartCoroutine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Navigate

 private IEnumerator Navigate(Seeker seeker)
 {
     while (!Done)
     {
         if (TaskFollower.Ship.CanSee(destination))
         {
             TaskFollower.Ship.ResetControls(thrust: 1);
             TaskFollower.Ship.RotateToPoint(destination);                
             
             yield return new WaitForSeconds(SHORT_THINK);
         }
         else
         {
             TaskFollower.Ship.ResetControls();
             yield return seeker.StartCoroutine(FollowWorldPath(seeker));
         }
     }
 }
开发者ID:spriest487,项目名称:spacetrader-unity,代码行数:18,代码来源:NavigateTask.cs

示例2: FollowWorldPath

    private IEnumerator FollowWorldPath(Seeker seeker)
    {
        //get a world path to target
        Debug.Log("getting a new world path...");
        var path = seeker.StartPath(TaskFollower.transform.position, destination, null, 1);
        yield return seeker.StartCoroutine(path.WaitForPath());

        if (path.error)
        {
            Debug.Log("world path failed");

            do
            {
                if (TaskFollower.Ship.CanSee(destination))
                {
                    TaskFollower.Ship.ResetControls(thrust: 1);
                    TaskFollower.Ship.RotateToPoint(destination);
                    yield return new WaitForSeconds(LONG_THINK);
                }
                else
                {
                    //feel our way forward blindly
                    var pos = TaskFollower.transform.position;
                    var between = destination - pos;

                    float lookAhead;
                    if (!GuessSizeOfObstacleInFront(between, out lookAhead))
                    {
                        lookAhead = TaskFollower.Ship.CurrentStats.MaxSpeed;
                    }

                    var aheadDest = pos + (between.normalized * lookAhead);

                    yield return seeker.StartCoroutine(FollowLocalPath(seeker, aheadDest));
                }                
            }
            while (!Done);
            
            yield break;
        }

        int pointIt = 0;

        do
        {
            //if at any point we can see the destination directly, go for that instead
            if (TaskFollower.Ship.CanSee(destination))
            {
                Debug.Log("giving up on world nav path because we can see the destination");
                TaskFollower.Ship.ResetControls(thrust: 1);
                TaskFollower.Ship.RotateToPoint(destination);
                yield return new WaitForSeconds(LONG_THINK);
                yield break;
            }

            var point = path.vectorPath[pointIt];
            bool lastPoint = pointIt == path.vectorPath.Count - 1;

            //can we see it?
            if (!TaskFollower.Ship.CanSee(point))
            {
                Debug.Log("can't see next world node, trying a local obstacle route");
                yield return seeker.StartCoroutine(FollowLocalPath(seeker, point));

                //start navigation again when we're done with that path
                yield break;
            }

            if (!lastPoint)
            {
                /* when doing world nav, skip a point if we can already see a clear path
                to the next point*/
                var nextPoint = path.vectorPath[pointIt + 1];
                if (TaskFollower.Ship.CanSee(nextPoint))
                {
                    ++pointIt;
                    continue;
                }
            }

            TaskFollower.Ship.ResetControls(thrust: 1);
            TaskFollower.Ship.RotateToPoint(point);

            if (TaskFollower.Ship.IsCloseTo(point))
            {
                ++pointIt;
            }
            else
            {
                yield return new WaitForSeconds(LONG_THINK);
            }
        }
        while (pointIt < path.vectorPath.Count);

        //if we reach the end of a world path and still can't see the target, look for a local obstacle path
        if (pointIt == path.vectorPath.Count
            && !TaskFollower.Ship.CanSee(destination))
        {
            Debug.Log("reached end of world path and couldn't see the dest, trying to navigate local obstacles");
            yield return seeker.StartCoroutine(FollowLocalPath(seeker, destination));
//.........这里部分代码省略.........
开发者ID:spriest487,项目名称:spacetrader-unity,代码行数:101,代码来源:NavigateTask.cs

示例3: FollowLocalPath

    private IEnumerator FollowLocalPath(Seeker seeker, Vector3 worldDest)
    {
        var localPath = seeker.StartPath(TaskFollower.transform.position, worldDest, null, ~1);
        yield return seeker.StartCoroutine(localPath.WaitForPath());

        if (localPath.error)
        {
            Debug.Log("local path failed, going back to world nav");
            TaskFollower.Ship.ResetControls(thrust: 1);
            TaskFollower.Ship.RotateToPoint(worldDest);

            yield return new WaitForSeconds(LONG_THINK);
            yield break;
        }

        //follow the local obstacle's path
        int pointIt = 0;
        do
        {
            var point = localPath.vectorPath[pointIt];
            bool lastPoint = pointIt == localPath.vectorPath.Count - 1;

            TaskFollower.Ship.ResetControls(thrust: 1);
            TaskFollower.Ship.RotateToPoint(point, Vector3.up);
            
            if (!TaskFollower.Ship.CanSee(point))
            {
                Debug.Log("cancelling local route since we can't see the next node");
                yield return new WaitForSeconds(LONG_THINK);
                yield break;
            }

            if (!lastPoint)
            {
                /* skip points if we can already see the next point */
                var nextPoint = localPath.vectorPath[pointIt + 1];
                if (TaskFollower.Ship.CanSee(nextPoint))
                {
                    ++pointIt;
                    continue;
                }
            }

            if (TaskFollower.Ship.IsCloseTo(point))
            {
                ++pointIt;
                Debug.Log("reached a waypoint on our local route");
            }
            else
            {
                //Debug.Log("flying on local route...");
                yield return new WaitForSeconds(SHORT_THINK);
            }
        }
        while (pointIt < localPath.vectorPath.Count);

        Debug.Log("stopped following a local route");
    }
开发者ID:spriest487,项目名称:spacetrader-unity,代码行数:58,代码来源:NavigateTask.cs


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