protected void Swap(int index, int directon) { directon = Mathf.Clamp(directon, -1, 1); listRoot.SwapArrayElements(index, directon); var tempData = renderData[index]; renderData[index] = renderData[index + directon]; renderData[index + directon] = tempData; }
public void CanSwapArrayElements() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[])); property.Value = new string[] { "hello", "there" }; var child1 = property.GetChildAt(0); var child2 = property.GetChildAt(1); property.SwapArrayElements(0, 1); Assert.AreEqual(property.GetValue <string[]>()[1], "hello"); Assert.AreEqual(property.GetValue <string[]>()[0], "there"); Assert.AreEqual(property.GetChildAt(1), child1); Assert.AreEqual(property.GetChildAt(0), child2); Assert.AreEqual(property.ChildCount, 2); }
public void SwapArrayElements(int index, int direction) { if (isCircular) { circularRef.SwapArrayElements(index, direction); } if (!IsArrayLike) { return; } direction = Mathf.Clamp(direction, -1, 1); var tempChild = children[index]; children[index] = children[index + direction]; children[index + direction] = tempChild; IList list = value as IList; var temp = list[index]; list[index] = list[index + direction]; list[index + direction] = temp; changed = true; }
public void ChangedFlagIsFlippedWhenManipulatingArray() { List <string> list = new List <string>(); list.Add("Hello"); list.Add("There"); list.Add("Unity"); SerializedPropertyX property = new SerializedPropertyX("name", typeof(List <string>)); property.ArraySize++; Assert.IsTrue(property.Changed); property = new SerializedPropertyX("name", typeof(List <string>), list); property.ArraySize--; Assert.IsTrue(property.Changed); property = new SerializedPropertyX("name", typeof(List <string>), list); property.SwapArrayElements(1, -1); Assert.IsTrue(property.Changed); property = new SerializedPropertyX("name", typeof(List <string>), list); property.DeleteArrayElementAt(1); Assert.IsTrue(property.Changed); }