/// <summary> /// Remove linked node from the managed list. /// </summary> /// <param name="n"> Number of linked object to remove. </param> /// <param name="startIndex"> Starting index to remove. </param> /// <returns> List of removed linked object. </returns> public List <JCS_TransformLinkedObject> RemoveLinked(int n = 1, int startIndex = 0) { if (!JCS_Utility.WithInArrayRange(startIndex, mManagedList)) { JCS_Debug.LogReminder("Can't remove linked node with index lower than 0"); return(null); } var lst = new List <JCS_TransformLinkedObject>(); int maxIndex = startIndex + n; List <int> ids = new List <int>(); for (int index = startIndex; index < mManagedList.Count && index < maxIndex; ++index) { JCS_TransformLinkedObject node = mManagedList[index]; ids.Add(index); // First record it down. lst.Add(node); // Added to the remove list, and ready to return. } for (int index = 0; index < ids.Count; ++index) { int id = ids[index]; JCS_TransformLinkedObject node = mManagedList[id]; Destroy(node.gameObject); mManagedList.RemoveAt(id); } OrganizedLinked(); return(lst); }
private void OrganizedLinked() { mManagedList = JCS_Utility.RemoveEmptySlotIncludeMissing(mManagedList); for (int index = 0; index < mManagedList.Count; ++index) { JCS_TransformLinkedObject node = mManagedList[index]; Vector3 newOffset = mIndexOffset * index; node.TransformTweener.DoTween(newOffset); } }