///<summary> 操作範囲を超えているかどうか判定する。 </summary> private bool CheckLimitOver(ChipUI chip) { float x_min = LIMIT_UI_SPACE["min x"]; float y_min = LIMIT_UI_SPACE["min y"]; float x_max = LIMIT_UI_SPACE["max x"]; float y_max = LIMIT_UI_SPACE["max y"]; ChipUI.Corner corner = chip.GetCorner(); // 4辺の接触判定 Vector2[] checks = new Vector2[8] { new Vector2(x_min, corner.top.y), new Vector2(x_min, corner.bottom.y), new Vector2(corner.top.x, y_min), new Vector2(corner.bottom.x, y_min), new Vector2(x_max, corner.top.y), new Vector2(x_max, corner.bottom.y), new Vector2(corner.top.x, y_max), new Vector2(corner.bottom.x, y_max) }; // どこかの座標が入っていたら、範囲を超えている。 foreach (Vector2 check in checks) { if (chip.CheckOnPoint(check)) { return(true); } } return(false); }
///<summary> 他のChipUIと接触しているかどうか </summary> public bool CheckHit(ChipUI chip) { Corner _corner_chip = chip.GetCorner(); Corner _corner_this = this.GetCorner(); // それぞれの大きさを計算する float size_chip = Vector2.Distance(_corner_chip.top, _corner_chip.bottom); float size_this = Vector2.Distance(_corner_this.top, _corner_this.bottom); // サイズが小さい方の頂点が大きい方の範囲内に入っていることを判定すればよい。 bool is_check_this = true; // thisの方が小さい場合 if (size_chip > size_this) { is_check_this = false; // chipの方が小さい場合 } // this側が小さい時の判定 if (is_check_this) { // this側のチェックで判定する座標群 Vector2[] this_check = new Vector2[4] { _corner_chip.top, new Vector2(_corner_chip.top.x, _corner_chip.bottom.y), _corner_chip.bottom, new Vector2(_corner_chip.bottom.x, _corner_chip.top.y) }; // this側のあたり判定 foreach (Vector2 check in this_check) { if (this.CheckOnPoint(check)) { return(true); } } } // chip側が小さい時の判定 else { // chip側のチェックで判定する座標群 Vector2[] chip_check = new Vector2[4] { _corner_this.top, new Vector2(_corner_this.top.x, _corner_this.bottom.y), _corner_this.bottom, new Vector2(_corner_this.bottom.x, _corner_this.top.y) }; // chip側のあたり判定 foreach (Vector2 check in chip_check) { if (chip.CheckOnPoint(check)) { return(true); } } } // 全てのチェックを通過したら、接触していない return(false); }