中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

網(wǎng)站建設(shè)宗旨是什么口碑營(yíng)銷公司

網(wǎng)站建設(shè)宗旨是什么,口碑營(yíng)銷公司,成都網(wǎng)絡(luò)優(yōu)化公司排行榜,做網(wǎng)站用什么軟件?【Unity教程】從0編程制作類銀河惡魔城游戲_嗶哩嗶哩_bilibili 教程源地址:https://www.udemy.com/course/2d-rpg-alexdev/ 本章節(jié)實(shí)現(xiàn)了玩家屬性欄,倉(cāng)庫(kù),物品欄UI的制作 UI_StatSlot.cs 這個(gè)腳本是用來在Unity的UI上顯示玩家屬性&#xf…

【Unity教程】從0編程制作類銀河惡魔城游戲_嗶哩嗶哩_bilibili

教程源地址:https://www.udemy.com/course/2d-rpg-alexdev/

本章節(jié)實(shí)現(xiàn)了玩家屬性欄,倉(cāng)庫(kù),物品欄UI的制作

UI_StatSlot.cs

這個(gè)腳本是用來在Unity的UI上顯示玩家屬性(比如生命值或攻擊力)的。

  1. 顯示狀態(tài)名稱statName用來存儲(chǔ)屬性名稱,比如"Health"。在編輯器中修改這個(gè)名字時(shí),它會(huì)自動(dòng)顯示在對(duì)應(yīng)的UI文本框里。
  2. 顯示狀態(tài)值statValueText是用來顯示這個(gè)屬性的數(shù)值(比如100生命值)。
  3. 初始化UIStart方法會(huì)在游戲開始時(shí)更新UI,確保顯示玩家的正確狀態(tài)。
  4. 動(dòng)態(tài)更新UpdateStatValueUI方法可以隨時(shí)調(diào)用,更新UI上顯示的數(shù)值。它會(huì)通過PlayerManager找到玩家的屬性,然后把這個(gè)值顯示在UI上。
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;public class UI_StatSlot : MonoBehaviour
{[SerializeField] private string statName;[SerializeField] private StatType statType;[SerializeField] private TextMeshProUGUI statValueText;[SerializeField] private TextMeshProUGUI statNameText;private void OnValidate(){gameObject.name = "Stat - "+ statName;if(statNameText != null)statNameText.text = statName;}void Start(){UpdateStatValueUI();}public void UpdateStatValueUI(){PlayerStats playerStats = PlayerManager.instance.player.GetComponent<PlayerStats>();if(playerStats !=null){statValueText.text = playerStats.GetStat(statType).GetValue().ToString();}}
}

CharacterStats.cs

把狀態(tài)類型移動(dòng)到這個(gè)腳本

