_xiaofang/xiaofang/Assets/Res/gsj/scripts/Drill.cs

88 lines
2.6 KiB
C#
Raw Normal View History

2024-12-20 10:10:19 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Drill : MonoBehaviour
{
2024-12-27 23:12:22 +08:00
public Text username;
public Text companyName;
2024-12-20 10:10:19 +08:00
private Button ScheduledBtn;
2024-12-27 16:29:07 +08:00
private bool isadministrator=false; // <20>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>Ա
2024-12-20 10:10:19 +08:00
private bool eventAdded = false; // <20><>ֹ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
public delegate void BoolChangedHandler(bool value);
public event BoolChangedHandler OnBoolAChanged;
private Text noRoomText; // "û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22><><EFBFBD>ı<EFBFBD>
private Transform content; // Scroll View Content
// <20><>¼<EFBFBD><C2BC>һ<EFBFBD>ε<EFBFBD> isadministrator ״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD>ظ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>߼<EFBFBD>
private bool lastIsAdministratorState;
2024-12-27 23:12:22 +08:00
2024-12-20 10:10:19 +08:00
void Start()
{
ScheduledBtn = transform.Find("down/ScheduledBtn").GetComponent<Button>();
ScheduledBtn.gameObject.SetActive(false); // <20><>ʼ<EFBFBD><CABC><EFBFBD>ذ<EFBFBD>ť
noRoomText = transform.Find("Text").GetComponent<Text>();
noRoomText.gameObject.SetActive(false); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
content = transform.Find("Mid/Scroll View/Viewport/Content");
2024-12-28 14:30:01 +08:00
if(GlobalData.ServerData.data.isCreater=="Y")
2024-12-27 23:12:22 +08:00
{
username.text = $"[{GlobalData.ServerData.data.userId}]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>";
}
else username.text = $"[{GlobalData.ServerData.data.userId}]";
companyName.text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[" + GlobalData.ServerData.data.companyName +"]";
2024-12-20 10:10:19 +08:00
}
void Update()
{
2024-12-27 16:29:07 +08:00
2024-12-20 10:10:19 +08:00
// ʵʱ<CAB5><CAB1><EFBFBD>ⷿ<EFBFBD><E2B7BF><EFBFBD>б<EFBFBD><D0B1>Ƿ<EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD> noRoomText <20>Ŀɼ<C4BF><C9BC><EFBFBD>
noRoomText.gameObject.SetActive(content.childCount == 0);
2024-12-27 16:29:07 +08:00
isadministrator=ReadRoom.instance.isadministrator;
2024-12-20 10:10:19 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա״̬<D7B4>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (isadministrator != lastIsAdministratorState)
{
lastIsAdministratorState = isadministrator; // <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>¼
UpdateScheduledBtnVisibility(); // <20><><EFBFBD>°<EFBFBD>ť<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>
}
}
// <20><><EFBFBD><EFBFBD> isadministrator ״̬ʵʱ<CAB5><CAB1><EFBFBD><EFBFBD> ScheduledBtn <20>Ŀɼ<C4BF><C9BC><EFBFBD>
private void UpdateScheduledBtnVisibility()
{
if (isadministrator)
{
ScheduledBtn.gameObject.SetActive(true);
// <20><>ֹ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
if (!eventAdded)
{
ScheduledBtn.onClick.AddListener(OnClickScheduleBtn);
eventAdded = true;
}
}
else
{
ScheduledBtn.gameObject.SetActive(false);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OnBoolAChanged?.Invoke(isadministrator);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
void OnClickScheduleBtn()
{
2024-12-27 16:29:07 +08:00
//SceneManager.LoadScene(2);
2024-12-20 10:10:19 +08:00
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD>ť<EFBFBD><C5A5>");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD><D3BE><EFBFBD><EFBFBD>߼<EFBFBD>
2024-12-28 15:48:01 +08:00
SceneManager.LoadScene("scheduled_exercise");
2024-12-20 10:10:19 +08:00
}
}