private void DetachRandomWorm() { bool flag = false; for (int i = 0; i < this.attachControl.AttachPoints.Length; i++) { i = UnityEngine.Random.Range(0, this.attachControl.AttachPoints.Length); wormAttachPoints wormAttachPoints = this.attachControl.AttachPoints[i]; for (int j = 0; j < wormAttachPoints.AttachedWorm.Length; j++) { if (wormAttachPoints.AttachedWorm[j] != null) { wormAttachPoints.AttachedWorm[j].SendMessage("Detach", SendMessageOptions.DontRequireReceiver); wormAttachPoints.AttachedWorm[j] = null; if (wormAttachPoints.currentEmptySlot > 0) { wormAttachPoints.currentEmptySlot--; } flag = true; break; } } if (flag) { break; } } }
private IEnumerator DetachAllWormsDelayedDown(int startSegment) { for (int index = startSegment; index > -1; index--) { wormAttachPoints t = this.attachControl.AttachPoints[index]; for (int i = 0; i < t.AttachedWorm.Length; i++) { if (t.AttachedWorm[i] != null) { t.AttachedWorm[i].SendMessage("Detach", SendMessageOptions.DontRequireReceiver); t.AttachedWorm[i] = null; } } t.currentEmptySlot = 0; yield return(YieldPresets.WaitPointOneSeconds); } yield break; }
private void UpdateAttachPoints() { this.currentAttachedWorms = 0; for (int i = 0; i < this.attachControl.AttachPoints.Length; i++) { bool flag = false; wormAttachPoints wormAttachPoints = this.attachControl.AttachPoints[i]; foreach (Transform x in wormAttachPoints.AttachedWorm) { if (x != null) { this.currentAttachedWorms++; flag = true; } } this.attachControl.numAttachedWorms = this.currentAttachedWorms; if (i > 0 && flag) { bool flag2 = false; int num = i - 1; foreach (Transform x2 in this.attachControl.AttachPoints[num].AttachedWorm) { if (x2 != null) { flag2 = true; } } if (!flag2) { base.StartCoroutine(this.DetachAllWormsDelayedUp(i)); base.StartCoroutine(this.DetachAllWormsDelayedDown(i)); this.delayedDetach = true; this.attachControl.canAttach = false; break; } } } if (this.currentAttachedWorms == 0 && this.delayedDetach) { UnityEngine.Object.Destroy(base.gameObject); } }