using PhxhSDK; using System.Collections.Generic; using TMPro; using UnityEngine; using Button = UnityEngine.UI.Button; using Image = UnityEngine.UI.Image; public class UI_VehicleChooseController : UIWindow { //UI GameObj ///Auto Gen Start/// public Image Image_BG; public Button Button_Back; public TMP_Text Text_Back; public Button Button_Home; public Image Image_HeadPic; public Image Image_BlackDown; public Image Image_Job; public TMP_Text Text_Lv; public TMP_Text Text_PropertyValue; public TMP_Text Text_Name; public Image Image_LevelBG; public Button Button_Level; public TMP_Text Text_Level; public Button Button_Team; public TMP_Text Text_Team; public Button Button_AllTerrian; public TMP_Text Text_AllTerrian; public Button Button_AllType; public TMP_Text Text_AllType; private GameObject mCurrentScrollViewContentObj = null; List mCurVehicles = new List(); List mShowList = new List(); Dictionary mUIHeadGoDic = new Dictionary(); Framework.PhxhScrollView _mCurrentScrollView = null; ///Auto Gen End/// // Use this for initialization public override void OnAwake() { //bind UI GameObj UI_VehicleChooseBinder.GetComponents(this); BindButton(Button_Back, OnBackClick); mCurrentScrollViewContentObj = FindObj("Image_BG/UI_Vehicle/ScrollView/Viewport/Content"); _mCurrentScrollView = GetComponent("Image_BG/UI_Vehicle/ScrollView"); mCurrentScrollViewContentObj = FindObj("Image_BG/UI_Vehicle/ScrollView/Viewport/Content"); } private void OnBackClick() { CloseWindow(); } //invoke when open window protected override void OnOpenWindow() { GetStorageData(); PreLoadAllVehicle(); RegisterEvent(); GetSelectedList(); CreateScrollView(); } private void GetSelectedList() { mShowList = mCurVehicles; } private void CreateScrollView() { if (!ShowIfNull()) { SetScrollViewAll(); } } private bool ShowIfNull() { if (mShowList.Count == 0) { FindObj("Nothing").SetActive(true); return true; } else { FindObj("Nothing").SetActive(false); return false; } } private void SetScrollViewAll() { if (null != mCurrentScrollViewContentObj) { Utils.CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj); } _mCurrentScrollView.SetUpdateFunc(RefreshItem); _mCurrentScrollView.SetItemCountFunc(GetCountFunc); _mCurrentScrollView.UpdateData(false); _mCurrentScrollView.SetButton(SetScrollviewItemButton); } private void SetScrollviewItemButton(GameObject obj) { for (int i = 0; i < 4; i++) { GameObject singleObj = Utils.CommonUtils.GetGameObject(obj, (i + 1).ToString()); if (singleObj != null) { ClearBind(Utils.CommonUtils.GetGameObject(singleObj, "Image_HeadPic")); BindButton(Utils.CommonUtils.GetGameObject(singleObj, "Image_HeadPic"), On2DPicClick, singleObj); } } } public class VehicleCultivateParam { public List showList; public VehicleCultivateData info; } private async void On2DPicClick(GameObject go) { VehicleCultivateData info = mUIHeadGoDic[go]; VehicleCultivateParam cultivateStruct = new VehicleCultivateParam(); cultivateStruct.showList = mShowList; cultivateStruct.info = info; await UIManager.Instance.OpenWindow(UINameConst.UI_VehicleCultivate, cultivateStruct); } private int GetCountFunc() { return mShowList.Count; } private void RefreshItem(int index, RectTransform item) { item.gameObject.SetActive(true); for (int i = 0; i < 4; i++) { GameObject singleItem = Utils.CommonUtils.GetGameObject(item.gameObject, (i + 1).ToString()); if (index * 4 + i < mShowList.Count) { singleItem.SetActive(true); VehicleCultivateData tempDataInfo = mShowList[index * 6 + i]; RefreshSingleItem(singleItem, tempDataInfo); mUIHeadGoDic[singleItem] = tempDataInfo; } else { singleItem.SetActive(false); } } } private void RefreshSingleItem(GameObject singleItem, VehicleCultivateData tempVehcile) { Utils.CommonUtils.GetComponent(singleItem, "Image_BlackDown/Text_Lv").text = tempVehcile.SumPowerLevel().ToString(); Utils.CommonUtils.GetComponent(singleItem, "Image_BlackDown/Text_Name").text = tempVehcile.Cfg.Name.ToString(); Image img = Utils.CommonUtils.GetComponent(singleItem, "Image_HeadPic"); string imgPath = Utils.CommonUtils.GetVehiclePicPath(tempVehcile.Cfg.ID); if (imgPath != null) { AssetManager.Instance.LoadAssetOnCallBack(imgPath, spr => { img.sprite = spr; img.gameObject.SetActive(true); }); } } private void RegisterEvent() { } //invoke when reload window protected override void OnReloadWindow(object data = null) { } void GetStorageData() { mCurVehicles.Clear(); mCurVehicles.AddRange(VehicleCultivateDataManager.Instance.DataList); } private void PreLoadAllVehicle() { for (int i = 0; i < mCurVehicles.Count; i++) { string strPath = Utils.CommonUtils.GetVehiclePicPath(mCurVehicles[i].Cfg.ID); AssetManager.Instance.PostPreload(strPath); } } }