This commit is contained in:
lq 2024-12-10 23:24:15 +08:00
parent 94eb75df55
commit 0b05e7d0ef
2 changed files with 31 additions and 5 deletions

View File

@ -334,6 +334,8 @@ public class EvacuationPanel : MonoBehaviour
levelBtn.onClick.AddListener(() => levelBtn.onClick.AddListener(() =>
{ {
jueseChoicePanel.gameObject .SetActive(true); jueseChoicePanel.gameObject .SetActive(true);
JueseChoicePop jueseChoicePop= jueseChoicePanel.gameObject.GetComponent<JueseChoicePop>();
jueseChoicePop.SetClass(personnelItem.sceneId);
}); });
ClassItem classItem = levelItem.GetComponent<ClassItem>(); ClassItem classItem = levelItem.GetComponent<ClassItem>();
classItem.classname.text = locationData.Level.ToString(); classItem.classname.text = locationData.Level.ToString();

View File

@ -17,6 +17,7 @@ public class JueseChoicePop : MonoBehaviour
public List<ClassMate> classMateList = new List<ClassMate> (); public List<ClassMate> classMateList = new List<ClassMate> ();
public string s; public string s;
public JSONReader jsonReader;
//Start is called before the first frame update //Start is called before the first frame update
void Start() void Start()
{ {
@ -47,17 +48,40 @@ public class JueseChoicePop : MonoBehaviour
} }
public void SetClass(int id) public void SetClass(int id)
{ {
// 获取指定 ID 的 LocationData
LocationData locationData = jsonReader.GetAreaDateById(id);
for (int i = 0; i < 10; i++) // 判断 Oversee 字段
if (locationData.Oversee == "-1")
{ {
GameObject item = GameObject.Instantiate<GameObject>(classmatePrefab, content); Debug.Log($"Skipping ID {id}: Oversee is -1.");
return; // 跳过
}
ClassMate classMate = item.GetComponent<ClassMate>(); // 分割 Oversee 字段
classMateList.Add(classMate); string[] overseeParts = locationData.Oversee.Split(',');
//classMate.SetJc(this); foreach (string part in overseeParts)
{
// 检查每个部分的最后一位是否为 "1"
string[] elements = part.Split('|');
if (elements.Length > 1)
{
string lastElement = elements[elements.Length - 1];
if (lastElement == "1") // 如果最后一部分是 "1",实例化对象
{
GameObject item = GameObject.Instantiate(classmatePrefab, content);
ClassMate classMate = item.GetComponent<ClassMate>();
// 设置 ClassMate 的名称或其他字段
classMate.classmatename.text = locationData.Note;
Debug.Log($"Instantiated ClassMate for ID {id} with name {locationData.Name}");
}
}
} }
} }
public void SetClassItem(ClassItem classItem) public void SetClassItem(ClassItem classItem)
{ {
this.classItem = classItem; this.classItem = classItem;