using System.Collections;
using UnityEngine;public enum StatType//枚舉 StatType 的定義
{strength,agility,intelligence,vitality,damage,critChance,critPower,health,armor,evasion,magicRes,fireDamage,iceDamage,lightingDamage
}//10月25日
//10月26日
public class CharacterStats : MonoBehaviour
{private EntityFX fx;[Header("主屬性")]public Stat strength;//力量,1點(diǎn)增加1攻擊力和%1爆傷public Stat agility;//敏捷,1點(diǎn)增加1%閃避和%1暴擊率public Stat intelligence;//智力,1點(diǎn)增加1法術(shù)強(qiáng)度和%1魔抗public Stat vitality;//活力,1點(diǎn)增加3生命值[Header("攻擊屬性")]//offensive statspublic Stat damage;public Stat critChance;//暴擊率public Stat critPower;//暴擊傷害,默認(rèn)%150[Header("防守屬性")]//defensive statspublic Stat maxHealth;public Stat armor;//護(hù)甲public Stat evasion;//閃避public Stat magicResistance;//魔抗[Header("魔法屬性")]//magic statspublic Stat fireDamage;public Stat iceDamage;public Stat lightningDamage;public bool isIgnited;//是否燃燒,持續(xù)傷害public bool isChilled;//是否凍結(jié),削弱護(hù)甲20%public bool isShocked;//是否感電,減少命中率20%[SerializeField] private float ailmentsDuration = 4;//異常狀態(tài)持續(xù)時(shí)間private float ignitedTimer;private float chilledTimer;private float shockedTimer;private float igniteDamageCoolDown = .3f;//燃燒傷害間隔時(shí)間private float igniteDamageTimer;//燃燒傷害計(jì)時(shí)器private int igniteDamage;//燃燒傷害[SerializeField] private GameObject shockStrikePrefab;private int shockDamage;public int currentHealth;public System.Action onHealthChanged;public bool isDead { get; private set; }protected virtual void Start(){critPower.SetDefaultValue(150);//暴擊傷害默認(rèn)150%currentHealth = GetMaxHealthValue();//一開始血條滿的fx = GetComponent<EntityFX>();}protected virtual void Update(){ignitedTimer -= Time.deltaTime;//燃燒時(shí)間減少chilledTimer -= Time.deltaTime;shockedTimer -= Time.deltaTime;igniteDamageTimer -= Time.deltaTime;//燃燒傷害計(jì)時(shí)器減少if (ignitedTimer < 0)isIgnited = false;if (chilledTimer < 0)isChilled = false;if (shockedTimer < 0)isShocked = false;if (isIgnited)ApplyIgniteDamage();}public virtual void IncreaseStatBy(int _modifier, float _duration, Stat _statToModify){StartCoroutine(StatModCoruntine(_modifier, _duration, _statToModify));}private IEnumerator StatModCoruntine(int _modifier, float _duration, Stat _statToModify)//加buff的協(xié)程{_statToModify.AddModifier(_modifier);//添加一個(gè)buffyield return new WaitForSeconds(_duration);_statToModify.RemoveModifier(_modifier);//移除一個(gè)buff}public virtual void DoDamage(CharacterStats _targetStats)//只是一次物理攻擊{if (TargetCanAvoidAttack(_targetStats))return;int totalDamage = damage.GetValue() + strength.GetValue();if (Cancrit()){//Debug.Log("Crit Hit");totalDamage = CalculateCriticalDamage(totalDamage);//Debug.Log(" 總的暴擊傷害是"+ totalDamage);//Total crit damage is}totalDamage = CheckTargetArmor(_targetStats, totalDamage);_targetStats.TakeDamage(totalDamage);//把造成的給到繼承CharacterStats的類DoMagicDamage(_targetStats);//如果普通攻擊不想要魔法傷害移除}#region Magic Damage and ailmentspublic virtual void DoMagicDamage(CharacterStats _targetStats)//只是一次魔法攻擊{int _fireDamage = fireDamage.GetValue();int _iceDamage = iceDamage.GetValue();int _lightningDamage = lightningDamage.GetValue();int totalMagicalDamage = _fireDamage + _iceDamage + _lightningDamage + intelligence.GetValue();totalMagicalDamage = CheckTargetResistance(_targetStats, totalMagicalDamage);_targetStats.TakeDamage(totalMagicalDamage);//把造成的給到繼承CharacterStats的類//importantif (Mathf.Max(_fireDamage, _iceDamage, _lightningDamage) <= 0)//可以保證下面的while循環(huán)不會(huì)無限循環(huán)return;AttempToApplyAilements(_targetStats, _fireDamage, _iceDamage, _lightningDamage);}private void AttempToApplyAilements(CharacterStats _targetStats, int _fireDamage, int _iceDamage, int _lightningDamage){//判斷魔法傷害類型bool canApplyIgnite = _fireDamage > _iceDamage && _fireDamage > _lightningDamage;bool canApplyChill = _iceDamage > _fireDamage && _iceDamage > _lightningDamage;bool canApplyShock = _lightningDamage > _fireDamage && _lightningDamage > _iceDamage;while (!canApplyIgnite && !canApplyChill && !canApplyShock){//三個(gè)if同時(shí)判斷大小,可以完成一個(gè)隨機(jī)屬性傷害的bossif (Random.value < .33f && _fireDamage > 0)//Random.value用于生成一個(gè)介于 0.0 和 1.0 之間的隨機(jī)浮點(diǎn)數(shù){canApplyIgnite = true;_targetStats.ApplyAilments(canApplyIgnite, canApplyChill, canApplyShock);//Debug.Log("ignited" );return;}if (Random.value < .5f && _lightningDamage > 0){canApplyShock = true;_targetStats.ApplyAilments(canApplyIgnite, canApplyChill, canApplyShock);//Debug.Log("shocked" );return;}if (Random.value < .99f && _iceDamage > 0){canApplyChill = true;_targetStats.ApplyAilments(canApplyIgnite, canApplyChill, canApplyShock);//Debug.Log("iced" );return;}}if (canApplyIgnite){_targetStats.SetupIgniteDamage(Mathf.RoundToInt(_fireDamage * .2f));}if (canApplyShock){_targetStats.SetupShockDamage(Mathf.RoundToInt(_lightningDamage * .1f));}_targetStats.ApplyAilments(canApplyIgnite, canApplyChill, canApplyShock);}public void ApplyAilments(bool _ignite, bool _chill, bool _shock)//應(yīng)用異常狀態(tài){bool canApplyIgnite = !isIgnited && !isChilled && !isShocked;bool canApplyChill = !isIgnited && !isChilled && !isShocked;bool canApplyShock = !isIgnited && !isChilled;//沒有其他異常狀態(tài)才能進(jìn)入一個(gè)異常狀態(tài)//if (isIgnited || isChilled || isShocked)//如果進(jìn)入一個(gè)異常狀態(tài)就不能進(jìn)入其他狀態(tài)了//    return;if (_ignite && canApplyIgnite){isIgnited = _ignite;ignitedTimer = ailmentsDuration;fx.IgniteFxFor(ailmentsDuration);}if (_chill && canApplyChill){isChilled = _chill;chilledTimer = ailmentsDuration;float slowPercentage = .2f;//減速百分比GetComponent<Entity>().SlowEntityBy(slowPercentage, ailmentsDuration);//減速20%fx.ChillFxFor(ailmentsDuration);}if (_shock && canApplyShock){if (!isShocked){ApplyShock(_shock);}else{if (GetComponent<Player>() != null)//防止敵人打玩家自己被電return;HitNearsetTargerWithShockStrike();}}}public void ApplyShock(bool _shock){if (isShocked)//已經(jīng)進(jìn)入感電就不如再次進(jìn)入return;isShocked = _shock;shockedTimer = ailmentsDuration;fx.ShockFxFor(ailmentsDuration);}private void HitNearsetTargerWithShockStrike(){Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 25);//碰撞體檢測(cè)周圍的敵人float closestDistance = Mathf.Infinity;Transform closestEnemy = null;foreach (var hit in colliders){if (hit.GetComponent<Enemy>() != null && Vector2.Distance(transform.position, hit.transform.position) > 1)//如果是敵人并且不是自己,防止自己被電{float distanceToEnemy = Vector2.Distance(transform.position, hit.transform.position);if (distanceToEnemy < closestDistance){closestDistance = distanceToEnemy;closestEnemy = hit.transform;}}if (closestEnemy == null)closestEnemy = transform;}//尋找最近的敵人然后雷擊if (closestEnemy != null){GameObject newShockStrike = Instantiate(shockStrikePrefab, transform.position, Quaternion.identity);newShockStrike.GetComponent<ShockStrike_Controller>().Setup(shockDamage, closestEnemy.GetComponent<CharacterStats>());}}//閃電攻擊附近的目標(biāo)private void ApplyIgniteDamage(){if (igniteDamageTimer < 0){DecreaseHealthBy(igniteDamage);//currentHealth -= igniteDamage;if (currentHealth < 0 && !isDead)Die();igniteDamageTimer = igniteDamageCoolDown;}}public void SetupIgniteDamage(int _damage) => igniteDamage = _damage;//設(shè)置燃燒傷害public void SetupShockDamage(int _damage) => shockDamage = _damage;//設(shè)置感電傷害#endregionpublic virtual void TakeDamage(int _damage)//造成傷害函數(shù),返回傷害值{DecreaseHealthBy(_damage);GetComponent<Entity>().DamageImpact();fx.StartCoroutine("FlashFX");Debug.Log(_damage);if (currentHealth < 0 && !isDead)Die();//人被殺就會(huì)死}public virtual void IncreaseHealthBy(int _amount)//加血函數(shù){currentHealth += _amount;if (currentHealth > GetMaxHealthValue())currentHealth = GetMaxHealthValue();if (onHealthChanged != null)onHealthChanged();}protected virtual void DecreaseHealthBy(int _damage)//受到傷害的數(shù)值變化{currentHealth -= _damage;if (onHealthChanged != null)onHealthChanged();}protected virtual void Die(){isDead = true;}#region Stat calculationsprivate int CheckTargetResistance(CharacterStats _targetStats, int totalMagicalDamage)//計(jì)算魔法傷害(魔抗{totalMagicalDamage -= _targetStats.magicResistance.GetValue() + (_targetStats.intelligence.GetValue() * 3);//減去魔抗值totalMagicalDamage = Mathf.Clamp(totalMagicalDamage, 0, int.MaxValue);//Clamp限制血量數(shù)值return totalMagicalDamage;}private int CheckTargetArmor(CharacterStats _targetStats, int totalDamage)//計(jì)算物理傷害(護(hù)甲{if (_targetStats.isChilled)totalDamage -= Mathf.RoundToInt(_targetStats.armor.GetValue() * .8f);//減去對(duì)方的護(hù)甲值elsetotalDamage -= _targetStats.armor.GetValue();//減去對(duì)方的護(hù)甲值totalDamage = Mathf.Clamp(totalDamage, 0, int.MaxValue);//最小值是0,最大值是int.MaxValue,防止別人打我加血return totalDamage;}private bool TargetCanAvoidAttack(CharacterStats _targetStats)//檢測(cè)閃避{int totalEvasion = _targetStats.evasion.GetValue() + _targetStats.agility.GetValue();//總的閃避率if (isShocked)totalEvasion += 20;if (Random.Range(0, 100) < totalEvasion){Debug.Log("Attack Avoided");return true;}return false;}private bool Cancrit()//暴擊檢測(cè){int totalCritChance = critChance.GetValue() + agility.GetValue();//總的暴擊率if (Random.Range(0, 100) < totalCritChance){return true;}return false;}private int CalculateCriticalDamage(int _damage)//計(jì)算爆傷{float totalCritPower = (critPower.GetValue() + strength.GetValue()) * .01f;//Debug.Log("總的暴擊率: " + totalCritPower);//total crit powerfloat critDamage = _damage * totalCritPower;//Debug.Log("取整之后的爆傷" + critDamage);//crit damage before round upreturn Mathf.RoundToInt(critDamage);}public int GetMaxHealthValue(){return maxHealth.GetValue() + vitality.GetValue() * 5;}//獲取最大生命值#endregionpublic Stat GetStat(StatType _statType)//根據(jù) buffType 返回需要修改的屬性{if (_statType == StatType.strength) return strength;else if (_statType == StatType.agility) return agility;else if (_statType == StatType.intelligence) return intelligence;else if (_statType == StatType.vitality) return vitality;else if (_statType == StatType.damage) return damage;else if (_statType == StatType.critChance) return critChance;else if (_statType == StatType.critPower) return critPower;else if (_statType == StatType.health) return maxHealth;else if (_statType == StatType.armor) return armor;else if (_statType == StatType.evasion) return evasion;else if (_statType == StatType.magicRes) return magicResistance;else if (_statType == StatType.fireDamage) return fireDamage;else if (_statType == StatType.iceDamage) return iceDamage;else if (_statType == StatType.lightingDamage) return lightningDamage;else return null;}
}

