101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class NPCController : PermanentTriggerBase
|
|
{
|
|
public List<string> npcSpeack;
|
|
public int speackIndex = 0;
|
|
public SpriteRenderer spriteRenderer;
|
|
public Animator animator;
|
|
public string animatorParameters;
|
|
public Transform target;
|
|
private float distance;
|
|
public float minDistance;
|
|
/// <summary>
|
|
/// 是否靠近
|
|
/// </summary>
|
|
private bool isClose = false;
|
|
|
|
private void Update()
|
|
{
|
|
if (target != null)
|
|
distance = Vector3.Distance(transform.position, target.position);
|
|
if (distance < minDistance)
|
|
{
|
|
transform.LookAt(target.position);
|
|
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
|
|
isClose = true;
|
|
}
|
|
else
|
|
{
|
|
isClose = false;
|
|
}
|
|
}
|
|
protected override void OnMEnter()
|
|
{
|
|
base.OnMEnter();
|
|
if (!isClose) return;
|
|
if (GameManager.RunModelMgr.ModeType != E_ModeType.Study)
|
|
{
|
|
_highlight.SetHighlighted(true);
|
|
}
|
|
}
|
|
protected override void OnMExit()
|
|
{
|
|
if (GameManager.RunModelMgr.ModeType != E_ModeType.Study)
|
|
_highlight.SetHighlighted(false);
|
|
base.OnMExit();
|
|
}
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
if (!isClose)
|
|
{
|
|
GameManager.UIMgr.ShowPanel<UI_MiddleTipPanel>(E_UI_Layer.System, (p) =>
|
|
{
|
|
p.Init($"提示:请靠近交互对象");
|
|
});
|
|
return;
|
|
}
|
|
if (GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, false) == 0)
|
|
{
|
|
GameManager.UIMgr.ShowPanel<UI_CustomSessionPanel>(E_UI_Layer.Mid, (panel) =>
|
|
{
|
|
panel.Init(triggerName, npcSpeack[speackIndex], NextSpeack);
|
|
});
|
|
_highlight.SetHighlighted(false);
|
|
spriteRenderer.gameObject.SetActive(false);
|
|
if (animator != null)
|
|
{
|
|
animator.SetInteger(animatorParameters, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NextSpeack(string id)
|
|
{
|
|
speackIndex++;
|
|
if (speackIndex <= npcSpeack.Count - 1)
|
|
{
|
|
if (GameManager.UIMgr.GetPanel<UI_CustomSessionPanel>())
|
|
{
|
|
GameManager.UIMgr.GetPanel<UI_CustomSessionPanel>().Init("", npcSpeack[speackIndex], NextSpeack);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, true);
|
|
if (animator != null)
|
|
{
|
|
animator.SetInteger(animatorParameters, 0);
|
|
}
|
|
//谈话回调
|
|
ScoreManager.instance.Check(triggerName, null);
|
|
if (GameManager.UIMgr.GetPanel<UI_CustomSessionPanel>())
|
|
GameManager.UIMgr.HidePanel<UI_CustomSessionPanel>();
|
|
speackIndex = 0;
|
|
}
|
|
}
|
|
}
|