private void TriggerJoinEvent(bool isJoined) { this.isJoined = isJoined; if (isJoined) { Joined.SafeInvoke(); } else { Splitted.SafeInvoke(); } }
public void Split() { var rb = GetComponentInParent <Rigidbody2D>(); // Vector3 direction = rb.velocity.normalized; Vector3 direction = Vector3.right; // hard code direction for now var offset = direction * 0.5f; var pos = transform.position; var extraVelocity = rb.velocity.normalized * 1f; var first = SpawnPart(pos + offset, rb.velocity + extraVelocity); var second = SpawnPart(pos, rb.velocity); Splitted?.Invoke(first, second); Destroy(this.gameObject); }
override public string ToString() { if (rows.Count > 0) { List <string> row = rows[rows.Count - 1]; if (row != null && row.Count == 0) { rows.RemoveAt(rows.Count - 1); } } int colsCount = 0; int rowsCount = rows.Count; for (int i = 0; i < rowsCount; i++) { List <string> list = rows[i]; if (list != null) { if (colsCount < list.Count) { colsCount = list.Count; } } } int[] colSizes = new int[colsCount]; for (int i = 0; i < colsCount; i++) { for (int j = 0; j < rowsCount; j++) { List <string> list = rows[j]; if (list != null) { string text = i < list.Count ? list[i] : ""; int length = Math.Min(maxColWidth, text.Length); if (colSizes[i] < length) { colSizes[i] = length; } } } } int width = (colsCount - 1) * 3; for (int i = 0; i < colsCount; i++) { width += colSizes[i]; } string[] lineTexts = new string[colsCount]; StringBuilder builder = new StringBuilder(); for (int i = 0; i < rowsCount; i++) { List <string> list = rows[i]; if (list != null) { for (int j = 0; j < colsCount; j++) { lineTexts[j] = j < list.Count ? list[j] : ""; } while (true) { bool allCompleted = true; for (int j = 0; j < colsCount; j++) { bool needLine = j > 0; if (lineTexts[j] != null) { string part = lineTexts[j]; if (needLine) { if (part.StartsWith("=")) { part = " " + part.Substring(1); builder.Append(" = "); } else { builder.Append(" │ "); } } Splitted splitted = SplitSubline(part, colSizes[j]); lineTexts[j] = splitted.tail; allCompleted = splitted.tail == null; builder.Append(splitted.head.PadRight(colSizes[j])); } else { if (needLine) { builder.Append(" │ "); } builder.Append(new string(' ', colSizes[j])); } } builder.AppendLine(); if (allCompleted) { break; } } } else { for (int j = 0; j < colsCount; j++) { if (j > 0) { builder.Append("─┼─"); } int colSize = colSizes[j]; builder.Append(new string('─', colSize)); } builder.AppendLine(); } } return(builder.ToString()); }