private void CheckOffmeshLink() { //IF ON OFF-MeshLink if (navMeshAgent != null && navMeshAgent.isOnOffMeshLink && navMeshAgent.updatePosition) { matchTargetEndPos = navMeshAgent.currentOffMeshLinkData.endPos; matchTargetStartPos = navMeshAgent.currentOffMeshLinkData.startPos; matchTargetRot = Quaternion.LookRotation( (matchTargetEndPos + Vector3.up * (matchTargetStartPos.y - matchTargetEndPos.y)) - matchTargetStartPos ); var link = navMeshAgent.navMeshOwner as NavMeshLink; if (link && !animator.GetCurrentAnimatorStateInfo(0).IsTag("OffMesh")) { var linkCast = (NavMeshLink_TBS)link; string offMeshLinkAnimName = linkCast.GetAnimName(transform.position); navMeshAgent.ActivateCurrentOffMeshLink(false); navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; transform.rotation = matchTargetRot; animator.Play(offMeshLinkAnimName); } //locomotion.Do ( 0, 0 ); } }
void CloseDiscoverd() { if (_agent.isOnOffMeshLink) { _agent.ActivateCurrentOffMeshLink(false); } }
//梯子 IEnumerator Locomotion_Ladder() { //梯子的中心位置 Vector3 linkCenter = (linkStart + linkEnd) * 0.5f; string linkAnim; //判断是在梯子上还是梯子下 if (transform.position.y > linkCenter.y) { linkAnim = "Ladder Down"; } else { linkAnim = "Ladder Up"; } agent.Stop(true); Quaternion startRot = transform.rotation; Vector3 startPos = transform.position; float blendTime = 0.2f; float tblend = 0f; //角色的位置插值变化(0.2内变化) do { transform.position = Vector3.Lerp(startPos, linkStart, tblend / blendTime); transform.rotation = Quaternion.Lerp(startRot, linkRotate, tblend / blendTime); yield return(new WaitForSeconds(0)); tblend += Time.deltaTime; } while(tblend < blendTime); //设置位置 transform.position = linkStart; //播放动画 anim.CrossFade(linkAnim, 0.1f, PlayMode.StopAll); agent.ActivateCurrentOffMeshLink(false); //等待动画结束 do { yield return(new WaitForSeconds(0)); } while(anim[linkAnim].normalizedTime < 1); agent.ActivateCurrentOffMeshLink(true); //恢复Idle状态 anim.Play("Idle"); transform.position = linkEnd; agent.CompleteOffMeshLink(); agent.Resume(); //下一个状态Stand locoState = "Locomotion_Stand"; yield return(null); }
static int ActivateCurrentOffMeshLink(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); NavMeshAgent obj = LuaScriptMgr.GetNetObject <NavMeshAgent>(L, 1); bool arg0 = LuaScriptMgr.GetBoolean(L, 2); obj.ActivateCurrentOffMeshLink(arg0); return(0); }
void DoActivateCurrentOffMeshLink() { if (activate == null || _agent == null) { return; } _agent.ActivateCurrentOffMeshLink(activate.Value); }
static int ActivateCurrentOffMeshLink(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); NavMeshAgent obj = (NavMeshAgent)LuaScriptMgr.GetUnityObjectSelf(L, 1, "NavMeshAgent"); bool arg0 = LuaScriptMgr.GetBoolean(L, 2); obj.ActivateCurrentOffMeshLink(arg0); return(0); }
/// <summary> /// The character has respawned. Start moving again. /// </summary> private void OnRespawn() { // Reset the NavMeshAgent to the new position. m_NavMeshAgent.Warp(m_Transform.position); if (m_NavMeshAgent.isOnOffMeshLink) { m_NavMeshAgent.ActivateCurrentOffMeshLink(false); } m_NavMeshAgent.updateRotation = m_UpdateRotation; }
private void Start() { _agent = GetComponent <NavMeshAgent>(); _agent.enabled = true; _agent.ActivateCurrentOffMeshLink(true); if (_agent.isActiveAndEnabled) { print("------------"); } //transform.localScale(new Vector3(1,1,2)); }
/// <summary> /// The character has respawned. Start moving again. /// </summary> private void OnRespawn() { // Reset the NavMeshAgent to the new position. m_NavMeshAgent.Warp(m_Transform.position); if (m_NavMeshAgent.isOnOffMeshLink) { m_NavMeshAgent.ActivateCurrentOffMeshLink(false); } m_NavMeshAgent.updateRotation = m_UpdateRotation; m_LastPathPendingFrame = int.MinValue; }
private void Update() { if (mAgent.isOnOffMeshLink) { mAgent.ActivateCurrentOffMeshLink(true); //mAgent.CompleteOffMeshLink(); //transform.position = Vector3.MoveTowards(transform.position, mAgent.currentOffMeshLinkData.endPos, Time.deltaTime); //if (Vector3.Distance(transform.position, mAgent.currentOffMeshLinkData.endPos) < 0.01f) //{ // mAgent.CompleteOffMeshLink(); //} } }
/// <summary> /// The character has respawned. Start moving again. /// </summary> private void OnRespawn() { // Reset the NavMeshAgent to the new position. m_NavMeshAgent.Warp(transform.position); if (m_NavMeshAgent.isOnOffMeshLink) { m_NavMeshAgent.ActivateCurrentOffMeshLink(false); } m_NavMeshAgent.updateRotation = true; enabled = true; EventHandler.RegisterEvent(m_GameObject, "OnDeath", OnDeath); EventHandler.UnregisterEvent(m_GameObject, "OnRespawn", OnRespawn); }
private void Start() { _agent.ActivateCurrentOffMeshLink(true); }