挂机相机跟随;宠物寻路适配

This commit is contained in:
fatiao 2025-05-23 09:35:25 +08:00
parent b25984f40b
commit 58ea4efd8b
4 changed files with 48 additions and 14 deletions

View File

@ -1,10 +1,12 @@
using UnityEngine;
using System;
using UnityEngine;
using System.Collections;
public class LookAtTarget : MonoBehaviour
{
public Transform target;
public Vector3 offset = Vector3.zero;
private Func<Vector3> _getTargetPos = null;
// Use this for initialization
void Start()
@ -18,16 +20,33 @@ public class LookAtTarget : MonoBehaviour
this.offset = offset;
}
public void SetTargetPos(Func<Vector3> getTargetPos, Vector3 offset)
{
_getTargetPos = getTargetPos;
//this.offset = offset;
}
// Update is called once per frame
void LateUpdate()
{
if (target == null) return;
this.transform.rotation = GetLookRotation();
if (target == null && _getTargetPos == null) return;
transform.rotation = GetLookRotation();
}
Quaternion GetLookRotation()
{
Vector3 lookDir = (target.position + this.offset) - transform.position;
return Quaternion.LookRotation(lookDir, Vector3.up);
if (target != null)
{
Vector3 lookDir = (target.position + this.offset) - transform.position;
return Quaternion.LookRotation(lookDir, Vector3.up);
}
if (_getTargetPos != null)
{
Vector3 lookDir = (_getTargetPos() + this.offset) - transform.position;
return Quaternion.LookRotation(lookDir, Vector3.up);
}
return transform.rotation;
}
}

View File

@ -485,7 +485,6 @@ public class BattleCamera : Singleton<BattleCamera>
mRealCam.allowMSAA = false;
mRealCam.farClipPlane = camera_far_clip;
InitComponents ();
initialized = true;
@ -932,7 +931,7 @@ public class BattleCamera : Singleton<BattleCamera>
}
private Vector3 _Explore_SyncCameraPos_Offset = new Vector3(0, 8.0f, -12.0f);
private Vector3 _AFK_SyncCameraPos_Offset = new Vector3(2, 8.0f, -10.0f);
private Vector3 _AFK_SyncCameraPos_Offset = new Vector3(0, 8.0f, -12.0f);
public void SetExploreCameraTarget(Fighter fighter)
{
if (_SyncCameraPos == null || _LookAtTarget == null)
@ -961,13 +960,13 @@ public class BattleCamera : Singleton<BattleCamera>
}
if (fighter != null)
{
_SyncCameraPos.SetFollowTarget(fighter.Ctrl.transform, _AFK_SyncCameraPos_Offset);
_LookAtTarget.SetTarget(fighter.Ctrl.transform, mBattle.TeamCenter - fighter.Ctrl.transform.position);
_SyncCameraPos.SetFollowTargetPos(() => { return mBattle.TeamCenter; }, _AFK_SyncCameraPos_Offset);
_LookAtTarget.SetTargetPos(() => { return mBattle.TeamCenter; }, Vector3.zero);
}
else
{
_SyncCameraPos.SetFollowTarget(null, _AFK_SyncCameraPos_Offset);
_LookAtTarget.SetTarget(null, Vector3.zero);
_SyncCameraPos.SetFollowTargetPos(null, _AFK_SyncCameraPos_Offset);
_LookAtTarget.SetTargetPos(null, Vector3.zero);
}
}

View File

@ -2810,7 +2810,7 @@ public class Fighter : LogicTransform
pet.Ctrl.EnableNavAgent(enableNavAgent);
}
pet.AutoMoveTo(petPos);
pet.AutoMoveTo(petPos, false, BattleMgr.Instance.IsNoramlMapMode == true);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -6,7 +7,8 @@ public class SyncCameraPos : MonoBehaviour
{
public Transform actorTrans;
public Vector3 offsetPos;
private float speed = 5f;
private float speed = 2.5f;
private Func<Vector3> _getBattleCenterFunc = null;
public void SetFollowTarget(Transform actorTrans, Vector3 offsetPos)
{
@ -14,6 +16,12 @@ public class SyncCameraPos : MonoBehaviour
this.offsetPos = offsetPos;
transform.position = this.actorTrans.position + this.offsetPos;
}
public void SetFollowTargetPos(Func<Vector3> getBattleCenterFunc, Vector3 offsetPos)
{
this._getBattleCenterFunc = getBattleCenterFunc;
//this.offsetPos = offsetPos;
}
void Update()
{
@ -23,5 +31,13 @@ public class SyncCameraPos : MonoBehaviour
transform.position = targetPosition;
//this.transform.position = Vector3.Lerp(transform.position, targetPosition,speed * Time.deltaTime);
}
if (_getBattleCenterFunc != null)
{
var centerPoint = this._getBattleCenterFunc();
var targetPosition = centerPoint + this.offsetPos;
//transform.position = targetPosition;
this.transform.position = Vector3.Lerp(transform.position, targetPosition,speed * Time.deltaTime);
}
}
}