/// <summary> /// 点击-升级 /// </summary> public void OnClickForLevel() { UserDataBean userData = uiComponent.handler_GameData.GetUserData(); UserModelPartDataBean userModelPartData = userModelData.GetUserPartDataById(modelPartInfo.id); if (userModelPartData == null) { return; } long levelMoney = modelPartInfo.GetLevelUpMoney(userModelPartData.level); bool isPay = userData.PayMoney(levelMoney); if (isPay) { //升级 int level = userModelPartData.LevelUp(1); //计算收益 long addPrice = modelPartInfo.GetAddPrice(level); //增加收益 userModelPartData.SetAddPrice(addPrice); //设置舰船显示进度 uiComponent.handler_GameModel.SetPartProgress(modelPartInfo.part_name, userModelPartData.GetProgress(modelPartInfo.max_level)); } else { LogUtil.Log("升级失败,没有足够的金钱"); } }
public void SetData(UserModelDataBean userModelData, ModelInfoBean modelInfo) { if (modelInfo == null) { return; } if (userModelData == null) { return; } dissolveAmountId = Shader.PropertyToID(m_DissolveAmount); mapMaterialForModel.Clear(); Texture textureDisolveGuide = Resources.Load("Texture/noise_1") as Texture; if (!CheckUtil.ListIsNull(modelInfo.listPartData)) { for (int i = 0; i < modelInfo.listPartData.Count; i++) { ModelPartInfoBean partInfo = modelInfo.listPartData[i]; Renderer itemRenderer = CptUtil.GetCptInChildrenByName <Renderer>(gameObject, partInfo.part_name); //获取所有的Material List <Material> listMaterial = new List <Material>(); itemRenderer.GetMaterials(listMaterial); //获取用户进度 UserModelPartDataBean userModelPartData = userModelData.GetUserPartDataById(partInfo.id); float pro = 0; if (userModelPartData != null) { pro = userModelPartData.GetProgress(partInfo.max_level); } //重新设置所有的shader foreach (Material itemMaterial in listMaterial) { Texture itemTexture = itemMaterial.GetTexture("_MainTex"); if (itemTexture) { itemMaterial.shader = Shader.Find("ASESampleShaders/Community/DissolveBurnWithFire"); itemMaterial.SetTexture("_Albedo", itemTexture); itemMaterial.SetTexture("_Normal", itemTexture); itemMaterial.SetTexture("_BurnRamp", itemTexture); itemMaterial.SetFloat("_MaskClipValue", 0.5f); } else { Color color = itemMaterial.GetColor("_Color"); itemMaterial.shader = Shader.Find("ASESampleShaders/Community/DissolveBurn_01"); itemMaterial.SetFloat("_Cutoff", 0.5f); itemMaterial.SetColor("_MainColor", color); } itemMaterial.SetTexture("_DisolveGuide", textureDisolveGuide); itemMaterial.SetFloat(dissolveAmountId, 1 - pro); } if (!mapMaterialForModel.ContainsKey(partInfo.part_name)) { mapMaterialForModel.Add(partInfo.part_name, listMaterial); } } } }
/// <summary> /// 检测是否有模型 /// </summary> /// <param name="modelId"></param> /// <returns></returns> public bool CheckHasPart(long partId, long addPrice, out UserModelPartDataBean partDataBean) { partDataBean = null; for (int i = 0; i < listUnlockPart.Count; i++) { UserModelPartDataBean itemPartData = listUnlockPart[i]; if (partId == itemPartData.partId) { partDataBean = itemPartData; partDataBean.addPrice = addPrice; return(true); } } return(false); }
/// <summary> /// 点击解锁 /// </summary> public void OnClickForUnlock() { UserDataBean userData = uiComponent.handler_GameData.GetUserData(); bool isPay = userData.PayMoney(modelPartInfo.unlock_money); if (isPay) { //添加解锁数据 UserModelPartDataBean userModelPartData = userModelData.AddUnLockPart(modelPartInfo.id, modelPartInfo.GetAddPrice(0)); //设置显示部件 } else { LogUtil.Log("解锁失败,没有足够的金钱"); } }
/// <summary> /// 升级部件 /// </summary> /// <param name="partId"></param> /// <param name="addLevel"></param> public void LevelUpPart(long partId, int addLevel) { if (listUnlockPart == null) { return; } for (int i = 0; i < listUnlockPart.Count; i++) { UserModelPartDataBean itemPartData = listUnlockPart[i]; if (partId == itemPartData.partId) { itemPartData.LevelUp(addLevel); return; } } }
/// <summary> /// 通过部件ID获取数据 /// </summary> /// <param name="partId"></param> /// <returns></returns> public UserModelPartDataBean GetUserPartDataById(long partId) { if (listUnlockPart == null) { return(null); } for (int i = 0; i < listUnlockPart.Count; i++) { UserModelPartDataBean itemPartData = listUnlockPart[i]; if (partId == itemPartData.partId) { return(itemPartData); } } return(null); }
/// <summary> /// 增加已解锁模型 /// </summary> /// <param name="modelId"></param> public UserModelPartDataBean AddUnLockPart(long partId, long addPrice) { if (listUnlockPart == null) { listUnlockPart = new List <UserModelPartDataBean>(); } bool hasData = CheckHasPart(partId, addPrice, out UserModelPartDataBean partDataBean); if (hasData) { return(partDataBean); } else { UserModelPartDataBean modelData = new UserModelPartDataBean(partId, addPrice); listUnlockPart.Add(modelData); return(modelData); } }
public IEnumerator CoroutineForGameDataChange() { while (gameObject) { yield return(new WaitForSeconds(1)); UserDataBean userData = GetUserData(); if (!CheckUtil.ListIsNull(userData.listUnlockModel)) { for (int i = 0; i < userData.listUnlockModel.Count; i++) { UserModelDataBean itemModelData = userData.listUnlockModel[i]; if (!CheckUtil.ListIsNull(itemModelData.listUnlockPart)) { for (int f = 0; f < itemModelData.listUnlockPart.Count; f++) { UserModelPartDataBean itemModelPartData = itemModelData.listUnlockPart[f]; userData.AddUserMoney(itemModelPartData.addPrice); } } } } } }