Buff_Effect.cs

using UnityEngine;//2024年11月11日[CreateAssetMenu(fileName = "Buff Effect", menuName = "Data/Item effect/Buff effect")]
public class Buff_Effect : ItemEffect
{private PlayerStats stats;[SerializeField] private StatType buffType;// Buff 的類型[SerializeField] private int buffAmount; // Buff 的增加量[SerializeField] private float buffDuration;// Buff 持續(xù)時(shí)間public override void ExcuteEffect(Transform _enemyPositon){stats = PlayerManager.instance.player.GetComponent<PlayerStats>();//相當(dāng)于獲得了CharacterStats的引用stats.IncreaseStatBy(buffAmount, buffDuration, stats.GetStat(buffType));}
}

Inventory.cs

更新部分

      [SerializeField] private Transform statSlotParent;private UI_StatSlot[] statSlot;private void Start()//初始實(shí)例化{inventoryItems = new List<InventoryItem>();inventoryDictionary = new Dictionary<ItemData, InventoryItem>();stash = new List<InventoryItem>();stashDictionary = new Dictionary<ItemData, InventoryItem>();equipment = new List<InventoryItem>();equipmentDictionary = new Dictionary<ItemData_Equipment, InventoryItem>();//同時(shí)獲取UI中對(duì)應(yīng)的物品槽//獲得起始的腳本inventoryItemSlot = inventorySlotParent.GetComponentsInChildren<UI_ItemSlot>();stashItemSlot = stashSlotParent.GetComponentsInChildren<UI_ItemSlot>();equipmentSlot = equipmentSlotParent.GetComponentsInChildren<UI_EquipmentSlot>();statSlot = statSlotParent.GetComponentsInChildren<UI_StatSlot>();AddStartingItems();}
