场景选择更改和剧本部分更改
This commit is contained in:
parent
5d16c5db3a
commit
dddce7611a
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
@ -76,16 +77,19 @@ public class Panel : MonoBehaviour
|
||||
peopleList.Add(item); // 将每个实例化的角色添加到列表中
|
||||
}
|
||||
}
|
||||
|
||||
//动态加载职责
|
||||
public void DynamicLoadingDuty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//动态加载场景
|
||||
public void DynamicLoadingScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//处理人员管理按钮
|
||||
public void ClickPersonnelManagement()
|
||||
{
|
||||
@ -124,13 +128,30 @@ public class Panel : MonoBehaviour
|
||||
{
|
||||
sceneDataDictionary[sceneName] = new List<SelectedInfo>();
|
||||
}
|
||||
else
|
||||
|
||||
// 需要判断是否达到了职责的人员上限
|
||||
bool isLimitReached = false;
|
||||
|
||||
// 获取当前场景中的所有人员信息
|
||||
List<SelectedInfo> currentSceneInfo = sceneDataDictionary[sceneName];
|
||||
|
||||
// 如果选中了“主持人”、“各组长”或“总指挥”,则限制数量为1
|
||||
if (selectedInfo.duty == "主持人" || selectedInfo.duty == "组长" || selectedInfo.duty == "总指挥")
|
||||
{
|
||||
Debug.Log("没有选场景");
|
||||
int count = currentSceneInfo.Count(info => info.duty == selectedInfo.duty); // 统计当前职责人数
|
||||
|
||||
if (count >= 1) // 如果已经有1个此职责的人选
|
||||
{
|
||||
Debug.LogError($"{selectedInfo.duty} 已达最大人数限制!");
|
||||
isLimitReached = true; // 标记限制已达
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有达到上限,则可以添加人员信息
|
||||
if (!isLimitReached)
|
||||
{
|
||||
// 将当前选中的人员信息添加到对应场景的人员列表中
|
||||
sceneDataDictionary[sceneName].Add(selectedInfo);
|
||||
currentSceneInfo.Add(selectedInfo);
|
||||
|
||||
// 打印当前场景人员信息
|
||||
Debug.Log($"场景: {sceneName},选中的人员: {selectedInfo.name},职责: {selectedInfo.duty}");
|
||||
@ -139,7 +160,9 @@ public class Panel : MonoBehaviour
|
||||
isPersonSelected = false;
|
||||
isDutySelected = false;
|
||||
isSceneSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("请确保选择了人员、职责和场景!");
|
||||
@ -148,6 +171,7 @@ public class Panel : MonoBehaviour
|
||||
// 可以在这里根据需求继续处理选中的数据
|
||||
}
|
||||
|
||||
|
||||
//处理界面关闭按钮
|
||||
public void ClickCloseBtn()
|
||||
{
|
||||
@ -216,17 +240,20 @@ public class Panel : MonoBehaviour
|
||||
UpdateConfirmButtonState();
|
||||
}
|
||||
}
|
||||
|
||||
//判断是否能够点击按钮
|
||||
private void UpdateConfirmButtonState()
|
||||
{
|
||||
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
|
||||
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
|
||||
}
|
||||
|
||||
//设置安排文字
|
||||
public void SetText()
|
||||
{
|
||||
arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]";
|
||||
}
|
||||
|
||||
//筛选
|
||||
public void SetInputFile()
|
||||
{
|
||||
@ -255,6 +282,7 @@ public class Panel : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 点击选中角色,改变视觉效果(可复用)
|
||||
public void OnPeopleItemClicked(GameObject clickedItem)
|
||||
{
|
||||
|
@ -6,10 +6,11 @@ using UnityEngine.UI;
|
||||
public class EventInfo : MonoBehaviour
|
||||
{
|
||||
public int eventId;
|
||||
public string eventName;
|
||||
public Text text;
|
||||
public Text eventName;
|
||||
public Image maskImage;
|
||||
public bool isOpen;
|
||||
void Start()
|
||||
{
|
||||
text.text = eventName;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
@ -7,85 +8,235 @@ using UnityEngine.UI;
|
||||
|
||||
public class SelectScenePanel : MonoBehaviour
|
||||
{
|
||||
public GameObject schoolPrefab;//滑动视图预制体
|
||||
public Transform schoolList;//预制体列表
|
||||
public ToggleGroup schooltoggleGroup;
|
||||
public ToggleGroup schoolimageGroup;
|
||||
public Toggle[] toggleList;
|
||||
[Header("组件")]
|
||||
public GameObject scenePrefab;//滑动视图预制体
|
||||
public Transform sceneList;//预制体列表
|
||||
public GameObject schoolPrefab;//学校按钮预制体
|
||||
public Transform schoolList;//学校预制体列表
|
||||
public GameObject eventPrefab;//事件按钮预制体
|
||||
public Transform eventList;//学校预制体列表
|
||||
public ToggleGroup schoolGroup;//学校ToggleGroup
|
||||
public ToggleGroup sceneGroup;//场景ToggleGroup
|
||||
public ToggleGroup eventGroup;//事件ToggleGroup
|
||||
public GameObject scoolSelectBtn;//学校选择按钮
|
||||
public GameObject schoolChoiceLable;//学校选择界面
|
||||
public GameObject eventChoiceLable;//事件选择界面
|
||||
public bool isOpen = false;
|
||||
public List<SchoolInfo> schoolInfos = new List<SchoolInfo>();//学校信息
|
||||
public List<EventInfo> eventInfos = new List<EventInfo>();//事件信息
|
||||
public List<Toggle> difficultyList = new List<Toggle>();
|
||||
public List<SchoolInfo> schoolInfoList = new List<SchoolInfo>();//学校信息
|
||||
public List<EventInfo> eventInfoList = new List<EventInfo>();//事件信息
|
||||
public List<SceneItem> sceneItemList = new List<SceneItem>();//场景信息
|
||||
public List<Toggle> difficultyList = new List<Toggle>();//游戏难度
|
||||
public Button continueBtn;
|
||||
public Toggle[] toggleList;
|
||||
public Toggle[] schooltoggleList;
|
||||
public Toggle[] eventToggleList;
|
||||
|
||||
//数据
|
||||
|
||||
[Header("数据")]
|
||||
public int schoolId;
|
||||
public string schoolName;
|
||||
public string sceneName;
|
||||
public int eventId;
|
||||
public string eventName;
|
||||
public string difficulty;
|
||||
public string isBuy;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
schoolChoiceLable.gameObject.SetActive(true);
|
||||
eventChoiceLable.gameObject.SetActive(false);
|
||||
//动态加载学校选择预制体
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
GameObject slot = GameObject.Instantiate<GameObject>(schoolPrefab, schoolList);
|
||||
//schoolPrefab.gameObject.GetComponent<Image>().sprite = Resources.Load("");
|
||||
Toggle toggle = slot.GetComponent<Toggle>();
|
||||
|
||||
if (toggle != null)
|
||||
{
|
||||
// 将 Toggle 添加到 ToggleGroup 中
|
||||
toggle.group = schoolimageGroup;
|
||||
|
||||
// 将 Toggle 添加到 toggleList 中
|
||||
toggleList[i] = toggle;
|
||||
}
|
||||
}
|
||||
InstantiateScenePrefab();
|
||||
InstantiateSchoolPrefab();
|
||||
InstantiateEventPrefab();
|
||||
continueBtn.onClick.AddListener(OnClickContinueBtn);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
IsClick();
|
||||
}
|
||||
//学校选择,确定学校信息
|
||||
|
||||
//动态加载场景选择预制体
|
||||
public void InstantiateScenePrefab()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
|
||||
SceneItem item = slot.GetComponent<SceneItem>();
|
||||
item.sceneName.text = "场景" + i;
|
||||
if (item.IsOpen)
|
||||
{
|
||||
item.maskImage.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.maskImage.gameObject.SetActive(true);
|
||||
}
|
||||
Toggle toggle = slot.GetComponent<Toggle>();
|
||||
if (toggle != null)
|
||||
{
|
||||
toggle.group = sceneGroup;
|
||||
toggleList[i] = toggle;
|
||||
sceneItemList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//动态加载学校选择预制体
|
||||
public void InstantiateSchoolPrefab()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
GameObject slot = GameObject.Instantiate<GameObject>(schoolPrefab, schoolList);
|
||||
SchoolInfo item = slot.GetComponent<SchoolInfo>();
|
||||
item.schoolName.text = "南山中学";
|
||||
item.schoolId = i;
|
||||
Toggle toggle = slot.GetComponent<Toggle>();
|
||||
|
||||
if (toggle != null)
|
||||
{
|
||||
// 将 Toggle 添加到 ToggleGroup 中
|
||||
toggle.group = schoolGroup;
|
||||
|
||||
// 将 Toggle 添加到 schooltoggleList 中
|
||||
schooltoggleList[i] = toggle;
|
||||
|
||||
// 将 SchoolInfo 对象添加到 schoolInfos 列表中
|
||||
schoolInfoList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//动态加载事件选择预制体
|
||||
public void InstantiateEventPrefab()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList);
|
||||
EventInfo item = slot.GetComponent<EventInfo>();
|
||||
item.eventName.text = "停车场起火";
|
||||
item.eventId = i*10;
|
||||
Toggle toggle = slot.GetComponent<Toggle>();
|
||||
|
||||
if (toggle != null)
|
||||
{
|
||||
// 将 Toggle 添加到 ToggleGroup 中
|
||||
toggle.group = schoolGroup;
|
||||
toggle.isOn = false;
|
||||
|
||||
// 将 Toggle 添加到 schooltoggleList 中
|
||||
eventToggleList[i] = toggle;
|
||||
|
||||
// 将 SchoolInfo 对象添加到 schoolInfos 列表中
|
||||
eventInfoList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//学校选择
|
||||
public void SelectSchoolBtn()
|
||||
{
|
||||
SchoolInfo gameObject = GetComponentInChildren<SchoolInfo>();
|
||||
foreach (SchoolInfo item in schoolInfos)
|
||||
foreach (SchoolInfo item in schoolInfoList)
|
||||
{
|
||||
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
||||
{
|
||||
this.schoolId = item.schoolId;
|
||||
this.schoolName = item.schoolName;
|
||||
this.schoolName = item.schoolName.ToString();
|
||||
}
|
||||
}
|
||||
//Debug.Log("###############1:"+ this.schoolId);
|
||||
//Debug.Log("###############2:" + this.schoolName);
|
||||
Debug.Log("###############1:" + this.schoolId);
|
||||
Debug.Log("###############2:" + this.schoolName);
|
||||
}
|
||||
|
||||
//场景选择
|
||||
public void SelectSceneBtn()
|
||||
{
|
||||
bool sceneSelected = false; // 检查是否有场景被选择
|
||||
foreach (SceneItem item in sceneItemList)
|
||||
{
|
||||
// 检查当前的 Toggle 是否被选中
|
||||
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
||||
{
|
||||
// 设置场景名称
|
||||
this.sceneName = item.sceneName.text; // 获取 Text 组件的文本
|
||||
sceneSelected = true;
|
||||
break; // 找到选中的场景后退出循环
|
||||
}
|
||||
}
|
||||
//IsClick();
|
||||
}
|
||||
|
||||
//事件选择
|
||||
public void SelectEvnentBtn()
|
||||
{
|
||||
bool eventSelected = false; // 检查是否有场景被选择
|
||||
foreach (EventInfo item in eventInfoList)
|
||||
{
|
||||
// 检查当前的 Toggle 是否被选中
|
||||
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
||||
{
|
||||
// 设置场景名称
|
||||
this.eventName = item.eventName.text; // 获取 Text 组件的文本
|
||||
eventSelected = true;
|
||||
break; // 找到选中的场景后退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//事件及难度选择
|
||||
public void SelectEvent()
|
||||
{
|
||||
EventInfo eventInfo = GetComponentInChildren<EventInfo>();
|
||||
foreach (EventInfo item in eventInfos)
|
||||
foreach (EventInfo item in eventInfoList)
|
||||
{
|
||||
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
|
||||
{
|
||||
this.eventId = item.eventId;
|
||||
this.eventName = item.eventName;
|
||||
this.eventName = item.eventName.text;
|
||||
}
|
||||
}
|
||||
//Debug.Log("%%%%%%%%%%%%%1:"+ this.eventId);
|
||||
//Debug.Log("%%%%%%%%%%%%%2:" + this.eventName);
|
||||
}
|
||||
|
||||
//随机事件
|
||||
public void OnRandomEventClick()
|
||||
{
|
||||
//Debug.Log("&&&&&&&&&&&&&&&&&&&&&&&&&7" + eventInfoList.Count);
|
||||
// 随机选择一个事件
|
||||
if (eventInfoList.Count > 0)
|
||||
{
|
||||
int randomIndex = Random.Range(0, eventInfoList.Count);
|
||||
|
||||
// 取消所有Toggle的选中状态
|
||||
foreach (Toggle toggle in eventToggleList)
|
||||
{
|
||||
// 先检查toggle是否为null
|
||||
if (toggle != null)
|
||||
{
|
||||
toggle.isOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 选中随机事件
|
||||
if (eventToggleList[randomIndex] != null)
|
||||
{
|
||||
eventToggleList[randomIndex].isOn = true;
|
||||
this.eventName = eventInfoList[randomIndex].eventName.text; // 设置随机选择的事件名称
|
||||
Debug.Log("已选择随机事件: " + this.eventName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("随机选择的事件 Toggle 为 null!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("事件列表为空!");
|
||||
}
|
||||
}
|
||||
|
||||
//游戏难度选择
|
||||
public void SelsctDifficulty()
|
||||
{
|
||||
@ -100,39 +251,51 @@ public class SelectScenePanel : MonoBehaviour
|
||||
}
|
||||
//Debug.Log("%%%%%%%%%%%%%3:" + this.difficulty);
|
||||
}
|
||||
|
||||
//继续按钮,点击后上传数据
|
||||
public void OnClickContinueBtn()
|
||||
{
|
||||
//IsClick(); // 调用 IsClick 检查是否选中学校和场景
|
||||
SelectSchoolBtn();
|
||||
SelectSceneBtn();
|
||||
// 如果场景或学校没有选中,则不执行下面的操作
|
||||
if (continueBtn.interactable)
|
||||
{
|
||||
schoolChoiceLable.gameObject.SetActive(false);
|
||||
eventChoiceLable.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("没有选择场景或学校,继续按钮不可用!");
|
||||
}
|
||||
}
|
||||
|
||||
//提交按钮,点击上传数据和隐藏界面
|
||||
public void SubmitBtn()
|
||||
{
|
||||
SelectEvent();
|
||||
SelsctDifficulty();
|
||||
SelectEvnentBtn();
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
//通过判断Toggle的IsOn是否被打开来判断继续按钮是否置灰
|
||||
public void IsClick()
|
||||
{
|
||||
bool anyToggleSelected = false;
|
||||
//continueBtn.transform.parent
|
||||
// // 检查场景选择
|
||||
foreach (Toggle toggle in toggleList)
|
||||
{
|
||||
if (toggle.isOn)
|
||||
{
|
||||
anyToggleSelected = true;
|
||||
break; // 如果有一个 Toggle 被选中,停止检查
|
||||
break; // 如果有一个场景 Toggle 被选中,停止检查
|
||||
}
|
||||
}
|
||||
// 获取 ContinueBtn 按钮组件
|
||||
|
||||
|
||||
// 根据是否有 Toggle 被选中,设置 ContinueBtn 是否可交互
|
||||
// //根据是否有 Toggle 被选中,设置 ContinueBtn 是否可交互
|
||||
if (continueBtn != null)
|
||||
{
|
||||
Debug.Log(anyToggleSelected);
|
||||
continueBtn.interactable = anyToggleSelected; // 如果有选中的 Toggle,继续按钮可交互,否则不可交互
|
||||
}
|
||||
else
|
||||
@ -140,5 +303,4 @@ public class SelectScenePanel : MonoBehaviour
|
||||
Debug.LogError("ContinueBtn 按钮组件未找到!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SchoolInfo : MonoBehaviour
|
||||
{
|
||||
public int schoolId;
|
||||
public string schoolName;
|
||||
public Text schoolName;
|
||||
public Image maskImage;
|
||||
public bool isOpen;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user