剧本UI逻辑更改,疏散人群UI部分逻辑编写
This commit is contained in:
parent
3a93a71921
commit
5d16c5db3a
File diff suppressed because it is too large
Load Diff
@ -49,6 +49,9 @@ public class Panel : MonoBehaviour
|
|||||||
public SelectedInfo selectedInfo;
|
public SelectedInfo selectedInfo;
|
||||||
public Dictionary<string, List<SelectedInfo>> sceneDataDictionary = new Dictionary<string, List<SelectedInfo>>();//不同的场景存取不同的人员数据
|
public Dictionary<string, List<SelectedInfo>> sceneDataDictionary = new Dictionary<string, List<SelectedInfo>>();//不同的场景存取不同的人员数据
|
||||||
public ManagerPanel managerPanel1;
|
public ManagerPanel managerPanel1;
|
||||||
|
private bool isPersonSelected = false; // 标志是否选择了人员
|
||||||
|
private bool isDutySelected = false; // 标志是否选择了职责
|
||||||
|
private bool isSceneSelected = false; // 标志是否选择了场景
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
@ -86,6 +89,10 @@ public class Panel : MonoBehaviour
|
|||||||
//处理人员管理按钮
|
//处理人员管理按钮
|
||||||
public void ClickPersonnelManagement()
|
public void ClickPersonnelManagement()
|
||||||
{
|
{
|
||||||
|
foreach (Transform child in panelContent)
|
||||||
|
{
|
||||||
|
Destroy(child.gameObject);
|
||||||
|
}
|
||||||
foreach (var sceneEntry in sceneDataDictionary)
|
foreach (var sceneEntry in sceneDataDictionary)
|
||||||
{
|
{
|
||||||
Debug.Log($"场景: {sceneEntry.Key},人数: {sceneEntry.Value.Count}");
|
Debug.Log($"场景: {sceneEntry.Key},人数: {sceneEntry.Value.Count}");
|
||||||
@ -94,6 +101,8 @@ public class Panel : MonoBehaviour
|
|||||||
|
|
||||||
Text sceneText= managerPanelInstance.transform.Find("top/sceneName").GetComponent<Text>();
|
Text sceneText= managerPanelInstance.transform.Find("top/sceneName").GetComponent<Text>();
|
||||||
sceneText.text = sceneEntry.Key;
|
sceneText.text = sceneEntry.Key;
|
||||||
|
|
||||||
|
|
||||||
managerPanel1.CreateScenePanel(sceneEntry.Key, sceneEntry.Value, managerPanelInstance);
|
managerPanel1.CreateScenePanel(sceneEntry.Key, sceneEntry.Value, managerPanelInstance);
|
||||||
|
|
||||||
//managerPanel1.SetPlate();
|
//managerPanel1.SetPlate();
|
||||||
@ -103,6 +112,9 @@ public class Panel : MonoBehaviour
|
|||||||
|
|
||||||
//处理点击确认按钮
|
//处理点击确认按钮
|
||||||
public void ClickSureBtn()
|
public void ClickSureBtn()
|
||||||
|
{
|
||||||
|
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作
|
||||||
|
if (isPersonSelected && isDutySelected && isSceneSelected)
|
||||||
{
|
{
|
||||||
// 保存选中的人员信息到场景数据字典中
|
// 保存选中的人员信息到场景数据字典中
|
||||||
string sceneName = selectedInfo.scene;
|
string sceneName = selectedInfo.scene;
|
||||||
@ -123,6 +135,16 @@ public class Panel : MonoBehaviour
|
|||||||
// 打印当前场景人员信息
|
// 打印当前场景人员信息
|
||||||
Debug.Log($"场景: {sceneName},选中的人员: {selectedInfo.name},职责: {selectedInfo.duty}");
|
Debug.Log($"场景: {sceneName},选中的人员: {selectedInfo.name},职责: {selectedInfo.duty}");
|
||||||
|
|
||||||
|
sureBtn.interactable = false; // 禁用确认按钮
|
||||||
|
isPersonSelected = false;
|
||||||
|
isDutySelected = false;
|
||||||
|
isSceneSelected = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("请确保选择了人员、职责和场景!");
|
||||||
|
}
|
||||||
|
|
||||||
// 可以在这里根据需求继续处理选中的数据
|
// 可以在这里根据需求继续处理选中的数据
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +171,7 @@ public class Panel : MonoBehaviour
|
|||||||
|
|
||||||
// 创建 PointerEventData 来记录点击事件的数据
|
// 创建 PointerEventData 来记录点击事件的数据
|
||||||
PointerEventData pointerData = new PointerEventData(eventSystem);
|
PointerEventData pointerData = new PointerEventData(eventSystem);
|
||||||
pointerData.position = Input.mousePosition;//获取鼠标点击的位置
|
pointerData.position = Input.mousePosition; // 获取鼠标点击的位置
|
||||||
|
|
||||||
// 用于存储射线检测的结果
|
// 用于存储射线检测的结果
|
||||||
List<RaycastResult> results = new List<RaycastResult>();
|
List<RaycastResult> results = new List<RaycastResult>();
|
||||||
@ -166,30 +188,40 @@ public class Panel : MonoBehaviour
|
|||||||
if (clickedButton != null)
|
if (clickedButton != null)
|
||||||
{
|
{
|
||||||
Text buttonText = clickedButton.GetComponentInChildren<Text>();
|
Text buttonText = clickedButton.GetComponentInChildren<Text>();
|
||||||
if (buttonText != null && buttonText.tag == Tags.people)//这里可以获取标签为人员的信息
|
if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
|
||||||
{
|
{
|
||||||
|
|
||||||
name = buttonText.text;
|
name = buttonText.text;
|
||||||
Debug.Log(name);
|
Debug.Log(name);
|
||||||
selectedInfo.name = name;
|
selectedInfo.name = name;
|
||||||
|
isPersonSelected = true; // 选择了人员
|
||||||
}
|
}
|
||||||
else if (buttonText != null && buttonText.tag == Tags.scene)//这里可以获取标签为场景的信息
|
else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
|
||||||
{
|
{
|
||||||
scene = buttonText.text;
|
scene = buttonText.text;
|
||||||
Debug.Log(scene);
|
Debug.Log(scene);
|
||||||
selectedInfo.scene = scene;
|
selectedInfo.scene = scene;
|
||||||
|
isSceneSelected = true; // 选择了场景
|
||||||
}
|
}
|
||||||
else if (buttonText != null && buttonText.tag == Tags.duty)//这里可以获取标签为职责的信息
|
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
|
||||||
{
|
{
|
||||||
duty = buttonText.text;
|
duty = buttonText.text;
|
||||||
Debug.Log(duty);
|
Debug.Log(duty);
|
||||||
selectedInfo.duty = duty;
|
selectedInfo.duty = duty;
|
||||||
}
|
isDutySelected = true; // 选择了职责
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据选择情况,启用或禁用确认按钮
|
||||||
|
UpdateConfirmButtonState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//判断是否能够点击按钮
|
||||||
|
private void UpdateConfirmButtonState()
|
||||||
|
{
|
||||||
|
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
|
||||||
|
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
|
||||||
|
}
|
||||||
//设置安排文字
|
//设置安排文字
|
||||||
public void SetText()
|
public void SetText()
|
||||||
{
|
{
|
||||||
@ -204,7 +236,7 @@ public class Panel : MonoBehaviour
|
|||||||
// 遍历所有已实例化的人员预制体
|
// 遍历所有已实例化的人员预制体
|
||||||
foreach (Transform child in peopleCountent)
|
foreach (Transform child in peopleCountent)
|
||||||
{
|
{
|
||||||
// 获取该子物体上的 Text 组件(假设它存储了姓名)
|
// 获取该子物体上的 Text 组件
|
||||||
Text personNameText = child.GetComponentInChildren<Text>();
|
Text personNameText = child.GetComponentInChildren<Text>();
|
||||||
|
|
||||||
if (personNameText != null)
|
if (personNameText != null)
|
||||||
@ -223,7 +255,7 @@ public class Panel : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 点击选中角色,改变视觉效果
|
// 点击选中角色,改变视觉效果(可复用)
|
||||||
public void OnPeopleItemClicked(GameObject clickedItem)
|
public void OnPeopleItemClicked(GameObject clickedItem)
|
||||||
{
|
{
|
||||||
// 如果有之前选中的角色,重置其视觉效果
|
// 如果有之前选中的角色,重置其视觉效果
|
||||||
|
@ -11,6 +11,7 @@ public class ManagerPanel : MonoBehaviour
|
|||||||
public Transform panelContent;
|
public Transform panelContent;
|
||||||
public GameObject personItemPrefab; // 用于显示人员信息的UI项
|
public GameObject personItemPrefab; // 用于显示人员信息的UI项
|
||||||
public GameObject scenePanelPrefab;
|
public GameObject scenePanelPrefab;
|
||||||
|
public ScrollRect scrollRect; // 引用ScrollRect组件,处理滑动
|
||||||
|
|
||||||
[Header("组件")]
|
[Header("组件")]
|
||||||
public Text sceneText;
|
public Text sceneText;
|
||||||
@ -28,24 +29,8 @@ public class ManagerPanel : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
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<SelectedInfo> peopleList,GameObject parentTransform)
|
public void CreateScenePanel(string sceneName, List<SelectedInfo> peopleList,GameObject parentTransform)
|
||||||
{
|
{
|
||||||
@ -59,11 +44,10 @@ public class ManagerPanel : MonoBehaviour
|
|||||||
CreatePersonItem(person, parentTransform); // 传递 managerPanelContent
|
CreatePersonItem(person, parentTransform); // 传递 managerPanelContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据人员信息生成一个UI项
|
// 根据人员信息生成一个UI项
|
||||||
private void CreatePersonItem(SelectedInfo person, GameObject parentTransform)
|
private void CreatePersonItem(SelectedInfo person, GameObject parentTransform)
|
||||||
{
|
{
|
||||||
Transform contentTransform = parentTransform.transform.Find("Content");
|
Transform contentTransform = parentTransform.transform.Find("Scroll View/Viewport/Content");
|
||||||
// 实例化一个人员项并将其作为场景面板的子物体
|
// 实例化一个人员项并将其作为场景面板的子物体
|
||||||
GameObject item = Instantiate(personItemPrefab, contentTransform);
|
GameObject item = Instantiate(personItemPrefab, contentTransform);
|
||||||
ArrangementItem arrangementItem = item.GetComponent<ArrangementItem>();
|
ArrangementItem arrangementItem = item.GetComponent<ArrangementItem>();
|
||||||
@ -72,45 +56,51 @@ public class ManagerPanel : MonoBehaviour
|
|||||||
arrangementItem.duty.text = person.duty; // 设置职责
|
arrangementItem.duty.text = person.duty; // 设置职责
|
||||||
}
|
}
|
||||||
// 点击项时调用
|
// 点击项时调用
|
||||||
//public void OnItemClicked(GameObject clickedItem)
|
public void OnItemClicked(GameObject clickedItem)
|
||||||
//{
|
{
|
||||||
// // 如果有之前选中的项,恢复其原始大小
|
// 如果有之前选中的项,恢复其原始大小
|
||||||
// if (currentSelectedItem != null)
|
if (currentSelectedItem != null)
|
||||||
// {
|
{
|
||||||
// RectTransform rt = currentSelectedItem.GetComponent<RectTransform>();
|
RectTransform rt = currentSelectedItem.GetComponent<RectTransform>();
|
||||||
// rt.localScale = originalScale; // 恢复原始大小
|
rt.localScale = originalScale; // 恢复原始大小
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // 更新当前选中的项
|
// 记录当前选中项的原始大小
|
||||||
// currentSelectedItem = clickedItem;
|
RectTransform clickedItemRT = clickedItem.GetComponent<RectTransform>();
|
||||||
// RectTransform clickedItemRT = clickedItem.GetComponent<RectTransform>();
|
if (originalScale == Vector3.zero)
|
||||||
|
{
|
||||||
|
originalScale = clickedItemRT.localScale; // 只记录一次原始大小
|
||||||
|
}
|
||||||
|
|
||||||
// // 放大当前选中的项
|
// 更新当前选中的项
|
||||||
// clickedItemRT.localScale = originalScale * 1.5f; // 放大1.5倍
|
currentSelectedItem = clickedItem;
|
||||||
|
|
||||||
// // 使当前选中的项居中显示
|
// 放大当前选中的项
|
||||||
// ScrollRect scrollRect = panelContent.GetComponentInParent<ScrollRect>();
|
clickedItemRT.localScale = originalScale * 1.2f; // 放大1.2倍
|
||||||
// if (scrollRect != null)
|
// 使当前选中的项居中显示
|
||||||
// {
|
//CenterOnItem(clickedItemRT);
|
||||||
// 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 void CenterOnItem(RectTransform item)
|
||||||
// }
|
{
|
||||||
//}
|
// 获取ScrollView的Viewport位置
|
||||||
|
RectTransform viewportRect = scrollRect.viewport.GetComponent<RectTransform>();
|
||||||
|
|
||||||
//// 平滑滚动到目标位置
|
// 计算选中项相对于视口的偏移量
|
||||||
//private IEnumerator SmoothScrollToPosition(Vector3 targetPosition, float duration)
|
float itemMinX = item.localPosition.x - item.rect.width / 2;
|
||||||
//{
|
float itemMaxX = item.localPosition.x + item.rect.width / 2;
|
||||||
// Vector3 startPos = panelContent.position;
|
|
||||||
// float time = 0;
|
|
||||||
|
|
||||||
// while (time < duration)
|
// 获取Scroll Rect的宽度
|
||||||
// {
|
float viewportWidth = viewportRect.rect.width;
|
||||||
// panelContent.position = Vector3.Lerp(startPos, targetPosition, time / duration);
|
|
||||||
// time += Time.deltaTime;
|
|
||||||
// yield return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// panelContent.position = targetPosition;
|
// 计算Normalized Position
|
||||||
//}
|
float normalizedPos = Mathf.InverseLerp(itemMinX, itemMaxX, 0);
|
||||||
|
|
||||||
|
// 设置Scroll Rect的normalizedPosition,来使项目居中
|
||||||
|
scrollRect.horizontalNormalizedPosition = normalizedPos;
|
||||||
|
}
|
||||||
|
public void OnClickCloseBtn()
|
||||||
|
{
|
||||||
|
transform.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ public class SelectScenePanel : MonoBehaviour
|
|||||||
schoolChoiceLable.gameObject.SetActive(true);
|
schoolChoiceLable.gameObject.SetActive(true);
|
||||||
eventChoiceLable.gameObject.SetActive(false);
|
eventChoiceLable.gameObject.SetActive(false);
|
||||||
//动态加载学校选择预制体
|
//动态加载学校选择预制体
|
||||||
for (int i=0;i<6;i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
GameObject slot = GameObject.Instantiate<GameObject>(schoolPrefab, schoolList);
|
GameObject slot = GameObject.Instantiate<GameObject>(schoolPrefab, schoolList);
|
||||||
//schoolPrefab.gameObject.GetComponent<Image>().sprite = Resources.Load("");
|
//schoolPrefab.gameObject.GetComponent<Image>().sprite = Resources.Load("");
|
||||||
@ -62,7 +62,7 @@ public class SelectScenePanel : MonoBehaviour
|
|||||||
SchoolInfo gameObject = GetComponentInChildren<SchoolInfo>();
|
SchoolInfo gameObject = GetComponentInChildren<SchoolInfo>();
|
||||||
foreach (SchoolInfo item in schoolInfos)
|
foreach (SchoolInfo item in schoolInfos)
|
||||||
{
|
{
|
||||||
if(item.gameObject.transform.GetComponent<Toggle>().isOn)
|
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
||||||
{
|
{
|
||||||
this.schoolId = item.schoolId;
|
this.schoolId = item.schoolId;
|
||||||
this.schoolName = item.schoolName;
|
this.schoolName = item.schoolName;
|
||||||
@ -75,7 +75,7 @@ public class SelectScenePanel : MonoBehaviour
|
|||||||
public void SelectEvent()
|
public void SelectEvent()
|
||||||
{
|
{
|
||||||
EventInfo eventInfo = GetComponentInChildren<EventInfo>();
|
EventInfo eventInfo = GetComponentInChildren<EventInfo>();
|
||||||
foreach(EventInfo item in eventInfos)
|
foreach (EventInfo item in eventInfos)
|
||||||
{
|
{
|
||||||
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ public class SelectScenePanel : MonoBehaviour
|
|||||||
public void SelsctDifficulty()
|
public void SelsctDifficulty()
|
||||||
{
|
{
|
||||||
auth_createTemplate auth_CreateTemplate = new auth_createTemplate();
|
auth_createTemplate auth_CreateTemplate = new auth_createTemplate();
|
||||||
foreach(Toggle item in difficultyList)
|
foreach (Toggle item in difficultyList)
|
||||||
{
|
{
|
||||||
if (item.isOn)
|
if (item.isOn)
|
||||||
{
|
{
|
||||||
@ -140,4 +140,5 @@ public class SelectScenePanel : MonoBehaviour
|
|||||||
Debug.LogError("ContinueBtn 按钮组件未找到!");
|
Debug.LogError("ContinueBtn 按钮组件未找到!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user