protected virtual void DrawFinalProperties ()
{
if (NGUIEditorTools.DrawHeader("Anchors"))
{
NGUIEditorTools.BeginContents();
NGUIEditorTools.SetLabelWidth(62f);
EditorGUI.BeginDisabledGroup(!((target as UIRect).canBeAnchored));
GUILayout.BeginHorizontal();
AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType);
GUILayout.Space(18f);
GUILayout.EndHorizontal();
SerializedProperty[] tg = new SerializedProperty[4];
for (int i = 0; i < 4; ++i) tg[i] = serializedObject.FindProperty(FieldName[i] + ".target");
if (mAnchorType == AnchorType.None && type != AnchorType.None)
{
if (type == AnchorType.Unified)
{
if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null)
{
UIRect rect = target as UIRect;
UIRect parent = NGUITools.FindInParents<UIRect>(rect.cachedTransform.parent);
if (parent != null)
for (int i = 0; i < 4; ++i)
mTarget[i] = parent.cachedTransform;
}
}
for (int i = 0; i < 4; ++i)
{
tg[i].objectReferenceValue = mTarget[i];
mTarget[i] = null;
}
UpdateAnchors(true);
}
if (type == AnchorType.Advanced)
{
DrawAnchor(0, true);
DrawAnchor(1, true);
DrawAnchor(2, true);
DrawAnchor(3, true);
}
else if (type == AnchorType.Unified)
{
DrawSingleAnchorSelection();
DrawAnchor(0, false);
DrawAnchor(1, false);
DrawAnchor(2, false);
DrawAnchor(3, false);
}
else if (type == AnchorType.None && mAnchorType != type)
{
// Save values to make it easy to "go back"
for (int i = 0; i < 4; ++i)
{
mTarget[i] = tg[i].objectReferenceValue as Transform;
tg[i].objectReferenceValue = null;
}
serializedObject.FindProperty("leftAnchor.relative").floatValue = 0f;
serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f;
serializedObject.FindProperty("rightAnchor.relative").floatValue = 1f;
serializedObject.FindProperty("topAnchor.relative").floatValue = 1f;
}
mAnchorType = type;
OnDrawFinalProperties();
EditorGUI.EndDisabledGroup();
NGUIEditorTools.EndContents();
}
}