using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //板块信息 public class ManagerPanel : MonoBehaviour { public Panel panelScript; // 引用Panel类的实例 public Transform managerPanelContent; // 管理面板中用于显示人员的UI容器 public Transform panelContent; public GameObject personItemPrefab; // 用于显示人员信息的UI项 public GameObject scenePanelPrefab; [Header("组件")] public Text sceneText; [Header("数据")] private GameObject currentSelectedItem = null; // 当前选中的项 private Vector3 originalScale; // 记录选中项的原始大小 // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { //SetPlate(); } //public void SetPlate() //{ // // 清空当前显示 // foreach (Transform child in managerPanelContent) // { // Debug.Log("Destroying: " + child.gameObject.name); // Destroy(child.gameObject); // } // // 遍历字典中的每个场景,生成对应的UI项 // foreach (var sceneEntry in panelScript.sceneDataDictionary) // { // CreateScenePanel(sceneEntry.Key, sceneEntry.Value); // 为每个场景调用封装的方法 // } //} // 根据场景名称和对应的人员列表生成场景面板和人员项 public void CreateScenePanel(string sceneName, List peopleList,GameObject parentTransform) { if (personItemPrefab == null) { Debug.LogError("personItemPrefab 没有被正确赋值!"); } // 遍历该场景下的所有人员,生成对应的UI项 foreach (SelectedInfo person in peopleList) { CreatePersonItem(person, parentTransform); // 传递 managerPanelContent } } // 根据人员信息生成一个UI项 private void CreatePersonItem(SelectedInfo person, GameObject parentTransform) { Transform contentTransform = parentTransform.transform.Find("Content"); // 实例化一个人员项并将其作为场景面板的子物体 GameObject item = Instantiate(personItemPrefab, contentTransform); ArrangementItem arrangementItem = item.GetComponent(); arrangementItem.name.text = person.name; // 设置姓名 arrangementItem.duty.text = person.duty; // 设置职责 } // 点击项时调用 //public void OnItemClicked(GameObject clickedItem) //{ // // 如果有之前选中的项,恢复其原始大小 // if (currentSelectedItem != null) // { // RectTransform rt = currentSelectedItem.GetComponent(); // rt.localScale = originalScale; // 恢复原始大小 // } // // 更新当前选中的项 // currentSelectedItem = clickedItem; // RectTransform clickedItemRT = clickedItem.GetComponent(); // // 放大当前选中的项 // clickedItemRT.localScale = originalScale * 1.5f; // 放大1.5倍 // // 使当前选中的项居中显示 // ScrollRect scrollRect = panelContent.GetComponentInParent(); // if (scrollRect != null) // { // float targetX = clickedItemRT.position.x - scrollRect.viewport.position.x; // Vector3 targetPos = new Vector3(targetX, clickedItemRT.position.y, clickedItemRT.position.z); // StartCoroutine(SmoothScrollToPosition(targetPos, 0.5f)); // 平滑滚动到目标位置 // } //} //// 平滑滚动到目标位置 //private IEnumerator SmoothScrollToPosition(Vector3 targetPosition, float duration) //{ // Vector3 startPos = panelContent.position; // float time = 0; // while (time < duration) // { // panelContent.position = Vector3.Lerp(startPos, targetPosition, time / duration); // time += Time.deltaTime; // yield return null; // } // panelContent.position = targetPosition; //} }