/// <summary> /// /// </summary> /// <param name="box"></param> public void Copy(XBoxRect box) { this.MinX = box.MinX; this.MinY = box.MinY; this.Width = box.Width; this.Height = box.Height; }
private bool IsBloodyAttack(XBoxComponent cruel, XBoxComponent hard) { XBoxRect attackBox = cruel.GetAttackBoxRect(); List <XBoxRect> receiveBoxes = hard.GetReceiveDamageBoxesRect(); if (attackBox == null || receiveBoxes == null) { return(false); } XBoxRect box = new XBoxRect(); for (int i = 0; i < receiveBoxes.Count; i++) { XBoxRect lapBox = XBoxRect.Overlap(attackBox, receiveBoxes[i]); if (lapBox.Width >= 0) { if (box.Height < lapBox.Height) { box.Copy(lapBox); } } } if (box.Width >= 0) { AddBloodyHeroes(cruel, hard, box); return(true); } return(false); }
void OnDrawGizmos() { if (HitBoxConfig == null) { return; } if (_trans == null) { _trans = transform; } Gizmos.color = Color.red; GetFixedHitBox(1); Gizmos.DrawWireCube(new Vector3((_hitRectBox.MinX + HitBoxConfig.Width) / XBoxComponent.FLOAT_CORRECTION, (_hitRectBox.MinY + HitBoxConfig.Height / 2f) / XBoxComponent.FLOAT_CORRECTION, 0f), new Vector3(HitBoxConfig.Width * 2 / XBoxComponent.FLOAT_CORRECTION, HitBoxConfig.Height / XBoxComponent.FLOAT_CORRECTION, 1.0f)); Gizmos.color = Color.yellow; XBoxRect box = GetFixedWarningBox(1); if (box != null) { Gizmos.DrawWireCube(new Vector3((_warningRectBox.MinX + WarningBoxConfig.Width) / XBoxComponent.FLOAT_CORRECTION, (_warningRectBox.MinY + WarningBoxConfig.Height / 2f) / XBoxComponent.FLOAT_CORRECTION, 0f), new Vector3(WarningBoxConfig.Width * 2 / XBoxComponent.FLOAT_CORRECTION, WarningBoxConfig.Height / XBoxComponent.FLOAT_CORRECTION, 1.0f)); } }
private bool _InternalWarningAttack(XBoxRect rectBox, XBoxComponent hard) { List <XBoxRect> receiveBoxes = hard.GetReceiveDamageBoxesRect(); if (rectBox == null || receiveBoxes == null) { return(false); } for (int i = 0; i < receiveBoxes.Count; i++) { XBoxRect box = XBoxRect.Overlap(rectBox, receiveBoxes[i]); if (box.Width >= 0) { if (!_receiveWarningHeroes.Contains(hard)) { _receiveWarningHeroes.Add(hard); } return(true); } } return(false); }
private void HugEach(XBoxComponent human, XBoxComponent orc) { XBoxHugRect humanBox = human.GetHugBoxRect(); XBoxHugRect orcBox = orc.GetHugBoxRect(); if (humanBox == null || orcBox == null) { return; } XBoxRect overlap = XBoxRect.Overlap(humanBox, orcBox); if (overlap != null && overlap.Width >= 0) { if (humanBox.HugType == orcBox.HugType || (humanBox.HugType != XHugType.Normal && orcBox.HugType != XHugType.Normal)) { if (!_hugEachList.Contains(human)) { _hugEachList.Add(human); } if (!_hugEachList.Contains(orc)) { _hugEachList.Add(orc); } } else { XBoxComponent hc = humanBox.HugType > orcBox.HugType ? orc : human; if (!_hugBeEatenList.Contains(hc)) { _hugBeEatenList.Add(hc); } } } }
/// <summary> /// /// </summary> /// <param name="box1"></param> /// <param name="box2"></param> /// <returns></returns> public static XBoxRect Overlap(XBoxRect box1, XBoxRect box2) { if (_rectBoxOverlap == null) { _rectBoxOverlap = new XBoxRect(); } if (box1 != null && box2 != null) { // pretend to create a box, if the box exit, overlap! int minX = Mathf.Max(box1.MinX, box2.MinX); int minY = Mathf.Max(box1.MinY, box2.MinY); int maxX = Mathf.Min(box1.MinX + box1.Width, box2.MinX + box2.Width); int maxY = Mathf.Min(box1.MinY + box1.Height, box2.MinY + box2.Height); if (minX > maxX || minY > maxY) { _rectBoxOverlap.Height = -1; _rectBoxOverlap.Width = -1; } else { _rectBoxOverlap.Height = maxY - minY; _rectBoxOverlap.Width = maxX - minX; _rectBoxOverlap.MinX = minX; _rectBoxOverlap.MinY = minY; } } else { _rectBoxOverlap.Width = -1; } return(_rectBoxOverlap); }
private void CalBulletHit(XBoxComponent hero) { if (_bullets.Count > 0) { bool isHeroWarning = false; for (int i = 0; i < _bullets.Count; i++) { bool addI = false; List <XBoxRect> boxes = hero.GetReceiveDamageBoxesRect(); for (int hurtBoxIndex = 0; hurtBoxIndex < boxes.Count; hurtBoxIndex++) { if (XBoxRect.Overlap(boxes[hurtBoxIndex], _bullets[i].GetBulletHitBox()).Width >= 0) { AddBulletHero(_bullets[i], hero.Trans); addI = true; break; } } if (!isHeroWarning) { isHeroWarning = IsWarningAttack(_bullets[i], hero); } if (addI) { continue; } for (int flexiHurtIndex = 0; flexiHurtIndex < _flexibleHurtBoxes.Count; flexiHurtIndex++) { if (XBoxRect.Overlap(_flexibleHurtBoxes[flexiHurtIndex].GetFlexibleHurtBox(), _bullets[i].GetBulletHitBox()).Width >= 0) { AddBulletHero(_bullets[i], _flexibleHurtBoxes[flexiHurtIndex].Trans); addI = true; break; } } if (addI) { continue; } for (int index = 0; index < _bullets.Count; index++) { if (index != i) { if (XBoxRect.Overlap(_bullets[i].GetBulletHitBox(), _bullets[index].GetBulletHitBox()).Width >= 0) { AddBulletHero(_bullets[i], _bullets[index].GetFlyEffectTrans()); } } } } } }
private bool IsWarningAttack(XBulletComponent bc, XBoxComponent hard) { XBoxRect box = bc.GetBulletWarningBox(); if (box == null) { return(false); } return(_InternalWarningAttack(box, hard)); }
private int LastTransMeet(XBoxComponent hc1, XBoxComponent hc2) { XBodyMoveRectBox rb1 = hc1.GetTransMoveBox(); XBodyMoveRectBox rb2 = hc2.GetTransMoveBox(); if (rb1 == null || rb2 == null) { return(-1); } XBoxRect box = XBoxRect.Overlap(rb1, rb2); return(box.Width); }
private void AddBloodyHeroes(XBoxComponent attack, int receiveId, XBoxRect overlap) { XBoxBloody hero = _bloodyHeroes.Find(delegate(XBoxBloody obj) { return(obj.AttackHero == attack); }); if (hero == null) { hero = new XBoxBloody(attack); _bloodyHeroes.Add(hero); } hero.AddBloodyHero(receiveId, overlap); }
public void AddBloodyHero(XBoxComponent receive, XBoxRect box) { if (_bloodyHeroes == null) { _bloodyHeroes = new List <int>(); } if (_boxes == null) { _boxes = new List <XBoxRect>(); } _bloodyHeroes.Add(receive.cid); _boxes.Add(box); }
public void AddBloodyHero(int receiveId, XBoxRect box) { if (_bloodyHeroes == null) { _bloodyHeroes = new List <int>(); } if (_boxes == null) { _boxes = new List <XBoxRect>(); } _bloodyHeroes.Add(receiveId); _boxes.Add(box); }
private XBoxExtraRect ExtraBoxMeet(XBoxExtraProperty property, XBoxRect box) { int meet = -1; if (_extraBoxesDic.ContainsKey(property)) { for (int extraIndex = 0; extraIndex < _extraBoxesDic[property].Count; extraIndex++) { meet = XBoxRect.Overlap(box, _extraBoxesDic[property][extraIndex]).Width; if (meet >= 0) { return(_extraBoxesDic[property][extraIndex]); } } } return(null); }
private XBoxRect GetBoundingRect(Transform trans, Collider col) { if (trans == null || col == null) { return(null); } float rectX = col.bounds.min.x * XBoxComponent.FLOAT_CORRECTION; XBoxRect rect = new XBoxRect(); rect.MinX = Mathf.RoundToInt(rectX); rect.MinY = Mathf.RoundToInt(Mathf.Max(0, col.bounds.min.y) * XBoxComponent.FLOAT_CORRECTION); rect.Width = Mathf.RoundToInt(col.bounds.size.x * XBoxComponent.FLOAT_CORRECTION); rect.Width = Mathf.RoundToInt(col.bounds.size.y * XBoxComponent.FLOAT_CORRECTION); return(rect); }
private void AddBloodyFlexiableBoxes(XBoxComponent attack) { XBoxRect attackBox = attack.GetAttackBoxRect(); if (attackBox == null || _flexibleHurtBoxes.Count < 1) { return; } for (int i = 0; i < _flexibleHurtBoxes.Count; i++) { XBoxRect box = XBoxRect.Overlap(attackBox, _flexibleHurtBoxes[i].GetFlexibleHurtBox()); if (box.Width >= 0) { AddBloodyHeroes(attack, _flexibleHurtBoxes[i].GetActiveId(), box); } } }
protected bool IsIntersect(Transform trans) { bool hit = false; XBoxComponent hc = trans.GetComponent <XBoxComponent>(); if (hc != null && collider_ != null) { List <XBoxRect> hurtBoxes = hc.GetReceiveDamageBoxesRect(); XBoxRect bulletRect = GetBoundingRect(transform, collider_); if (hurtBoxes != null && hurtBoxes.Count > 0 && bulletRect != null) { for (int i = 0; i < hurtBoxes.Count; i++) { if (bulletRect.Overlap(hurtBoxes[i]) >= 0) { hit = true; break; } } } } else { Collider colid = trans.GetComponent <Collider>(); if (colid != null) { if (collider_ != null) { hit = colid.bounds.Intersects(collider_.bounds); } else { hit = colid.bounds.Contains(transform.position); } } } return(hit); }
/// <summary> /// /// </summary> /// <param name="box"></param> /// <returns></returns> public int Overlap(XBoxRect box) { // pretend to create a box, if the box exit, overlap! int minX = Mathf.Max(this.MinX, box.MinX); int minY = Mathf.Max(this.MinY, box.MinY); int maxX = Mathf.Min(this.MinX + Width, box.MinX + box.Width); int maxY = Mathf.Min(this.MinY + Height, box.MinY + box.Height); if (minX > maxX || minY > maxY) { return(-1); } else { if (minX >= maxX) { return(0); } return(maxX - minX); } }
private bool AttackOnBullet(XBoxComponent hero) { XBoxRect attackBox = hero.GetAttackBoxRect(); if (attackBox == null) { return(false); } if (_bullets.Count > 0) { for (int i = 0; i < _bullets.Count; i++) { XBoxRect lapBox = XBoxRect.Overlap(attackBox, _bullets[i].GetBulletHitBox()); if (lapBox.Width >= 0) { AddBloodyHeroes(hero, _bullets[i].gid, lapBox); return(true); } } } return(false); }
private void HugYou(XBoxComponent me, XBoxComponent you) { if (_hugBeEatenList.Contains(me)) { return; } XBoxRect hugBox = me.GetHugBoxRect(); if (hugBox == null) { return; } List <XBoxRect> hurtBoxes = you.GetReceiveDamageBoxesRect(); if (hurtBoxes == null) { return; } for (int i = 0; i < hurtBoxes.Count; i++) { XBoxRect overlap = XBoxRect.Overlap(hugBox, hurtBoxes[i]); if (overlap != null && overlap.Width >= 0) { if ((_hugHeroesDic.ContainsKey(me) && overlap.Width < _hugHeroesDic[me].Overlap) || !_hugHeroesDic.ContainsKey(me)) { XBoxOverlap lap = new XBoxOverlap(); lap.Hero = you; lap.Overlap = overlap.Width; _hugHeroesDic[me] = lap; } return; } } }
private void AddBloodyHeroes(XBoxComponent attack, XBoxComponent receive, XBoxRect overlap) { AddBloodyHeroes(attack, receive.cid, overlap); }
private void DrawGL() { if (hitBox_ == null) { return; } if (_hitBoxMat == null) { InitHitBoxShowStuff(); } if (_hc == null || (_hc != null && !_hc.IsDrawBox)) { return; } float width; float height; float minx; float miny; XBoxRect r = GetBulletHitBox(); if (r != null) { width = r.Width / (XBoxComponent.FLOAT_CORRECTION); height = r.Height / (XBoxComponent.FLOAT_CORRECTION); minx = r.MinX / (XBoxComponent.FLOAT_CORRECTION); miny = r.MinY / (XBoxComponent.FLOAT_CORRECTION); if (_hitMesh == null) { _hitMesh = new Mesh(); } _hitMesh.Clear(); _hitMesh.vertices = new Vector3[] { new Vector3(minx, miny, 0), new Vector3(minx + width, miny, 0), new Vector3(minx + width, miny + height, 0), new Vector3(minx, miny + height, 0), }; _hitMesh.triangles = new int[] { 0, 2, 1, 0, 3, 2 }; _hitMesh.name = "HitBoxMesh"; Graphics.DrawMesh(_hitMesh, Vector3.zero, Quaternion.identity, _hitBoxMat, 0); } r = GetBulletWarningBox(); if (r != null) { width = r.Width / (XBoxComponent.FLOAT_CORRECTION); height = r.Height / (XBoxComponent.FLOAT_CORRECTION); minx = r.MinX / (XBoxComponent.FLOAT_CORRECTION); miny = r.MinY / (XBoxComponent.FLOAT_CORRECTION); if (_warningMesh == null) { _warningMesh = new Mesh(); } _warningMesh.Clear(); _warningMesh.vertices = new Vector3[] { new Vector3(minx, miny, 0), new Vector3(minx + width, miny, 0), new Vector3(minx + width, miny + height, 0), new Vector3(minx, miny + height, 0), }; _warningMesh.triangles = new int[] { 0, 2, 1, 0, 3, 2 }; _warningMesh.name = "WarningBoxMesh"; Graphics.DrawMesh(_warningMesh, Vector3.zero, Quaternion.identity, _warningBoxMat, 0); } }
private void CalMove(List <List <XBoxComponent> > cacheList) { for (int i = 0; i < cacheList.Count; i++) { List <XBoxComponent> cache = cacheList[i]; if (cache != null && cache.Count > 1) { List <XBoxIndex> forceBodyList = new List <XBoxIndex>(); for (int index = 0; index < cache.Count; index++) { if (cache[index].GetBodyMoveBox().MoveX != 0) { XBoxIndex hi = new XBoxIndex(); hi.hc = cache[index]; hi.index = index; forceBodyList.Add(hi); } if (cache[index].GetBodyMoveBox().MoveY != 0) { int y = cache[index].GetBodyMoveBox().MoveY > 0 ? _bodyMoveRuler : -_bodyMoveRuler; y = GetRoundZero(y, cache[index].GetBodyMoveBox().MoveY); cache[index].SetLastDeltaPos(0, y); } } List <XBoxIndex> bodyStarts = new List <XBoxIndex>(); CalDirectionalForce(forceBodyList, 0, 0, bodyStarts); for (int index = 0; index < bodyStarts.Count; index++) { if (bodyStarts[index].hc.GetBodyMoveBox().MoveX > 0) { XBoxRect extra = ExtraBoxMeet(XBoxExtraProperty.Wall, cache[cache.Count - 1].GetBodyMoveBox()); if (extra != null && (bodyStarts[index].hc.GetBodyMoveBox().MinX - extra.MinX) * bodyStarts[index].hc.GetBodyMoveBox().MoveX <= 0) { continue; } for (int moveIndex = bodyStarts[index].index; moveIndex < cache.Count; moveIndex++) { int moveStep = GetRoundZero(bodyStarts[index].hc.GetBodyMoveBox().MoveX, _bodyMoveRuler); cache[moveIndex].SetLastDeltaPos(moveStep, 0); cache[moveIndex].AdjustBodyMoveBox(); } } else { XBoxRect extra = ExtraBoxMeet(XBoxExtraProperty.Wall, cache[0].GetBodyMoveBox()); if (extra != null && (bodyStarts[index].hc.GetBodyMoveBox().MinX - extra.MinX) * bodyStarts[index].hc.GetBodyMoveBox().MoveX <= 0) { continue; } for (int moveIndex = bodyStarts[index].index; moveIndex >= 0; moveIndex--) { int moveStep = GetRoundZero(bodyStarts[index].hc.GetBodyMoveBox().MoveX, -_bodyMoveRuler); cache[moveIndex].SetLastDeltaPos(moveStep, 0); cache[moveIndex].AdjustBodyMoveBox(); } } } forceBodyList.Clear(); bodyStarts.Clear(); } } }
private void DealBodyMove() { int threshold = 300; while (threshold > 0) { for (int i = 0; i < _bodySortedHeroes.Count; i++) { for (int index = 0; index < _bodySortedHeroes.Count; index++) { if (i < index) { int meet = XBoxRect.Overlap(_bodySortedHeroes[i].GetBodyMoveBox(), _bodySortedHeroes[index].GetBodyMoveBox()).Width; if (meet >= 0) { XBoxRect extraI = ExtraBoxMeet(XBoxExtraProperty.Wall, _bodySortedHeroes[i].GetBodyMoveBox()); XBoxRect extrIndex = ExtraBoxMeet(XBoxExtraProperty.Wall, _bodySortedHeroes[index].GetBodyMoveBox()); if (extraI != null && extrIndex != null && extrIndex == extraI) { meet = _bodySortedHeroes[i].GetBodyMoveBox().MinX < 0 ? _bodyMoveRuler : -_bodyMoveRuler; if (_bodySortedHeroes[i].GetBodyMoveBox().MinY > _bodySortedHeroes[index].GetBodyMoveBox().MinY) { _bodySortedHeroes[index].SetLastDeltaPos(meet, 0); _bodySortedHeroes[index].AdjustBodyMoveBox(); } else { _bodySortedHeroes[i].SetLastDeltaPos(meet, 0); _bodySortedHeroes[i].AdjustBodyMoveBox(); } } else { if (_bodySortedHeroes[i].GetBodyMoveBox().MinX < _bodySortedHeroes[index].GetBodyMoveBox().MinX) { int move = Mathf.Min((int)(meet * 0.5), _bodyMoveRuler); _bodySortedHeroes[i].GetBodyMoveBox().MoveX -= move; _bodySortedHeroes[index].GetBodyMoveBox().MoveX += move; } else { int move = Mathf.Min((int)(meet * 0.5), _bodyMoveRuler); _bodySortedHeroes[index].GetBodyMoveBox().MoveX -= move; _bodySortedHeroes[i].GetBodyMoveBox().MoveX += move; } } _meetCache.AddCache(_bodySortedHeroes[i], _bodySortedHeroes[index]); } } } } CalMove(_meetCache.CacheList); bool stillMove = false; for (int i = 0; i < _bodySortedHeroes.Count; i++) { if (_bodySortedHeroes[i].GetBodyMoveBox().MoveX != 0 || _bodySortedHeroes[i].GetBodyMoveBox().MoveY != 0) { int x = 0; if (_bodySortedHeroes[i].GetBodyMoveBox().MoveX != 0) { x = _bodySortedHeroes[i].GetBodyMoveBox().MoveX > 0 ? _bodyMoveRuler : -_bodyMoveRuler; x = GetRoundZero(x, _bodySortedHeroes[i].GetBodyMoveBox().MoveX); } int y = 0; if (_bodySortedHeroes[i].GetBodyMoveBox().MoveY != 0) { y = _bodySortedHeroes[i].GetBodyMoveBox().MoveY > 0 ? _bodyMoveRuler : -_bodyMoveRuler; y = GetRoundZero(y, _bodySortedHeroes[i].GetBodyMoveBox().MoveY); } if (_meetCache.GetCacheInCache(_bodySortedHeroes[i]) == null) { XBoxRect extra = ExtraBoxMeet(XBoxExtraProperty.Wall, _bodySortedHeroes[i].GetBodyMoveBox()); if (extra == null || (extra != null && (_bodySortedHeroes[i].GetBodyMoveBox().MinX - extra.MinX) * _bodySortedHeroes[i].GetBodyMoveBox().MoveX > 0)) { _bodySortedHeroes[i].SetLastDeltaPos(x, y); _bodySortedHeroes[i].AdjustBodyMoveBox(); } } BodyMoveStep(_bodySortedHeroes[i], x, y); stillMove = true; } } _meetCache.Clear(); if (stillMove) { threshold -= _bodyMoveRuler; } else { threshold = 0; } } }
private bool IsWarningAttack(XBoxComponent cruel, XBoxComponent hard) { XBoxRect attackBox = cruel.GetAttackWarningBoxRect(); return(_InternalWarningAttack(attackBox, hard)); }