NPctext
This commit is contained in:
parent
0fa701719b
commit
d98d907ca2
@ -9,6 +9,7 @@ using Google.Protobuf;
|
|||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static UnityEditor.Progress;
|
||||||
public class test : MonoBehaviour
|
public class test : MonoBehaviour
|
||||||
{
|
{
|
||||||
public string token;
|
public string token;
|
||||||
@ -550,16 +551,36 @@ public class test : MonoBehaviour
|
|||||||
Vector3 position = new Vector3(x, y, z);
|
Vector3 position = new Vector3(x, y, z);
|
||||||
|
|
||||||
NPCController.instance.InitNPC(position, npcData);
|
NPCController.instance.InitNPC(position, npcData);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (npcData.Type == 2)//npcÒÆ¶¯
|
if (npcData.Type == 2)//npcÒÆ¶¯
|
||||||
{
|
{
|
||||||
Vector3 v = new Vector3(float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()) + 0.5f, float.Parse(npcData.Z.ToString()));
|
Vector3 v = new Vector3(float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()) + 0.5f, float.Parse(npcData.Z.ToString()));
|
||||||
foreach (RecuseNpc item in NPCController.instance.npcsList)
|
//NPCController.instance.npcposition.Add(v);
|
||||||
|
//foreach (RecuseNpc item in NPCController.instance.npcsList)
|
||||||
|
//{
|
||||||
|
// if (npcData.UserId == item.npcId)
|
||||||
|
// {
|
||||||
|
// //Debug.Log("================" + v);
|
||||||
|
// item.SetNpcDes(v);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
foreach (var npcDict in NPCController.instance.npcsList)
|
||||||
{
|
{
|
||||||
if (npcData.UserId == item.npcId)
|
// 遍历每个字典中的键值对
|
||||||
|
foreach (var kvp in npcDict)
|
||||||
{
|
{
|
||||||
//Debug.Log("================" + v);
|
RecuseNpc npc = kvp.Key; // 获取 NPC 脚本(键)
|
||||||
item.SetNpcDes(v);
|
Vector3 position = kvp.Value; // 获取 NPC 的位置(值)
|
||||||
|
|
||||||
|
// 在这里,你可以使用 npc 和 position 进行其他操作
|
||||||
|
if (npcData.UserId == npc.npcId)
|
||||||
|
{
|
||||||
|
//Debug.Log("================" + v);
|
||||||
|
npc.SetNpcDes(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using Unity.VisualScripting;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
@ -8,10 +9,9 @@ public class NPCController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public static NPCController instance;
|
public static NPCController instance;
|
||||||
|
|
||||||
public List<RecuseNpc> npcsList = new List<RecuseNpc>();//存放每个生成的npc的脚本
|
public List<Dictionary<RecuseNpc,Vector3>> npcsList = new List<Dictionary<RecuseNpc, Vector3>>();//存放每个生成的npc的脚本
|
||||||
public GameObject npc;//npc人物预制体
|
public GameObject npc;//npc人物预制体
|
||||||
|
public List<Vector3> npcposition = new List<Vector3>();//存放每个生成的npc位置
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +29,13 @@ public class NPCController : MonoBehaviour
|
|||||||
RecuseNpc recuseNpc = go.GetComponent<RecuseNpc>();
|
RecuseNpc recuseNpc = go.GetComponent<RecuseNpc>();
|
||||||
recuseNpc.SetNPCInfo(npcData.UserId);//初始化npcid
|
recuseNpc.SetNPCInfo(npcData.UserId);//初始化npcid
|
||||||
Debug.Log(npcData.UserId);
|
Debug.Log(npcData.UserId);
|
||||||
npcsList.Add(recuseNpc);//将生成的NPC的脚本加入list存放
|
Dictionary<RecuseNpc, Vector3> npcDict = new Dictionary<RecuseNpc, Vector3>
|
||||||
|
{
|
||||||
|
{ recuseNpc, v } // 将 recuseNpc 和其位置 v 作为键值对添加到字典中
|
||||||
|
};
|
||||||
|
|
||||||
|
// 将字典添加到 npcsList
|
||||||
|
npcsList.Add(npcDict);//将生成的NPC的脚本加入list存放
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user