Npc移动逻辑
This commit is contained in:
parent
7217b04390
commit
0fc572148d
@ -79,6 +79,13 @@ public class TaskItem : MonoBehaviour
|
|||||||
triggers.Add(triggerType);
|
triggers.Add(triggerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 任务完成时调用的函数
|
||||||
|
public void OnTaskCompleted()
|
||||||
|
{
|
||||||
|
TaskPanel.instance.RemoveTask(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ using UnityEditor;
|
|||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
public class EncryptionDongleClient : MonoBehaviour
|
public class EncryptionDongleClient : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static string licenseID = "Ïû·Àid";
|
public static string licenseID = "xiaofangid";
|
||||||
private static string serverURL = "http://shu.sheziwanglo.cn:5001/validate";
|
private static string serverURL = "http://shu.sheziwanglo.cn:5001/validate";
|
||||||
|
|
||||||
static EncryptionDongleClient()
|
static EncryptionDongleClient()
|
||||||
|
@ -12,7 +12,7 @@ public class TaskPanel : Base
|
|||||||
|
|
||||||
public static TaskPanel instance;
|
public static TaskPanel instance;
|
||||||
|
|
||||||
public List<int> taskId = new List<int>();
|
public List<int> taskIds = new List<int>();
|
||||||
|
|
||||||
public Transform contentTrans;
|
public Transform contentTrans;
|
||||||
|
|
||||||
@ -73,12 +73,12 @@ public class TaskPanel : Base
|
|||||||
public async void InitTask()
|
public async void InitTask()
|
||||||
{
|
{
|
||||||
await DestroyTaskAsync();
|
await DestroyTaskAsync();
|
||||||
for(int i = 0; i < taskId.Count;i++)
|
for(int i = 0; i < taskIds.Count;i++)
|
||||||
{
|
{
|
||||||
GameObject go = GameObject.Instantiate(taskPrefab, contentTrans);
|
GameObject go = GameObject.Instantiate(taskPrefab, contentTrans);
|
||||||
go.transform.name = "Task_" + i;
|
go.transform.name = "Task_" + i;
|
||||||
TaskItem item = go.GetComponent<TaskItem>();
|
TaskItem item = go.GetComponent<TaskItem>();
|
||||||
item.SetInfo(taskId[i], JSONReader);
|
item.SetInfo(taskIds[i], JSONReader);
|
||||||
Button button = go.GetComponent<Button>();
|
Button button = go.GetComponent<Button>();
|
||||||
button.onClick.AddListener(() => OnButtonClicked(button));
|
button.onClick.AddListener(() => OnButtonClicked(button));
|
||||||
buttons.Add(button);
|
buttons.Add(button);
|
||||||
@ -113,7 +113,7 @@ public class TaskPanel : Base
|
|||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//这里是在加入新任务时需要更新显示前的删除
|
||||||
public void DeleteAllChildObjects()
|
public void DeleteAllChildObjects()
|
||||||
{
|
{
|
||||||
// ±éÀúËùÓÐ×ÓÎïÌ岢ɾ³ý
|
// ±éÀúËùÓÐ×ÓÎïÌ岢ɾ³ý
|
||||||
@ -129,12 +129,24 @@ public class TaskPanel : Base
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
taskId.Add(id);
|
taskIds.Add(id);
|
||||||
InitTask();
|
InitTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void RemoveTask(int taskId)
|
||||||
|
{
|
||||||
|
// 通过 taskId 找到对应的任务按钮并移除
|
||||||
|
Button taskButton = buttons.Find(button => button.name == "Task_" + taskId);
|
||||||
|
if (taskButton != null)
|
||||||
|
{
|
||||||
|
buttons.Remove(taskButton);
|
||||||
|
Destroy(taskButton.gameObject); // 删除该任务按钮
|
||||||
|
|
||||||
|
// 如果任务完成后有其他特定处理,比如从任务 ID 列表中移除任务,也可以在这里做
|
||||||
|
taskIds.Remove(taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +24,12 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
|
|
||||||
private bool movebool = false;
|
private bool movebool = false;
|
||||||
public Transform target;
|
public Transform target;
|
||||||
|
|
||||||
|
public Vector3 currentTarget;
|
||||||
|
|
||||||
|
// 存储目标点的List
|
||||||
|
public List<Vector3> targetPoints = new List<Vector3>();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -45,6 +51,7 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
recusebtn.gameObject.SetActive(false);
|
recusebtn.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置NPC的状态
|
||||||
public void Setnpcstate()//点击救援按钮执行完动作后对按钮进行隐藏
|
public void Setnpcstate()//点击救援按钮执行完动作后对按钮进行隐藏
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -54,29 +61,49 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
Debug.Log("Setnpcstate调用");
|
Debug.Log("Setnpcstate调用");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置NPC的目标点
|
||||||
public void SetNpcDes(Vector3 tar)
|
public void SetNpcDes(Vector3 tar)
|
||||||
{
|
{
|
||||||
target.position = tar;
|
//target.position = tar;
|
||||||
|
targetPoints.Add(tar); // 将目标点添加到列表中
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Vector3.Distance(transform.position,target.position) < 1.3f && movebool && target.transform.position != null)//判断人物被救援后移动到目标位置
|
if (targetPoints.Count > 0) // 确保列表中有目标点
|
||||||
|
{
|
||||||
|
currentTarget = targetPoints[0]; // 获取当前的目标点
|
||||||
|
|
||||||
|
if (Vector3.Distance(transform.position, currentTarget) < 1.3f && movebool && currentTarget != null) // 判断人物被救援后移动到目标位置
|
||||||
{
|
{
|
||||||
Debug.Log("到达目标点");
|
Debug.Log("到达目标点");
|
||||||
nstate = Npcstate.idle;
|
|
||||||
movebool = false;
|
// 达到目标后,从列表中移除该目标点
|
||||||
|
if(targetPoints.Count > 1)
|
||||||
|
{
|
||||||
|
targetPoints = RemoveDes();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetPoints = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (nstate)//通过枚举状态实现人物是否被救援,以及动作的改变
|
// 设置NPC状态
|
||||||
|
nstate = Npcstate.idle;
|
||||||
|
movebool = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 继续处理NPC的状态和动画
|
||||||
|
switch (nstate)
|
||||||
{
|
{
|
||||||
case Npcstate.idle:
|
case Npcstate.idle:
|
||||||
SetAni(2);
|
SetAni(2);
|
||||||
break;
|
break;
|
||||||
case Npcstate.run:
|
case Npcstate.run:
|
||||||
movebool = true;
|
movebool = true;
|
||||||
Run();
|
Run(currentTarget);
|
||||||
break;
|
break;
|
||||||
case Npcstate.dead:
|
case Npcstate.dead:
|
||||||
SetAni(0);
|
SetAni(0);
|
||||||
@ -84,14 +111,28 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//删除目标点
|
||||||
|
public List<Vector3> RemoveDes()
|
||||||
|
{
|
||||||
|
List<Vector3> list = new List<Vector3>();
|
||||||
|
|
||||||
|
for(int i= 1;i<targetPoints.Count;i++)
|
||||||
|
{
|
||||||
|
list[i-1] = targetPoints[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//跑步逻辑
|
//跑步逻辑
|
||||||
public void Run()
|
public void Run(Vector3 target)
|
||||||
{
|
{
|
||||||
if (movebool)
|
if (movebool)
|
||||||
{
|
{
|
||||||
SetAni(1);
|
SetAni(1);
|
||||||
transform.LookAt(target);
|
transform.LookAt(target);
|
||||||
transform.position = Vector3.Lerp(transform.position, target.position, 0.3f * Time.deltaTime);
|
transform.position = Vector3.Lerp(transform.position, target, 0.3f * Time.deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user