_xiaofang/xiaofang/Assets/Script/hylScripts/NPCController.cs
2024-12-29 17:50:20 +08:00

61 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;
public class NPCController : MonoBehaviour
{
public static NPCController instance;
public List<Dictionary<RecuseNpc,Vector3>> npcsList = new List<Dictionary<RecuseNpc, Vector3>>();//存放每个生成的npc的脚本
public GameObject npc;//npc人物预制体
public List<Vector3> npcposition = new List<Vector3>();//存放每个生成的npc位置
// Start is called before the first frame update
void Start()
{
instance = this;
}
public void INITNPCMOVE(Vector3 pos)
{
Debug.Log("11111111");
foreach (var npcDict in npcsList)
{
foreach (var kvp in npcDict)
{
RecuseNpc npc = kvp.Key;
npc.SetNpcDes(pos);
}
}
}
public void InitNPC(Vector3 v,NpcData npcData)
{
// 使用指定的世界坐标位置来实例化 NPC而不是依赖 trans 位置
GameObject go = GameObject.Instantiate(npc, v, Quaternion.identity); // 直接指定位置和旋转c
RecuseNpc recuseNpc = go.GetComponent<RecuseNpc>();
recuseNpc.SetNPCInfo(npcData.UserId);//初始化npcid
Debug.Log(npcData.UserId);
Dictionary<RecuseNpc, Vector3> npcDict = new Dictionary<RecuseNpc, Vector3>
{
{ recuseNpc, v } // 将 recuseNpc 和其位置 v 作为键值对添加到字典中
};
// 将字典添加到 npcsList
npcsList.Add(npcDict);//将生成的NPC的脚本加入list存放
}
// Update is called once per frame
void Update()
{
}
}