388 lines
11 KiB
C#
388 lines
11 KiB
C#
using cfg.SkillCfg;
|
|
using cfg.VihecleCultivateCfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using PhxhSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Gameplay;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static UI_VehicleChooseController;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
public class UI_VehicleCultivateController : 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_LevelBarBG;
|
|
public Button Button_LevelPlus;
|
|
public TMP_Text Text_Level_Max;
|
|
public TMP_Text Text_LevelName;
|
|
public TMP_Text Text_Level_Now;
|
|
public Image Image_Property;
|
|
public TMP_Text Text_Property;
|
|
public Image Image_Hp;
|
|
public TMP_Text Text_Vehicle_Hp;
|
|
public TMP_Text Text_Hp_Value;
|
|
public Image Image_Defance;
|
|
public TMP_Text Text_Vehicle_Defance;
|
|
public TMP_Text Text_Defance_Value;
|
|
public Image Image_Capacity;
|
|
public TMP_Text Text_Vehicle_Capacity;
|
|
public TMP_Text Text_Capacity_Value;
|
|
public Image Image_PersonNum;
|
|
public TMP_Text Text_Vehicle_PersonNum;
|
|
public TMP_Text Text_PersonNum_Value;
|
|
public Image Image_Attack;
|
|
public TMP_Text Text_Vehicle_Attack;
|
|
public TMP_Text Text_Attack_Value;
|
|
public Image Image_Speed;
|
|
public TMP_Text Text_Vehicle_Speed;
|
|
public TMP_Text Text_Speed_Value;
|
|
public Image Image_Terrian;
|
|
public TMP_Text Text_Terrian;
|
|
public Image Image_Road;
|
|
public TMP_Text Text_RoadName;
|
|
public TMP_Text Text_Road_Value;
|
|
public Image Image_Snow;
|
|
public TMP_Text Text_SnowName;
|
|
public TMP_Text Text_Snow_Value;
|
|
public Image Image_Mountain;
|
|
public TMP_Text Text_MountainName;
|
|
public TMP_Text Text_Mountain_Value;
|
|
public Image Image_Forest;
|
|
public TMP_Text Text_ForestName;
|
|
public TMP_Text Text_Forest_Value;
|
|
public Image Image_ActiveSkill;
|
|
public Image Image_SkillLogo;
|
|
public Image Image_UI_SkillCd;
|
|
public TMP_Text Text_CDSecond;
|
|
public TMP_Text Text_CDTme;
|
|
public TMP_Text Text_ActiveSkill;
|
|
public TMP_Text Text_ActiveSkillName;
|
|
public TMP_Text Text_SkillInfo;
|
|
public TMP_Text Text_Class;
|
|
public TMP_Text Text_Class_Value;
|
|
public Image Image_VehicleLogo;
|
|
public TMP_Text Text_VehicleName;
|
|
|
|
///Auto Gen End///
|
|
private GameObject modelParent;
|
|
|
|
private VehicleCultivateData mVehicleData;
|
|
private GameObject showModel;
|
|
private GameObject viewModel = null;
|
|
List<GameObject> childGo;
|
|
RawImage rt;
|
|
ShowModelPreviewNode node;
|
|
private bool IsCanChange = false;
|
|
int mCurIndex = 0;//当前人物索引
|
|
List<VehicleCultivateData> vCDataList;
|
|
// Use this for initialization
|
|
public override void OnAwake()
|
|
{
|
|
//bind UI GameObj
|
|
UI_VehicleCultivateBinder.GetComponents(this);
|
|
rt = GetComponent<RawImage>("Image_BG/rt");
|
|
BindButton(Button_LevelPlus,OnLevelPlusClick);
|
|
BindButton(Button_Back, OnButton_BackClick);
|
|
BindButton(Button_Home, OnClickHome);
|
|
childGo = new List<GameObject>();
|
|
vCDataList = new List<VehicleCultivateData>();
|
|
|
|
}
|
|
private void OnClickHome()
|
|
{
|
|
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
|
|
}
|
|
|
|
|
|
private void RefreshModel()
|
|
{
|
|
CommonUtils.DestoryAllChildGameObject(modelParent);
|
|
viewModel=null;
|
|
viewModel = GameObject.Instantiate(showModel);
|
|
viewModel.transform.SetParent(modelParent.transform);
|
|
viewModel.transform.localPosition = new Vector3(-77, -309, -247);
|
|
viewModel.transform.localScale = new Vector3(330, 330, 330);
|
|
viewModel.transform.localRotation = new Quaternion(0, 139, 0, 1);
|
|
|
|
}
|
|
private void FindChild(GameObject child)
|
|
{
|
|
|
|
//利用for循环 获取物体下的全部子物体
|
|
for (int c = 0; c < child.transform.childCount; c++)
|
|
{
|
|
//如果子物体下还有子物体 就将子物体传入进行回调查找 直到物体没有子物体为止
|
|
if (child.transform.GetChild(c).childCount > 0)
|
|
{
|
|
FindChild(child.transform.GetChild(c).gameObject);
|
|
|
|
}
|
|
childGo.Add(child.transform.GetChild(c).gameObject);
|
|
|
|
|
|
}
|
|
}
|
|
private void OnButton_BackClick()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
private void RefreshPreviewNodeRawImage()
|
|
{
|
|
if (node!=null)
|
|
{
|
|
rt.texture = node.RTexture;
|
|
}
|
|
}
|
|
|
|
private async void OnLevelPlusClick()
|
|
{
|
|
CommonUtils.CaptureScreenshot();
|
|
await UIManager.Instance.OpenWindow(UINameConst.UI_VehicleLevelUp, mVehicleData);
|
|
ControllInput(false);
|
|
|
|
}
|
|
|
|
//invoke when open window
|
|
protected override async void OnOpenWindow(object data)
|
|
{
|
|
VehicleCultivateParam tempData=data as VehicleCultivateParam;
|
|
mVehicleData = tempData.info;
|
|
vCDataList = tempData.showList;
|
|
showModel= await LoadModel();
|
|
await CreateModelNode();
|
|
modelParent = node.contentObj;
|
|
RefreshModel();
|
|
RefreshLevel();
|
|
RefreshProperty();
|
|
RefreshTerrainAdapt();
|
|
RefreshVehicleAbout();
|
|
RefreshSkill();
|
|
RefreshPreviewNodeRawImage();
|
|
ControllInput(true);
|
|
|
|
RegisterEvent();
|
|
}
|
|
private async UniTask<GameObject> LoadModel()
|
|
{
|
|
return await AssetManager.Instance.LoadAssetAsync<GameObject>(TableManager.Instance.Tables.VehicleConfig.Get(mVehicleData.Cfg.ID).PrefabPath);
|
|
|
|
}
|
|
|
|
|
|
private void ControllInput(bool isRegister)
|
|
{
|
|
if (isRegister)
|
|
{
|
|
InputManager.Instance.OnFingerMoveUI += OnFingleSwipe;
|
|
|
|
}
|
|
else
|
|
{
|
|
InputManager.Instance.OnFingerMoveUI -= OnFingleSwipe;
|
|
|
|
}
|
|
}
|
|
float sumTime = 0;
|
|
|
|
void Update()
|
|
{
|
|
if (!IsCanChange)
|
|
{
|
|
sumTime += Time.deltaTime;
|
|
if (sumTime >= 1)
|
|
{
|
|
IsCanChange = true;
|
|
sumTime = 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void OnFingleSwipe(Vector2 delta)
|
|
{
|
|
if (!IsCanChange)
|
|
{
|
|
return;
|
|
}
|
|
if (delta.x > 25)
|
|
{
|
|
OnButton_RightArrowsClick();
|
|
IsCanChange = false;
|
|
}
|
|
else if (delta.x < -25)
|
|
{
|
|
OnButton_LeftArrowsClick();
|
|
IsCanChange = false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private async void OnButton_LeftArrowsClick()
|
|
{
|
|
int nowIndex = ReturnCorrectCharacterIndex(mCurIndex - 1);
|
|
mCurIndex = nowIndex;
|
|
RefreshCurCharacterDataInfo(mCurIndex);
|
|
|
|
await LoadModel();
|
|
RefreshModel();
|
|
|
|
RefreshLevel();
|
|
RefreshProperty();
|
|
RefreshTerrainAdapt();
|
|
RefreshVehicleAbout();
|
|
RefreshSkill();
|
|
ControllInput(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
private async UniTask CreateModelNode()
|
|
{
|
|
if (node == null)
|
|
{
|
|
node = new ShowModelPreviewNode();
|
|
await node.Show();
|
|
}
|
|
}
|
|
private async void OnButton_RightArrowsClick()
|
|
{
|
|
int nowIndex = ReturnCorrectCharacterIndex(mCurIndex + 1);
|
|
mCurIndex = nowIndex;
|
|
|
|
RefreshCurCharacterDataInfo(mCurIndex);
|
|
|
|
await LoadModel();
|
|
RefreshModel();
|
|
|
|
RefreshLevel();
|
|
RefreshProperty();
|
|
RefreshTerrainAdapt();
|
|
RefreshVehicleAbout();
|
|
RefreshSkill();
|
|
ControllInput(true);
|
|
|
|
}
|
|
void RefreshCurCharacterDataInfo(int index)
|
|
{
|
|
mVehicleData = vCDataList[index];
|
|
}
|
|
|
|
|
|
private int ReturnCorrectCharacterIndex(int index)
|
|
{
|
|
if (index < 0)
|
|
{
|
|
index = vCDataList.Count - 1;
|
|
}
|
|
if (index > vCDataList.Count - 1)
|
|
if (index > vCDataList.Count - 1)
|
|
{
|
|
index = 0;
|
|
}
|
|
return index;
|
|
}
|
|
private void RegisterEvent()
|
|
{
|
|
EventManager.Instance.Register(EventManager.EventName.VehecleUpgrade, OnVehecleUpgradeClick);
|
|
EventManager.Instance.Register(EventManager.EventName.EN_UIControllCultivateMainInput, (Action<bool>)OnRecvEventControlInput);
|
|
|
|
}
|
|
private void UnRegisterEvent()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.VehecleUpgrade, OnVehecleUpgradeClick);
|
|
EventManager.Instance.Unregister(EventManager.EventName.EN_UIControllCultivateMainInput, (Action<bool>)OnRecvEventControlInput);
|
|
|
|
|
|
}
|
|
private void OnRecvEventControlInput(bool isRegister)
|
|
{
|
|
ControllInput(isRegister);
|
|
}
|
|
private void OnVehecleUpgradeClick()
|
|
{
|
|
mVehicleData = VehicleCultivateDataManager.GetSingleton().GetVehicleCultivateData(mVehicleData.nID);
|
|
RefreshSkill();
|
|
RefreshLevel();
|
|
RefreshProperty();
|
|
RefreshTerrainAdapt();
|
|
}
|
|
private void RefreshSkill()
|
|
{
|
|
|
|
|
|
DataSkill nowSkillCfg = TableManager.Instance.Tables.SkillConfig.Get(VehicleDataHelper.GetVehicleSkillId(mVehicleData.Cfg.ID));
|
|
if(nowSkillCfg==null)
|
|
{
|
|
nowSkillCfg = TableManager.Instance.Tables.SkillConfig.DataList[0];
|
|
DebugUtil.LogError("skillConfig没有配置id为{0}", VehicleDataHelper.GetVehicleSkillId(mVehicleData.Cfg.ID));
|
|
}
|
|
|
|
Text_CDTme.text = nowSkillCfg.CDTime.ToString();
|
|
Text_ActiveSkillName.text = CommonUtils.GetLocalizeText(nowSkillCfg.Name);
|
|
|
|
AssetManager.Instance.LoadAssetOnCallBack<Sprite>(nowSkillCfg.IconPath, skillIcon =>
|
|
{
|
|
Image_SkillLogo.sprite = skillIcon;
|
|
});
|
|
|
|
Text_Class_Value.text = CommonUtils.GetRomanCode((int)mVehicleData.SumBonus(BonusType.SkillLv));
|
|
|
|
Text_SkillInfo.text =CommonUtils.GetLocalizeText( nowSkillCfg.SkillDesc);
|
|
}
|
|
|
|
private void RefreshLevel()
|
|
{
|
|
Text_Level_Max.text = mVehicleData.SumPowerMaxLevel().ToString();
|
|
Text_Level_Now.text = mVehicleData.SumPowerLevel().ToString();
|
|
|
|
}
|
|
private void RefreshVehicleAbout()
|
|
{
|
|
Text_VehicleName.text = mVehicleData.Cfg.Name;
|
|
|
|
}
|
|
private void RefreshProperty()
|
|
{
|
|
Text_Hp_Value.text = mVehicleData.Hp().ToString();
|
|
Text_PersonNum_Value.text=mVehicleData.SeatCount().ToString();
|
|
Text_Defance_Value.text = mVehicleData.Defense().ToString();
|
|
Text_Speed_Value.text = mVehicleData.MoveSpeed().ToString();
|
|
Text_Attack_Value.text = mVehicleData.Attack().ToString();
|
|
Text_Capacity_Value.text = mVehicleData.BulletCapacity().ToString();
|
|
}
|
|
private void RefreshTerrainAdapt()
|
|
{
|
|
Text_Road_Value.text = mVehicleData.GetTerrainAdapt(BonusType.TerrainPlain);
|
|
Text_Snow_Value.text = mVehicleData.GetTerrainAdapt(BonusType.TerrainSnow);
|
|
Text_Mountain_Value.text = mVehicleData.GetTerrainAdapt(BonusType.TerrainMountain);
|
|
Text_Forest_Value.text = mVehicleData.GetTerrainAdapt(BonusType.TerrainForest);
|
|
}
|
|
//invoke when reload windowq
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when close window
|
|
protected override void OnCloseWindow()
|
|
{
|
|
node.Destroy();
|
|
node = null;
|
|
|
|
UnRegisterEvent();
|
|
}
|
|
} |