UIRectEditor.UpdateAnchor C# (CSharp) Method

UpdateAnchor() protected method

Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
protected UpdateAnchor ( int index, bool resetRelative ) : void
index int
resetRelative bool
return void
	protected void UpdateAnchor (int index, bool resetRelative)
	{
		serializedObject.ApplyModifiedProperties();

		Object[] objs = serializedObject.targetObjects;

		for (int i = 0; i < objs.Length; ++i)
		{
			UIRect rect = objs[i] as UIRect;

			if (rect)
			{
				if (index == 0) UpdateHorizontalAnchor(rect, rect.leftAnchor, resetRelative);
				if (index == 1) UpdateHorizontalAnchor(rect, rect.rightAnchor, resetRelative);
				if (index == 2) UpdateVerticalAnchor(rect, rect.bottomAnchor, resetRelative);
				if (index == 3) UpdateVerticalAnchor(rect, rect.topAnchor, resetRelative);

				UnityEditor.EditorUtility.SetDirty(rect);
			}
		}
		serializedObject.Update();
	}