添加了NPC的管理类NPCController
This commit is contained in:
parent
8216fd8b4b
commit
d9af993db4
@ -13,8 +13,6 @@ public class test : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public string token;
|
public string token;
|
||||||
public WEBScriptListener wEBScriptListener;
|
public WEBScriptListener wEBScriptListener;
|
||||||
public GameObject npc;
|
|
||||||
public Transform trans;
|
|
||||||
|
|
||||||
public class auth_login
|
public class auth_login
|
||||||
{
|
{
|
||||||
@ -515,16 +513,20 @@ public class test : MonoBehaviour
|
|||||||
float z = float.Parse(npcData.Z.ToString());
|
float z = float.Parse(npcData.Z.ToString());
|
||||||
Vector3 position = new Vector3(x, y, z);
|
Vector3 position = new Vector3(x, y, z);
|
||||||
|
|
||||||
// 使用指定的世界坐标位置来实例化 NPC,而不是依赖 trans 位置
|
NPCController.instance.InitNPC(position, npcData);
|
||||||
GameObject.Instantiate(npc, position, Quaternion.identity); // 直接指定位置和旋转
|
|
||||||
// Npc生成后调用选择路线,=================这里也会删掉,在等UI逻辑那边处理完
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(npcData.Type == 2)//npcÒƶ¯
|
if(npcData.Type == 2)//npcÒƶ¯
|
||||||
{
|
{
|
||||||
Vector3 v = new Vector3(-float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()), float.Parse(npcData.Z.ToString()));
|
Vector3 v = new Vector3(-float.Parse(npcData.X.ToString()), float.Parse(npcData.Y.ToString()), float.Parse(npcData.Z.ToString()));
|
||||||
RecuseNpc.instance.SetNpcDes(v);
|
foreach(var item in NPCController.instance.npcsList)
|
||||||
|
{
|
||||||
|
if(npcData.UserId == item.npcId)
|
||||||
|
{
|
||||||
|
item.SetNpcDes(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//npc.transform.name = npcData.UserId;
|
//npc.transform.name = npcData.UserId;
|
||||||
|
41
xiaofang/Assets/Script/hylScripts/NPCController.cs
Normal file
41
xiaofang/Assets/Script/hylScripts/NPCController.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
public class NPCController : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static NPCController instance;
|
||||||
|
|
||||||
|
public List<RecuseNpc> npcsList = new List<RecuseNpc>();//存放每个生成的npc的脚本
|
||||||
|
public GameObject npc;//npc人物预制体
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InitNPC(Vector3 v,NpcData npcData)
|
||||||
|
{
|
||||||
|
// 使用指定的世界坐标位置来实例化 NPC,而不是依赖 trans 位置
|
||||||
|
GameObject go = GameObject.Instantiate(npc, v, Quaternion.identity); // 直接指定位置和旋转
|
||||||
|
RecuseNpc recuseNpc = go.GetComponent<RecuseNpc>();
|
||||||
|
recuseNpc.SetNPCInfo(npcData.UserId);//初始化npcid
|
||||||
|
npcsList.Add(recuseNpc);//将生成的NPC的脚本加入list存放
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
xiaofang/Assets/Script/hylScripts/NPCController.cs.meta
Normal file
11
xiaofang/Assets/Script/hylScripts/NPCController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1a829b8d12d88e14487451b9c601ab85
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -12,6 +12,8 @@ public enum Npcstate
|
|||||||
|
|
||||||
public class RecuseNpc : MonoBehaviour
|
public class RecuseNpc : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public string npcId;
|
||||||
|
|
||||||
public static RecuseNpc instance;
|
public static RecuseNpc instance;
|
||||||
|
|
||||||
private Button recusebtn;
|
private Button recusebtn;
|
||||||
@ -51,6 +53,11 @@ public class RecuseNpc : MonoBehaviour
|
|||||||
recusebtn.gameObject.SetActive(false);
|
recusebtn.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetNPCInfo(string id)
|
||||||
|
{
|
||||||
|
npcId = id;
|
||||||
|
}
|
||||||
|
|
||||||
//设置NPC的状态
|
//设置NPC的状态
|
||||||
public void Setnpcstate()//点击救援按钮执行完动作后对按钮进行隐藏
|
public void Setnpcstate()//点击救援按钮执行完动作后对按钮进行隐藏
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user