using System.Collections.Generic;
using UnityEngine;//放在創(chuàng)建倉(cāng)庫(kù)的empyty對(duì)象上,就是倉(cāng)庫(kù)的運(yùn)行函數(shù)
public class Inventory : MonoBehaviour
{public static Inventory instance;//單例模式public List<ItemData> startingItems;//初始裝備//兩種關(guān)鍵的存貯結(jié)構(gòu)//List:存儲(chǔ)玩家的裝備、倉(cāng)庫(kù)物品、儲(chǔ)藏室物品等//Dictionary:存儲(chǔ)每個(gè)物品的數(shù)據(jù)以及物品在倉(cāng)庫(kù)中的具體信息,例如物品的堆疊數(shù)量public List<InventoryItem> equipment;public Dictionary<ItemData_Equipment, InventoryItem> equipmentDictionary;public List<InventoryItem> inventoryItems;public Dictionary<ItemData, InventoryItem> inventoryDictionary;public List<InventoryItem> stash;public Dictionary<ItemData, InventoryItem> stashDictionary;//UI物品槽管理:通過以下代碼將游戲中的物品槽和UI界面上的物品槽關(guān)聯(lián)起來[Header("倉(cāng)庫(kù)UI")]//Inventory UI[SerializeField] private Transform inventorySlotParent;//位置[SerializeField] private Transform stashSlotParent;[SerializeField] private Transform equipmentSlotParent;[SerializeField] private Transform statSlotParent;//物品和材料的存貯位置分開private UI_ItemSlot[] inventoryItemSlot;private UI_ItemSlot[] stashItemSlot;//儲(chǔ)藏室private UI_EquipmentSlot[] equipmentSlot;//裝備private UI_StatSlot[] statSlot;[Header("物品冷卻")]private float lastTimeUsedFlask;private float lastTimeUsedArmor;//P122解決一開始不能用物品的問題,因?yàn)橐婚_始冷卻被賦值,使用了currentFlask.itemCoolDownprivate float flaskCoolDown;private float armorCoolDown;private void Awake(){if (instance == null)instance = this;elseDestroy(gameObject);//防止從一個(gè)地方到另一個(gè)地方}private void Start()//初始實(shí)例化{inventoryItems = new List<InventoryItem>();inventoryDictionary = new Dictionary<ItemData, InventoryItem>();stash = new List<InventoryItem>();stashDictionary = new Dictionary<ItemData, InventoryItem>();equipment = new List<InventoryItem>();equipmentDictionary = new Dictionary<ItemData_Equipment, InventoryItem>();//同時(shí)獲取UI中對(duì)應(yīng)的物品槽//獲得起始的腳本inventoryItemSlot = inventorySlotParent.GetComponentsInChildren<UI_ItemSlot>();stashItemSlot = stashSlotParent.GetComponentsInChildren<UI_ItemSlot>();equipmentSlot = equipmentSlotParent.GetComponentsInChildren<UI_EquipmentSlot>();statSlot = statSlotParent.GetComponentsInChildren<UI_StatSlot>();AddStartingItems();}private void AddStartingItems()//添加初始物品{for (int i = 0; i < startingItems.Count; i++){AddItem(startingItems[i]);}}public void EquipItem(ItemData _item)//把一個(gè)物品裝備到角色身上{ItemData_Equipment newEquipment = _item as ItemData_Equipment;//把 _item 對(duì)象轉(zhuǎn)換為 ItemData_Equipment 類型,表示它是一個(gè)裝備物品InventoryItem newItem = new InventoryItem(newEquipment); //把 ItemData 對(duì)象轉(zhuǎn)換為 InventoryItem 對(duì)象ItemData_Equipment oldEquipment = null;//要?jiǎng)h除的物品foreach (KeyValuePair<ItemData_Equipment, InventoryItem> item in equipmentDictionary)//遍歷裝備字典{if (item.Key.equipmentType == newEquipment.equipmentType)//如果裝備類型相同oldEquipment = item.Key;//刪除該裝備}if (oldEquipment != null){UnequipItem(oldEquipment);AddItem(oldEquipment);//把要?jiǎng)h除的物品放回倉(cāng)庫(kù)}equipment.Add(newItem);equipmentDictionary.Add(newEquipment, newItem);newEquipment.AddModifiers();//添加裝備屬性RemoveItem(_item);UpdataSlotsUI();}public void UnequipItem(ItemData_Equipment itemToRemove)//移除裝備函數(shù){if (equipmentDictionary.TryGetValue(itemToRemove, out InventoryItem value)){equipment.Remove(value);equipmentDictionary.Remove(itemToRemove);itemToRemove.RemoveModifiers();}}private void UpdataSlotsUI()//更新UI物體的數(shù)量{// 更新裝備槽for (int i = 0; i < equipmentSlot.Length; i++)//將裝備物品槽與一個(gè)裝備字典中的物品進(jìn)行匹配,并根據(jù)匹配結(jié)果更新物品槽的內(nèi)容{foreach (KeyValuePair<ItemData_Equipment, InventoryItem> item in equipmentDictionary)//遍歷裝備字典{if (item.Key.equipmentType == equipmentSlot[i].slotType)//這個(gè)條件用于確保物品能放入正確的槽位中equipmentSlot[i].UpdataSlot(item.Value);}}// 清空并更新倉(cāng)庫(kù)和儲(chǔ)藏室的物品槽for (int i = 0; i < inventoryItemSlot.Length; i++)//倉(cāng)庫(kù)物品槽{inventoryItemSlot[i].CleanUpSlot();}for (int i = 0; i < stashItemSlot.Length; i++)//儲(chǔ)藏室中的物品槽{stashItemSlot[i].CleanUpSlot();}// 重新填充倉(cāng)庫(kù)和儲(chǔ)藏室for (int i = 0; i < inventoryItems.Count; i++){inventoryItemSlot[i].UpdataSlot(inventoryItems[i]);}for (int i = 0; i < stash.Count; i++){stashItemSlot[i].UpdataSlot(stash[i]);}//更新屬性槽for (int i = 0; i < statSlot.Length; i++){statSlot[i].UpdateStatValueUI();}}public void AddItem(ItemData _item)//據(jù)物品類型,將物品添加到倉(cāng)庫(kù)(inventory)或者儲(chǔ)藏室(stash){if (_item.itemType == ItemType.Equipment){AddToInventory(_item);}else if (_item.itemType == ItemType.Material){AddToStash(_item);}UpdataSlotsUI();}private void AddToStash(ItemData _item){if (stashDictionary.TryGetValue(_item, out InventoryItem value)){value.AddStack();}else{InventoryItem newItem = new InventoryItem(_item);stash.Add(newItem);stashDictionary.Add(_item, newItem);}}private void AddToInventory(ItemData _item){if (inventoryDictionary.TryGetValue(_item, out InventoryItem value))//字典中檢查倉(cāng)庫(kù)中是否有這個(gè)物品,具體查找的是ItemData,out InventoryItem value如果找,返回與該鍵相關(guān)聯(lián)的值{value.AddStack();//如果物品已經(jīng)存在于庫(kù)存中,則增加其堆疊數(shù)量}else{InventoryItem newItem = new InventoryItem(_item);//如果物品不存在,則創(chuàng)建一個(gè)新的 InventoryIteminventoryItems.Add(newItem);inventoryDictionary.Add(_item, newItem);}}//檢查物品是否已經(jīng)在倉(cāng)庫(kù)里,如果存在則增加堆疊數(shù)量,如果不存在則創(chuàng)建新的物品對(duì)象并加入倉(cāng)庫(kù)public void RemoveItem(ItemData _item){if (inventoryDictionary.TryGetValue(_item, out InventoryItem value)){if (value.stackSize <= 1){inventoryItems.Remove(value);inventoryDictionary.Remove(_item);}else{value.RemoveStack();}}if (stashDictionary.TryGetValue(_item, out InventoryItem stashValue)){if (stashValue.stackSize <= 1)//如果物品的堆疊數(shù)量小于等于1,則從庫(kù)存中刪除該物品{stash.Remove(stashValue);stashDictionary.Remove(_item);}else{stashValue.RemoveStack();//否則就減少堆寨數(shù)量}}UpdataSlotsUI();}public bool CanCraft(ItemData_Equipment _itemToCraft, List<InventoryItem> _requiredMaterials)//判斷是否可以合成的函數(shù){List<InventoryItem> materialsToRemove = new List<InventoryItem>();for (int i = 0; i < _requiredMaterials.Count; i++){if (stashDictionary.TryGetValue(_requiredMaterials[i].data, out InventoryItem stashValue))//如果儲(chǔ)藏室中沒有所需材料{if (stashValue.stackSize < _requiredMaterials[i].stackSize)//數(shù)量是否足夠{Debug.Log("沒有足夠的材料");return false;}else{materialsToRemove.Add(stashValue);}}else{Debug.Log("沒有足夠的材料");return false;}}for (int i = 0; i < materialsToRemove.Count; i++)//使用了就從臨時(shí)倉(cāng)庫(kù)中移除{RemoveItem(materialsToRemove[i].data);}AddItem(_itemToCraft);Debug.Log("這里是你的物品" + _itemToCraft.name);return true;}public List<InventoryItem> GetEquipmentList() => equipment;//獲取裝備列表public List<InventoryItem> GetStashList() => stash;//獲取倉(cāng)庫(kù)列表public ItemData_Equipment GetEquipment(EquipmentType _type)//獲取裝備{ItemData_Equipment equipedItem = null;foreach (KeyValuePair<ItemData_Equipment, InventoryItem> item in equipmentDictionary)//遍歷裝備字典{if (item.Key.equipmentType == _type)//如果裝備類型相同equipedItem = item.Key;//刪除該裝備}return equipedItem;}public void UseFlask()//使用藥水的函數(shù){ItemData_Equipment currentFlask = GetEquipment(EquipmentType.Flask);//獲取當(dāng)前的藥水if (currentFlask == null)return;bool canUseFlask = Time.time > lastTimeUsedFlask + flaskCoolDown;//判斷是否可以使用藥水if (canUseFlask){flaskCoolDown = currentFlask.itemCoolDown;//重置冷卻時(shí)間,一開始就可以使用物品currentFlask.Effect(null);lastTimeUsedFlask = Time.time;}elseDebug.Log("藥水冷卻中");}public bool CanUseArmor(){ItemData_Equipment currentArmor = GetEquipment(EquipmentType.Armor);//獲取當(dāng)前裝備的護(hù)甲信息。if (Time.time > lastTimeUsedArmor + armorCoolDown){//更新冷卻時(shí)間和使用時(shí)間armorCoolDown = currentArmor.itemCoolDown;lastTimeUsedArmor = Time.time;return true;}Debug.Log("護(hù)甲正在冷卻中");return false;}//private void Updata()//{//    Debug.Log(Time.time);//}
}

