using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using System; using UnityEngine.UI; using System.Reflection; public class SpecailBuff_Buildings : MonoBehaviour { public GameObject specialBuffButton_Prefab; public List buffName_CN = new List(); public List buffName_EN = new List(); public UI_InformationPanel infoPanel; //已弃用 private GameObject information_Panel; public Dictionary EN_CN = new Dictionary(); public Dictionary buff_ifActive = new Dictionary(); public Dictionary buff_Level = new Dictionary(); // Start is called before the first frame update public List buildTechItems = new List(); [System.Serializable] public struct Resource { public int Wood; public int Faith; public int TuanZi; public Resource(int w, int f, int t) { Wood = w; Faith = f; TuanZi = t; } } public enum BuffState { Close,UpGrade,Open } public class BuildingTechItem { public BuildingTechItem NextItem; public Action TechNameEN; public string TechNameCN; public int faithCost; public int woodCost; public int blobCost; public bool firstTech; private bool endless; public int currentNum; public BuildingTechItem(BuildingTechItem nextItem, Action techNameEN, string techNameCN, int faithCost, int woodCost, int blobCost,bool firstTech,int currentNum = 0) { this.NextItem = nextItem; this.TechNameEN = techNameEN; this.TechNameCN = techNameCN; this.faithCost = faithCost; this.woodCost = woodCost; this.blobCost = blobCost; this.firstTech = firstTech; this.currentNum = currentNum; } //----------------------------------------------------- //注意!如果团子消耗方式与建筑物高度相关,请把团子消耗写在Buff里! //----------------------------------------------------- public void CostResource() { Singleton.Instance.FaithCount -= faithCost; Singleton.Instance.WoodCount -= woodCost; //TODO: 有待维护消耗团子数 //BlobManager.Instance.AvailableBlobs.RemoveRange(0,blobCost); } public void SetEndless() { endless = true; } public void InvokeNextTech(UI_InformationPanel infoPanel,int siblingIndex) { if (NextItem != null) infoPanel.AddTechItem(NextItem, siblingIndex); if (endless) { //目前Endless 团子专属 currentNum++; infoPanel.AddTechItem(this,siblingIndex); }else if (currentNum>=0) { currentNum++; } } } public BuildingTechItem CreateTechItem(BuildingTechItem nextItem, Action techNameEN, string techNameCN, int faithCost, int woodCost, int blobCost,bool firstTech,int currentNum = -1) { BuildingTechItem newItem = new BuildingTechItem(nextItem, techNameEN, techNameCN, faithCost, woodCost, blobCost,firstTech,currentNum); if (firstTech) { //無消耗,则为直接解锁项目,直接解锁 if (faithCost == 0 && woodCost == 0 && blobCost == 0) { techNameEN.Invoke(); } //需要消耗资源解锁,则在UI面板中添加【建筑解锁项】 else { infoPanel.AddTechItem(newItem); } } return newItem; } void Start() { for (int i = 0; i < buffName_CN.Count; i++) { EN_CN.Add(buffName_EN[i], buffName_CN[i]); } AddFunctionToTreeContoller(); } public virtual void AddFunctionToTreeContoller() { } //1.在UI添加buff按钮2.不需要升级 public void AddBuff_Type_1(string BuffName, bool canBeClosed) { if (canBeClosed) { buff_ifActive.Add(BuffName, true); } GameObject Button = Instantiate(specialBuffButton_Prefab, information_Panel.transform.Find("Panel")); //设置按钮的脚本内容 Button.GetComponent().InitalSet(this,BuffName,canBeClosed); //激活buff Button.GetComponent().SpecialBuffActive(); } //2.在UI添加按钮,需要升级 public void AddBuff_Type_2(string BuffName,bool canBeClosed,int maxLevel,List resourceNeeded) { if (canBeClosed) { buff_ifActive.Add(BuffName, false);//满级以后才会被真正视为激活状态,然后可以被关闭 } GameObject Button = Instantiate(specialBuffButton_Prefab, information_Panel.transform.Find("Panel")); //设置按钮的脚本内容 Button.GetComponent().InitalSet(this, BuffName, canBeClosed,maxLevel,resourceNeeded); //修改按钮文本 Button.GetComponent().SetText(); } public void Step2_Type_1(string BuffName)//激活Buff { Invoke(BuffName, 0); } public void Step2_Type_2(string BuffName,int Level)//激活Buff { CallMethodByName(BuffName,Level); } public void CallMethodByName(string methodName, int Level) { // 获取当前实例的Type对象 Type type = this.GetType(); // 获取MethodInfo对象 MethodInfo methodInfo = type.GetMethod(methodName, new Type[] { typeof(int) }); // 检查MethodInfo是否找到 if (methodInfo != null) { // 调用方法 methodInfo.Invoke(this, new object[] { Level }); } else { Debug.LogError("Method not found: " + methodName); } } }