/// <summary> /// Updates the position of the handle based on the flattened axis (if applicable) /// </summary> /// <param name="axis"></param> public void RefreshFlattenedPosition(BoundsExtentions.Axis axis) { if (HandleTypeFlattened != HandleTypeFlattenedEnum.None) { transform.localPosition = GetHandlePositionFromType(HandleTypeFlattened, axis); } }
/// <summary> /// Convenience function used to correctly place handles. /// Helps prevent prefab corruption. /// </summary> /// <param name="flattenedType"></param> /// <param name="axis"></param> /// <returns></returns> public static Vector3 GetHandlePositionFromType(HandleTypeFlattenedEnum flattenedType, BoundsExtentions.Axis axis) { float left = 0f; float right = 0f; switch (flattenedType) { case HandleTypeFlattenedEnum.None: default: break; case HandleTypeFlattenedEnum.Scale_LT: left = -0.5f; right = 0.5f; break; case HandleTypeFlattenedEnum.Scale_LB: left = -0.5f; right = -0.5f; break; case HandleTypeFlattenedEnum.Scale_RT: left = 0.5f; right = 0.5f; break; case HandleTypeFlattenedEnum.Scale_RB: left = 0.5f; right = -0.5f; break; case HandleTypeFlattenedEnum.Rotate_LT_RT: left = 0.0f; right = 0.5f; break; case HandleTypeFlattenedEnum.Rotate_RT_RB: left = 0.5f; right = 0.0f; break; case HandleTypeFlattenedEnum.Rotate_RB_LB: left = 0.0f; right = -0.5f; break; case HandleTypeFlattenedEnum.Rotate_LB_LT: left = -0.5f; right = 0.0f; break; } Vector3 newPos = Vector3.zero; switch (axis) { case BoundsExtentions.Axis.X: newPos.x = 0; newPos.y = left; newPos.z = right; break; case BoundsExtentions.Axis.Y: newPos.x = left; newPos.y = 0; newPos.z = right; break; case BoundsExtentions.Axis.Z: newPos.x = left; newPos.y = right; newPos.z = 0; break; } return(newPos); }