http://www.risenshineclean.com/news/51544.html

相關(guān)文章:

  • 科技公司企業(yè)網(wǎng)站建設(shè)做一個(gè)企業(yè)網(wǎng)站大概需要多少錢
  • 營(yíng)銷型網(wǎng)站建設(shè)極速建站廣州網(wǎng)絡(luò)seo公司
  • 視頻下載網(wǎng)站軟件做副屏做網(wǎng)頁(yè)設(shè)計(jì)一個(gè)月能掙多少
  • 什么網(wǎng)站可以看女人唔易做網(wǎng)絡(luò)營(yíng)銷策劃書1500字
  • 做笑話網(wǎng)站常見的推廣方式
  • 免費(fèi)中文網(wǎng)站模板html關(guān)鍵詞排名哪里查
  • 手機(jī)點(diǎn)了釣魚網(wǎng)站怎么辦查詢網(wǎng)址域名ip地址
  • 廊坊網(wǎng)站制作公司小程序開發(fā)平臺(tái)有哪些
  • 個(gè)人網(wǎng)站可以做資訊小說類網(wǎng)絡(luò)優(yōu)化工程師是做什么的
  • 2017做那個(gè)網(wǎng)站能致富惠州seo關(guān)鍵字排名
  • 做彩平的材質(zhì)網(wǎng)站優(yōu)質(zhì)友情鏈接
  • c 網(wǎng)站開發(fā)的優(yōu)點(diǎn)建設(shè)網(wǎng)站推廣
  • 企業(yè)網(wǎng)站建站技術(shù)seo網(wǎng)絡(luò)營(yíng)銷外包公司
  • 個(gè)人建網(wǎng)站的費(fèi)用百度搜索引擎官網(wǎng)入口
  • 網(wǎng)站建設(shè)南陽(yáng)seo外包公司報(bào)價(jià)
  • 做網(wǎng)站客戶一般會(huì)問什么問題寧波seo外包推廣排名
  • 有哪些比較好的外貿(mào)網(wǎng)站seo推廣計(jì)劃
  • 網(wǎng)站建設(shè)企業(yè)建站要求seo的優(yōu)化原理
  • 南昌網(wǎng)站開發(fā)多少錢杭州seo公司
  • 仿xss網(wǎng)站搭建個(gè)人網(wǎng)站制作
  • 西安網(wǎng)站開發(fā)哪家好教育機(jī)構(gòu)加盟
  • 石家莊網(wǎng)站建設(shè)培訓(xùn)班2022真實(shí)新聞作文400字
  • 網(wǎng)站網(wǎng)頁(yè)的收錄數(shù)量好的競(jìng)價(jià)賬戶托管外包
  • 從網(wǎng)絡(luò)營(yíng)銷角度做網(wǎng)站seo外包服務(wù)方案
  • 任丘網(wǎng)站優(yōu)化網(wǎng)站推廣名詞解釋
  • 免費(fèi)ppt成品網(wǎng)站上海百度seo網(wǎng)站優(yōu)化
  • 北流建設(shè)局網(wǎng)站seo網(wǎng)站關(guān)鍵詞優(yōu)化工具
  • 一站式服務(wù)是什么意思網(wǎng)址和網(wǎng)站的區(qū)別
  • 上海 網(wǎng)站備案系統(tǒng)windows優(yōu)化大師會(huì)員兌換碼
  • 小程序開發(fā)費(fèi)用計(jì)入什么科目seo服務(wù)商技術(shù)好的公司