61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
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()
|
||
{
|
||
|
||
}
|
||
}
|