| | |
| | | |
| | | private void OnDamageTaken(BattleDmgInfo damageInfo) |
| | | { |
| | | GameObject damageContent = damagePrefabPool.Request(); |
| | | DamageContent content = damageContent.GetComponent<DamageContent>(); |
| | | damageContent.transform.SetParent(damageNode, false); |
| | | |
| | | var heroRect = damageInfo.hurtObj.heroRectTrans; |
| | | if (heroRect == null) |
| | | SetTargetDamage(damageInfo); |
| | | SetSelfDamage(damageInfo); |
| | | } |
| | | |
| | | private void SetSelfDamage(BattleDmgInfo damageInfo) |
| | | { |
| | | if (damageInfo.casterDamageList.Count > 0) |
| | | { |
| | | damagePrefabPool.Release(damageContent); |
| | | return; |
| | | GameObject damageContent = damagePrefabPool.Request(); |
| | | DamageContent content = damageContent.GetComponent<DamageContent>(); |
| | | damageContent.transform.SetParent(damageNode, false); |
| | | |
| | | var heroRect = damageInfo.casterObj.heroRectTrans; |
| | | if (heroRect == null) |
| | | { |
| | | damagePrefabPool.Release(damageContent); |
| | | return; |
| | | } |
| | | |
| | | var contentRect = content.GetComponent<RectTransform>(); |
| | | var contentParentRect = contentRect.parent as RectTransform; |
| | | |
| | | // 获取 heroRect 的世界坐标(锚点为中心) |
| | | Vector3 worldTargetPos = heroRect.transform.TransformPoint(heroRect.rect.center); |
| | | |
| | | // 转换到 content 父节点下的 anchoredPosition |
| | | Vector2 anchoredPos; |
| | | RectTransformUtility.ScreenPointToLocalPointInRectangle( |
| | | contentParentRect, |
| | | RectTransformUtility.WorldToScreenPoint(null, worldTargetPos), |
| | | null, |
| | | out anchoredPos); |
| | | |
| | | // 设置动态位置(会覆盖配置中的位置) |
| | | Vector2 beginPos = anchoredPos; |
| | | Vector2 endPos = anchoredPos + new Vector2(0, 150); |
| | | content.SetPosition(beginPos, endPos); |
| | | |
| | | // 设置速度比例 |
| | | if (battleField != null) |
| | | { |
| | | content.SetRatio(battleField.speedRatio, 1f); |
| | | } |
| | | |
| | | content.SetDamage(damageInfo, damageInfo.casterDamageList, () => RemoveDamageContent(content)); |
| | | damageContentList.Add(content); |
| | | } |
| | | } |
| | | |
| | | var contentRect = content.GetComponent<RectTransform>(); |
| | | var contentParentRect = contentRect.parent as RectTransform; |
| | | |
| | | // 获取 heroRect 的世界坐标(锚点为中心) |
| | | Vector3 worldTargetPos = heroRect.transform.TransformPoint(heroRect.rect.center); |
| | | |
| | | // 转换到 content 父节点下的 anchoredPosition |
| | | Vector2 anchoredPos; |
| | | RectTransformUtility.ScreenPointToLocalPointInRectangle( |
| | | contentParentRect, |
| | | RectTransformUtility.WorldToScreenPoint(null, worldTargetPos), |
| | | null, |
| | | out anchoredPos); |
| | | |
| | | // 设置动态位置(会覆盖配置中的位置) |
| | | Vector2 beginPos = anchoredPos; |
| | | Vector2 endPos = anchoredPos + new Vector2(0, 150); |
| | | content.SetPosition(beginPos, endPos); |
| | | |
| | | // 设置速度比例 |
| | | if (battleField != null) |
| | | private void SetTargetDamage(BattleDmgInfo damageInfo) |
| | | { |
| | | if (damageInfo.targetDamageList.Count > 0) |
| | | { |
| | | content.SetRatio(battleField.speedRatio, 1f); |
| | | } |
| | | GameObject damageContent = damagePrefabPool.Request(); |
| | | DamageContent content = damageContent.GetComponent<DamageContent>(); |
| | | damageContent.transform.SetParent(damageNode, false); |
| | | |
| | | var heroRect = damageInfo.hurtObj.heroRectTrans; |
| | | if (heroRect == null) |
| | | { |
| | | damagePrefabPool.Release(damageContent); |
| | | return; |
| | | } |
| | | |
| | | // 设置伤害数据并开始播放 |
| | | content.SetDamage(damageInfo, () => RemoveDamageContent(content)); |
| | | damageContentList.Add(content); |
| | | var contentRect = content.GetComponent<RectTransform>(); |
| | | var contentParentRect = contentRect.parent as RectTransform; |
| | | |
| | | // 获取 heroRect 的世界坐标(锚点为中心) |
| | | Vector3 worldTargetPos = heroRect.transform.TransformPoint(heroRect.rect.center); |
| | | |
| | | // 转换到 content 父节点下的 anchoredPosition |
| | | Vector2 anchoredPos; |
| | | RectTransformUtility.ScreenPointToLocalPointInRectangle( |
| | | contentParentRect, |
| | | RectTransformUtility.WorldToScreenPoint(null, worldTargetPos), |
| | | null, |
| | | out anchoredPos); |
| | | |
| | | // 设置动态位置(会覆盖配置中的位置) |
| | | Vector2 beginPos = anchoredPos; |
| | | Vector2 endPos = anchoredPos + new Vector2(0, 150); |
| | | content.SetPosition(beginPos, endPos); |
| | | |
| | | // 设置速度比例 |
| | | if (battleField != null) |
| | | { |
| | | content.SetRatio(battleField.speedRatio, 1f); |
| | | } |
| | | |
| | | content.SetDamage(damageInfo, damageInfo.targetDamageList, () => RemoveDamageContent(content)); |
| | | damageContentList.Add(content); |
| | | } |
| | | } |
| | | |
| | | public void SetBattleField(BattleField _battleField) |