104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
using UnityEngine;
|
|
using EasyInject.Attributes;
|
|
using UnityEngine.AI;
|
|
|
|
|
|
[GameObjectBean(ENameType.GameObjectName)]
|
|
[AddComponentMenu("WXDC/Container/Container")]
|
|
public class Container : MonoBehaviour, IMouseClick, IFollowHelp
|
|
{
|
|
[SerializeField]
|
|
private ContainerEntity _containerData;
|
|
[Autowired]
|
|
private CameraManage cameraManage;
|
|
private NavMeshAgent _agent;
|
|
[SerializeField]
|
|
public GameObject target;
|
|
[SerializeField]
|
|
public bool debugMode;
|
|
|
|
public bool isAwke;
|
|
|
|
[SerializeField]
|
|
private Vector3 _offset = new Vector3(0,0,-3);
|
|
[SerializeField]
|
|
private Transform _follow;
|
|
[SerializeField]
|
|
private Transform _lookAt;
|
|
[Autowired]
|
|
private ContainerPopUI containerPop;
|
|
private bool isOpenPop;
|
|
|
|
/// <summary>
|
|
/// NavMeshAgent 代理
|
|
/// </summary>
|
|
public NavMeshAgent Agent { get => _agent; set => _agent = value; }
|
|
|
|
private void Start()
|
|
{
|
|
_agent = GetComponent<NavMeshAgent>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 容器信息
|
|
/// </summary>
|
|
public ContainerEntity ContainerData { get => _containerData; set => _containerData = value; }
|
|
|
|
public Transform Follow => _follow ? _follow : transform;
|
|
|
|
public Transform FookAt => _lookAt ? _lookAt : transform;
|
|
|
|
public Vector3 Offset => _offset;
|
|
private void FixedUpdate()
|
|
{
|
|
if (debugMode)
|
|
{
|
|
if (!CheckAgentPosition(target.transform.position))
|
|
{
|
|
Agent.SetDestination(target.transform.position);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 如果代理终点已经是该位置了返回true
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool CheckAgentPosition(Vector3 target)
|
|
{
|
|
// Debug.LogWarning(string.Format("容器= 【{0}】 距离【{1}】 ", name, Vector3.Distance(transform.position, new Vector3(target.x, transform.position.y, target.z))));
|
|
return Vector3.Distance(transform.position, new Vector3(target.x, transform.position.y, target.z)) < 0.01f;
|
|
}
|
|
public void ToTarget(Vector3 target)
|
|
{
|
|
if(debugMode)
|
|
{
|
|
return;
|
|
}
|
|
if (!isAwke)
|
|
{
|
|
//唤醒
|
|
Agent.Warp(target);
|
|
Agent.enabled = true;
|
|
isAwke = true;
|
|
}
|
|
Agent.SetDestination(target);
|
|
}
|
|
|
|
public virtual void MouseSingleClick()
|
|
{
|
|
if (Follow && FookAt)
|
|
{
|
|
cameraManage.ShotCut(this);
|
|
}
|
|
isOpenPop = !isOpenPop;
|
|
containerPop.Open(_containerData,Follow,isOpenPop);
|
|
|
|
}
|
|
public virtual void MouseDoubleClick()
|
|
{
|
|
|
|
}
|
|
}
|