101 lines
2.8 KiB
C#
101 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class JueseChoicePop : MonoBehaviour
|
|
{
|
|
public ClassMate classMate;
|
|
public ClassItem classItem;
|
|
|
|
public Button CloseBtn;
|
|
public Button Surebtn;
|
|
public GameObject classmatePrefab;
|
|
public Transform content;
|
|
|
|
public List<ClassMate> classMateList = new List<ClassMate> ();
|
|
|
|
public string s;
|
|
public JSONReader jsonReader;
|
|
//Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
CloseBtn.onClick.AddListener(CLosePop);
|
|
Surebtn.onClick.AddListener(CLosePop);
|
|
Surebtn.onClick.AddListener(SetFenguan);
|
|
//SetClass();
|
|
}
|
|
void CLosePop()
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
public void openPop()
|
|
{
|
|
this.gameObject.SetActive(true);
|
|
}
|
|
void SetFenguan()
|
|
{
|
|
//设置此区分的分管人员为用户选中的角色,并刷新界面信息
|
|
classItem.isSet = true;
|
|
//classItem.setClassItem();
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
public void SetClass(int id)
|
|
{
|
|
// 获取指定 ID 的 LocationData
|
|
LocationData locationData = jsonReader.GetAreaDateById(id);
|
|
|
|
// 判断 Oversee 字段
|
|
if (locationData.Oversee == "-1")
|
|
{
|
|
Debug.Log($"Skipping ID {id}: Oversee is -1.");
|
|
return; // 跳过
|
|
}
|
|
|
|
// 分割 Oversee 字段
|
|
string[] overseeParts = locationData.Oversee.Split(',');
|
|
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)
|
|
{
|
|
this.classItem = classItem;
|
|
}
|
|
|
|
|
|
public void SetClassMate(ClassMate classMate, string a = "")
|
|
{
|
|
classMate.isBeSet = true;
|
|
classItem.isSet = true;
|
|
this.classMate = classMate;
|
|
//classItem.setClassItem(classMate.classmatename.text);
|
|
//s = classMate.classmatename.text;
|
|
this.classMate.classmatename.text = classMate.classmatename.text + "(" + classItem.classname.text + ")";
|
|
}
|
|
}
|