public static void DestroyIntersectingConnections(GameObject PlacedObject) { BoxCollider[] boxes = PlacedObject.GetComponentsInChildren <BoxCollider>(); List <GameObject> WiresDestroyed = new List <GameObject>(); foreach (BoxCollider box in boxes) { Vector3 center = box.transform.TransformPoint(box.center); Vector3 halfextents = Vector3.Scale(box.size, box.transform.lossyScale) / 2; Vector3 direction = box.transform.up; Quaternion orientation = box.transform.rotation; RaycastHit[] hits = Physics.BoxCastAll(center, halfextents, direction, orientation, 1); // not sure why maxdistance needs to be 1 here but 0 doesn't register ANY wire collisions. Possibly something to do with how thin their colliders are? foreach (RaycastHit hit in hits) { if (hit.collider.tag == "Wire") { // manually check connections, just in case the boxcast hits a false positive if (!hit.collider.GetComponent <Wire>().CanFindPoints()) { if (!WiresDestroyed.Contains(hit.collider.gameObject)) { WiresDestroyed.Add(hit.collider.gameObject); StuffDeleter.DestroyWire(hit.collider.gameObject); } } } } } }
private void DestroySnappedConnection() { if (SnappedConnection == null) { return; } StuffDeleter.DestroyWire(SnappedConnection); DestroyImmediate(SnappedConnection.gameObject); // without this, rotating a snapping peg will make its wire get drawn with the new geometry for a frame }
protected override void ApplyInner() { foreach (var wire in GetWires()) { DeletedWires.Add(new DeletedWire(wire.Point1, wire.Point2)); StuffDeleter.DestroyWire(wire); } SoundPlayer.PlaySoundGlobal(Sounds.DeleteSomething); }
public override void Do() { var wire = NetObject.GetByNetId(Packet.WireNetID)?.gameObject; if (wire == null) { return; } StuffDeleter.DestroyWire(wire); }
public virtual void Undo() { if (Created != null) { foreach (var item in Created) { StuffDeleter.DestroyWire(item); } SoundPlayer.PlaySoundGlobal(Sounds.DeleteSomething); } }