/* * 攻击判定时, * 看是否同时接触了对方本体 ,以及对方的刀光 * 如果同时接触了对方本体 和 刀光, 则认为 此次攻击是“拼刀”, * 不对对方本体造成伤害 */ public void OnJudgeHurtFrame() { // key: victim object id, value: victim CanBeHit component Dictionary <int, CanBeHit> hurtMap = new Dictionary <int, CanBeHit>(); // key: be blocked victim id, value: block attack object CanBlockAttack component Dictionary <int, CanBlockAttack> blockMap = new Dictionary <int, CanBlockAttack>(); // The first block attack object, determine which direction owner shall be bounced CanBlockAttack firstBlockAttack = null; foreach (GameObject other in m_hitList) { CanBeHit cbh = other.GetComponent <CanBeHit>(); if (cbh != null) { hurtMap.Add(other.GetInstanceID(), cbh); //DoLog("OnJudgeHurtFrame [hurtMap] " + other.GetInstanceID()); } CanBlockAttack cba = other.GetComponent <CanBlockAttack>(); if (cba != null && cba.GetOwner() != null) { CanBeHit owner = cba.GetOwner(); int goInstanceId = owner.gameObject.GetInstanceID(); blockMap.Add(goInstanceId, cba); } if (cba != null && firstBlockAttack == null) { firstBlockAttack = cba; } } foreach (int otherId in hurtMap.Keys) { if (blockMap.ContainsKey(otherId)) { GameObject other = blockMap[otherId].gameObject; OnBlocked(other); } else { DoHurtOther(hurtMap[otherId].gameObject); } } if (firstBlockAttack != null) { OnBounced(firstBlockAttack.gameObject); } }
private GameObject CreateSlash() { // create slash GameObject slash = GameObject.Instantiate(m_slashPrefab, Vector3.zero, Quaternion.identity); if (slash.GetComponent <SlashEnvDetector>() != null) { slash.GetComponent <SlashEnvDetector>().InitWithOwner(m_controller.gameObject); } if (slash.GetComponent <CanBlockAttack>() != null) { CanBlockAttack cba = slash.GetComponent <CanBlockAttack>(); CanBeHit cbh = m_controller.GetComponent <CanBeHit>(); if (cbh != null) { cba.SetOwner(cbh); } } // locate position m_slashPos = m_controller.transform.position; float horizonOffset = m_offset.x; if (m_controller.m_faceDir == FaceDir.LEFT) { horizonOffset = -horizonOffset; } m_slashPos.x += horizonOffset; m_slashPos.y += m_offset.y; // update face if (m_isHorizontalSlash && slash.GetComponent <ff.AriesHorizontalSlash>() != null) { // horizontal slash m_slashPos += m_controller.GetFront(); ff.AriesHorizontalSlash horizonSlash = slash.GetComponent <ff.AriesHorizontalSlash>(); horizonSlash.InitWithOwner(m_controller); } slash.transform.position = m_slashPos; slash.transform.localEulerAngles = m_euler; return(slash); }