MayHeCome/Assets/ChengHui/Script/UI_InformationPanel.cs
2024-12-18 17:55:34 +08:00

200 lines
6.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Schema;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UI_InformationPanel : MonoBehaviour
{
public Transform UpdateBuilding;
public Transform SetBlob;
[SerializeField] private Transform OnOffButton;
[SerializeField] private Transform SecondInfoPanel;
[SerializeField] private GameObject TechItemPrefab;
public GameObject CeremonyButton;
public Transform itemPanel;
public GameObject YishiUIObject;
[SerializeField] private AudioClip OverClip;
[SerializeField] private AudioClip ClickClip;
private AudioSource audioSource;
private Dictionary<SpecailBuff_Buildings.BuildingTechItem,GameObject> items = new Dictionary<SpecailBuff_Buildings.BuildingTechItem,GameObject>();
//下方成就
private List<Transform> UpgradeItems = new List<Transform>();
private List<Transform> UnlockedItems = new List<Transform>();
private Buildings buildings;
[System.Serializable]
public class BTInfo
{
public string BITName;
public string BTIDescription;
public string BTIWordDescription;
public int currentNum;
public BTInfo(string name, string description, string btiWordDescription, int currentNum = 0)
{
BITName = name;
BTIDescription = description;
BTIWordDescription = btiWordDescription;
this.currentNum = currentNum;
}
}
void Start()
{
//GetComponent<CanvasGroup>().alpha = 0;
//YishiUIObject = GameObject.Find("仪式UI");
gameObject.SetActive(false);
buildings = transform.parent.GetComponent<Buildings>();
audioSource = GetComponent<AudioSource>();
}
public void PlayUIAudio(int index)
{
if (index == 0)
{
audioSource.PlayOneShot(OverClip);
}
if (index == 1)
{
audioSource.PlayOneShot(ClickClip);
}
}
private void FixedUpdate()
{
/*//每帧逐个【建筑科技项】检测,是否资源足够
foreach (SpecailBuff_Buildings.BuildingTechItem bti in items.Keys)
{
if (CheckUnlock(bti.faithCost,bti.blobCost,bti.woodCost))
{
items[bti].transform.Find("AddTuanZi").GetComponent<Button>().interactable = true;
foreach (TMP_Text tmpText in items[bti].transform.GetChild(0).GetChild(3).GetComponentsInChildren<TMP_Text>())
{
tmpText.color = Color.white;
}
}
else
{
items[bti].GetComponent<Button>().interactable = false;
foreach (TMP_Text tmpText in items[bti].transform.GetChild(0).GetChild(3).GetComponentsInChildren<TMP_Text>())
{
tmpText.color = Color.red;
}
}
}*/
}
//临时,为建筑升级特制的建筑科技项
/*public void SetBuildingUpgradeStatus(int current, int faith, int blob,int wood)
{
UpdateBuilding.GetChild(3).GetComponent<TMP_Text>().text = current.ToString();
bool unlocked = CheckUnlock(faith,blob,wood);
if (unlocked)
{
UpdateBuilding.GetComponent<Button>().interactable = true;
foreach (TMP_Text tmpText in UpdateBuilding.GetChild(5).GetComponentsInChildren<TMP_Text>())
{
tmpText.color = Color.white;
}
}
else
{
UpdateBuilding.GetComponent<Button>().interactable = false;
foreach (TMP_Text tmpText in UpdateBuilding.GetChild(5).GetComponentsInChildren<TMP_Text>())
{
tmpText.color = Color.red;
}
}
}*/
//临时,为团子增加特指的建筑科技项
/*public void SetBlobUpgradeStatus(int current)
{
SetBlob.GetChild(3).GetComponent<TMP_Text>().text = current.ToString();
//bool unlocked = CheckUnlock(0,1,0);
if (unlocked)
{
SetBlob.GetComponent<Button>().interactable = true;
foreach (TMP_Text tmpText in SetBlob.GetChild(5).GetComponentsInChildren<TMP_Text>())
{
tmpText.color = Color.white;
}
}
else
{
SetBlob.GetComponent<Button>().interactable = false;
foreach (TMP_Text tmpText in SetBlob.GetChild(5).GetComponentsInChildren<TMP_Text>())
{
tmpText.color = Color.red;
}
}
}*/
//还没太写好可能有BUG
public void InstantiateCeremony(string CeremonyName, int index)
{
CeremonyButton.SetActive(true);
CeremonyButton.transform.GetChild(0).GetChild(0).GetComponent<TMP_Text>().text = CeremonyName;
CeremonyButton.transform.GetChild(0).GetComponent<Button>().onClick.AddListener(delegate ()
{
YiShiUI.Instance.YiShiMode = index;
YishiUIObject.SetActive(true);
//Destroy(ceremonyButton);
});
}
//增加新的【建筑科技项】
public void AddTechItem(SpecailBuff_Buildings.BuildingTechItem techItem,int siblingIndex=-1)
{
GameObject techItemObject = Instantiate(TechItemPrefab, itemPanel);
if (siblingIndex >= 0)
{
techItemObject.transform.SetSiblingIndex(siblingIndex);
}
techItemObject.GetComponent<BuildingTechItemUI>().CreateBuildingTechItemUI(techItem,this);
items.Add(techItem, techItemObject);
//点击后如果解锁,删除当前【建筑科技项】,消耗对应资源
//-----------------------------------------------------
//注意如果团子消耗方式与建筑物高度相关请把团子消耗写在Buff里
//-----------------------------------------------------
}
public int RemoveTechItem(SpecailBuff_Buildings.BuildingTechItem bti)
{
int index = items[bti].transform.GetSiblingIndex();
Destroy(items[bti]);
items.Remove(bti);
return index;
}
//生成【建筑科技项】的资源需求,基于需求和父物体
public void OpenSecondInfo(string techName)
{
SecondInfoPanel.gameObject.SetActive(true);
BTInfo tmpInfo = Singleton<TreeControl>.Instance.GetTechInfo(techName);
SecondInfoPanel.gameObject.GetComponent<SecondInfo>().SetSecondPanel(tmpInfo);
}
public void CloseSecondInfo()
{
SecondInfoPanel.gameObject.SetActive(false);
}
}