本文整理汇总了C#中UnityEngine.NavMeshPath类的典型用法代码示例。如果您正苦于以下问题:C# NavMeshPath类的具体用法?C# NavMeshPath怎么用?C# NavMeshPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NavMeshPath类属于UnityEngine命名空间,在下文中一共展示了NavMeshPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CalculatePathLength
float CalculatePathLength(Vector3 targetPosition)
{
// Create a path and set it based on a target position.
NavMeshPath path = new NavMeshPath();
if (nav.enabled)
nav.CalculatePath(targetPosition, path);
// Create an array of points which is the length of the number of corners in the path + 2.
Vector3[] allWayPoints = new Vector3[path.corners.Length + 2];
// The first point is the enemy's position.
allWayPoints[0] = transform.position;
// The last point is the target position.
allWayPoints[allWayPoints.Length - 1] = targetPosition;
// The points inbetween are the corners of the path.
for (int i = 0; i < path.corners.Length; i++)
{
allWayPoints[i + 1] = path.corners[i];
}
// Create a float to store the path length that is by default 0.
float pathLength = 0;
// Increment the path length by an amount equal to the distance between each waypoint and the next.
for (int i = 0; i < allWayPoints.Length - 1; i++)
{
pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
}
return pathLength;
}
开发者ID:Defsv,项目名称:UJelly-ProtoType1,代码行数:32,代码来源:EnemySight.cs
示例2: InteractWithNearestState
public InteractWithNearestState(NavMeshAgent agent, string tag, GameObject pickup)
{
_agent = agent;
cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();
_interactGameObject = pickup;
var interactables = GameObject.FindGameObjectsWithTag(tag);
if (interactables.Length < 1)
{
GameObject.FindGameObjectWithTag("AudioManager").GetComponent<AudioManager>().FemaleNoSoundPlay();
_state = State.Done;
return;
}
foreach (var i in interactables)
{
_interactGameObject = i;
var dest = i.GetComponent<IInteractable>();
if(!dest.CanThisBeInteractedWith(pickup)) continue;
var path = new NavMeshPath();
agent.CalculatePath(dest.InteractPosition(_agent.transform.position), path);
if (path.status != NavMeshPathStatus.PathComplete) continue;
_intaractableGoal = dest;
break;
}
if(_intaractableGoal == null)
_state = State.Done;
}
开发者ID:veselin-,项目名称:Team4BabelGame,代码行数:33,代码来源:InteractWithNearestState.cs
示例3: DoCalculatePath
void DoCalculatePath()
{
_getNavMeshPathProxy();
if (_NavMeshPathProxy ==null)
{
return;
}
NavMeshPath _path = new NavMeshPath();
bool _found = NavMesh.CalculatePath(sourcePosition.Value,targetPosition.Value,passableMask.Value,_path);
_NavMeshPathProxy.path = _path;
resultingPathFound.Value = _found;
if (_found)
{
if ( ! FsmEvent.IsNullOrEmpty(resultingPathFoundEvent) ){
Fsm.Event(resultingPathFoundEvent);
}
}else
{
if (! FsmEvent.IsNullOrEmpty(resultingPathNotFoundEvent) ){
Fsm.Event(resultingPathNotFoundEvent);
}
}
}
开发者ID:KnightsWhoSaysNi,项目名称:feuerbeuch,代码行数:28,代码来源:NavMeshCalculatePath.cs
示例4: OnEnter
public override void OnEnter(ref AiParam _param)
{
if (_param == null || _param.NavAgent == null)
return;
_param.OnAiActionChanged (UnityChan_Ctrl.ActionState.Walk);
//_param.NavAgent.Resume ();
Movement (ref _param);
int searchMax = 30;
for (var i = 0; i < searchMax; i++)
{
Vector3 randomPoint = _param.Owner.transform.position + Random.insideUnitSphere * 3F;
NavMeshHit hit;
if (NavMesh.SamplePosition (randomPoint, out hit, 1F, 0xFF)) {
NavMeshPath path = new NavMeshPath();
if(_param.NavAgent.CalculatePath(hit.position, path) == true)
{
_param.NavAgent.SetPath(path);
return;
}
}
}
}
开发者ID:DeanLu,项目名称:SnowBall,代码行数:27,代码来源:AiStrategy_Patrol.cs
示例5: DrawPath
void DrawPath(NavMeshPath path) {
if (path.corners.Length < 2)
return;
switch (path.status) {
case NavMeshPathStatus.PathComplete:
c = Color.white;
break;
case NavMeshPathStatus.PathInvalid:
c = Color.red;
break;
case NavMeshPathStatus.PathPartial:
c = Color.yellow;
break;
}
Vector3 previousCorner = path.corners[0];
int i = 1;
while (i < path.corners.Length) {
Vector3 currentCorner = path.corners[i];
Debug.DrawLine(previousCorner, currentCorner, c);
previousCorner = currentCorner;
i++;
}
}
开发者ID:tchrisbaker,项目名称:Unity3DRPG,代码行数:28,代码来源:PathUtilsFSMAction.cs
示例6: Update
void Update()
{
/*if (oldpos != transform.position) {
oldpos = newpos;
newpos = transform.position;
} else {
anim.SetBool("isWalking", false);
}*/
if (Input.touchCount == 1)
{
Vector3 moveTo = GetPositionTouch();
//player.SetDestination(moveTo);
//anim.SetBool("isWalking", true);
NavMeshPath path = new NavMeshPath();
GetComponent<NavMeshAgent>().CalculatePath(moveTo, path);
//Debug.Log(path.status);
if (path.status == NavMeshPathStatus.PathComplete)
{
TouchIndicator(moveTo);
player.SetDestination(moveTo);
anim.SetBool("isWalking", true);
}
}
//Debug.Log (player.remainingDistance);
if (player.remainingDistance == 0) {
anim.SetBool("isWalking", false);
}
}
开发者ID:jsimoesjr,项目名称:Unity,代码行数:35,代码来源:PlayerControl.cs
示例7: Start
// Use this for initialization
void Start()
{
destination = transform.position;
path = new NavMeshPath();
CalcPath();
rigidBody = GetComponent<Rigidbody>();
}
开发者ID:SteveRodkiss,项目名称:PauseTimeStrategy,代码行数:8,代码来源:HoverTankFollowPath.cs
示例8: CalculatePathLength
float CalculatePathLength(Vector3 targetPosition)
{
//To calculate how far the sound can travel - identifies player behind corners
NavMeshPath path = new NavMeshPath();
if (nav.enabled)
nav.CalculatePath(targetPosition, path);
Vector3[] allWayPoints = new Vector3[path.corners.Length + 2]; //+2 to allow for the enemy and player positions
allWayPoints[0] = transform.position;
allWayPoints[allWayPoints.Length - 1] = targetPosition;
for (int i = 0; i < path.corners.Length; i++)
{
allWayPoints[i + 1] = path.corners[i];
}
float pathLength = 0f;
for (int i = 0; i < allWayPoints.Length-1; i++)
{
pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
}
return pathLength;
}
开发者ID:rnabeth,项目名称:stealth,代码行数:27,代码来源:EnemySight.cs
示例9: CalculatePathLength
// this is used for finding how long a sound has to travel
float CalculatePathLength(Vector3 targetPosition)
{
NavMeshPath path = new NavMeshPath();
if (nav.enabled)
nav.CalculatePath(targetPosition, path);
Vector3[] allWayPoints = new Vector3[path.corners.Length + 2];
//first point in array should be the enemy's posiotn
allWayPoints[0] = transform.position;
allWayPoints[allWayPoints.Length - 1] = targetPosition;
for (int i = 0; i < path.corners.Length; i ++) {
allWayPoints[i + 1] = path.corners[i];
}
float pathLength = 0;
for (int i = 0; i < allWayPoints.Length - 1; i++) {
pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
}
return pathLength;
}
开发者ID:daxaxelrod,项目名称:Loom-Vr,代码行数:27,代码来源:npcSight.cs
示例10: DrawLinesWithNavigation
//draw lines using navmesh
void DrawLinesWithNavigation()
{
if(useOwnNavSystem == false)
{
int testId2 = 0;
int testIdPlus2 = 1;
List<Vector3> waypointVector3 = new List<Vector3>();
while(testId2 < waypointList.Length)
{
if(testIdPlus2 >= waypointList.Length)
{
testIdPlus2 = 0;
}
NavMeshPath pathMain = new NavMeshPath();
NavMesh.CalculatePath(waypointList[testId2].transform.position, waypointList[testIdPlus2].transform.position, -1, pathMain);
int testId3 = 0;
while(testId3 < pathMain.corners.Length)
{
waypointVector3.Add(pathMain.corners[testId3]);
testId3 += 1;
}
testId2 += 1;
testIdPlus2 += 1;
}
//draw the lines
int testId = 0;
int testIdPlus = 1;
while(testId < waypointVector3.Count)
{
if(testIdPlus >= waypointVector3.Count)
{
testIdPlus = 0;
}
Gizmos.color = Color.magenta;
Gizmos.DrawLine(waypointVector3[testId], waypointVector3[testIdPlus]);
testId += 1;
testIdPlus += 1;
}
}
}
开发者ID:PlayHopeless,项目名称:game,代码行数:61,代码来源:PatrolManager.cs
示例11: FindNearest
//returns the nearest portal of a container, based on the position
static Vector3? FindNearest(Transform parent, Vector3 pos)
{
//initialize variables
NavMeshPath path = new NavMeshPath();
Vector3? nearest = null;
float distance = Mathf.Infinity;
//don't continue if the parent does not exist
if (!portals.ContainsKey(parent)) return null;
//loop over portals of this portal container,
//find the shortest NavMesh path to a portal
for (int i = 0; i < portals[parent].Count; i++)
{
Vector3 portal = portals[parent][i].position;
float length = Mathf.Infinity;
//let Unity calculate the path and set length, if valid
if (NavMesh.CalculatePath(pos, portal, -1, path)
&& path.status == NavMeshPathStatus.PathComplete)
length = PathLength(path);
if (length < distance)
{
distance = length;
nearest = portal;
}
}
return nearest;
}
开发者ID:kostya05,项目名称:TestingRacing,代码行数:31,代码来源:PortalManager.cs
示例12: Start
void Start()
{
anim = GetComponent<Animator>();
anim.SetBool("isWalking", true);
NavMeshPath path = new NavMeshPath();
agent.destination = target.position;
}
开发者ID:KickAss42,项目名称:Projet-SurvivAll,代码行数:7,代码来源:MobMouve.cs
示例13: Awake
public virtual void Awake()
{
nav = GetComponent<NavMeshAgent> ();
vision = GetComponent<Vision> ();
player = GameObject.FindGameObjectWithTag ("Player").transform;
path = new NavMeshPath ();
}
开发者ID:Time14,项目名称:Trapped,代码行数:7,代码来源:BaseAI.cs
示例14: findNextDestination
public void findNextDestination()
{
NavMeshPath path = new NavMeshPath();
int indexTargetChosen = -1;
bool found = false;
int count = 0;
if (getNumberOfTargetsOff() > 0)
{
while (!found && count < 99)
{
indexTargetChosen = Random.Range(0, targets.Length);
if (!targets[indexTargetChosen].isOn)
{
m_Agent.CalculatePath(targets[indexTargetChosen].transform.position, path);
if (path.status == NavMeshPathStatus.PathComplete)
{
found = true;
}
}
count++;
}
}
if (found)
{
Vector3 destination = targets[indexTargetChosen].transform.position;
m_Agent.destination = new Vector3(destination.x, transform.position.y, destination.z);
}
}
开发者ID:simonchauvin,项目名称:Ludum-Dare-33,代码行数:29,代码来源:Player.cs
示例15: Update
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitinfo;
// LayerMask mask = 1 << LayerMask.NameToLayer("GroundLayer");
bool isCollider = Physics.Raycast(ray, out hitinfo);
if (isCollider && hitinfo.collider.tag == Tags.player)
{
cur_Role = hitinfo.collider.transform.parent.GetComponent<DBaseFightRole>();
}
if (isCollider && hitinfo.collider.tag == Tags.ground && cur_Role != null)
{
NavMeshPath path = new NavMeshPath();
cur_Role.agent.enabled = true;
cur_Role.agent.CalculatePath(hitinfo.point, path);
if (path.corners.Length >= 2)
{
cur_Role.gotoDestination(hitinfo.point);
}
cur_Role = null;
}
}
}
开发者ID:satela,项目名称:xjhU3d,代码行数:29,代码来源:CastSkill.cs
示例16: CalculatePathLength
// Unity's example function..
public float CalculatePathLength(NavMeshAgent nav, Vector3 targetPosition)
{
// Added condition since it was returning impossible values if given same position :P
if (nav.transform.position == targetPosition)
return 0;
// Create a path and set it based on a target position.
var path = new NavMeshPath();
if (nav.enabled)
nav.CalculatePath(targetPosition, path);
// Create an array of points which is the length of the number of corners in the path + 2.
var allWayPoints = new Vector3[path.corners.Length + 2];
// The first point is the player position.
allWayPoints[0] = player.transform.position;
// The last point is the enemy position
allWayPoints[allWayPoints.Length - 1] = targetPosition;
// The points inbetween are the corners of the path.
for (var i = 0; i < path.corners.Length; i++)
allWayPoints[i + 1] = path.corners[i];
// Create a float to store the path length that is by default 0.
float pathLength = 0;
// Increment the path length by an amount equal to the distance between each waypoint and the next.
for (int i = 0; i < allWayPoints.Length - 1; i++)
{
pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
}
return pathLength;
}
开发者ID:Kullax,项目名称:competence,代码行数:36,代码来源:SavedValues.cs
示例17: CalculatePathLength
float CalculatePathLength(Vector3 targetPos)
{
NavMeshPath path = new NavMeshPath ();
if(nav.enabled)
{
nav.CalculatePath(targetPos, path);
}
Vector3 [] waypointsToTarget = new Vector3[path.corners.Length + 2]; //2 for orgin + target.
waypointsToTarget [0] = transform.position;
waypointsToTarget [waypointsToTarget.Length - 1] = targetPos;
for(int i= 0; i<path.corners.Length; i++)
{
waypointsToTarget[i+1] = path.corners[i];
}
float pathLength = 0;
for(int i = 0; i < waypointsToTarget.Length -1; i++)
{
pathLength += Vector3.Distance(waypointsToTarget[i],waypointsToTarget[i+1]);
}
return pathLength;
}
开发者ID:Allsaveone,项目名称:LevelUp,代码行数:28,代码来源:Senses.cs
示例18: CalculatePathLength
private float CalculatePathLength(Vector3 targetPosition)
{
NavMeshPath path = new NavMeshPath();
if (nav.enabled)
{
nav.CalculatePath(targetPosition, path);
}
Vector3[] allWayPoints = new Vector3[path.corners.Length + 2];
allWayPoints[0] = transform.position;
allWayPoints[allWayPoints.Length - 1] = targetPosition;
for (int i = 0; i < path.corners.Length; i++)
{
allWayPoints[i + 1] = path.corners[i];
}
float pathLength = 0f;
for (int i = 0; i < allWayPoints.Length - 1; i++)
{
pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
}
return pathLength;
}
开发者ID:HitomiFlower,项目名称:Stealth-VR,代码行数:27,代码来源:EnemySight.cs
示例19: Start
// Use this for initialization
void Start()
{
navAgent = transform.GetComponent<NavMeshAgent>();
characterController = transform.GetComponent<CharacterController>();
characterController.center = new Vector3(0, 1, 0);
path = new NavMeshPath();
GetComponent<Animator>().applyRootMotion = false;
}
开发者ID:lbddk,项目名称:ahzs-client,代码行数:9,代码来源:MogoMotorMonsterClient.cs
示例20: Start
void Start()
{
m_CalculatedPath = new NavMeshPath();
//enable finding for path/leader formation positions
StartCoroutine(CheckObjFound());
//enable making a path if the above coroutine finds an object to goto
StartCoroutine(NavGetPath());
}
开发者ID:Army2015,项目名称:PhysDrive-Unity,代码行数:8,代码来源:NavMeshGet.cs
注:本文中的UnityEngine.NavMeshPath类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论