void OnValidate() { switch (constrainerType) { case ConstrainerType.Constrainer_angle: constrainer = new Constrainer_angle(); ((Constrainer_angle)constrainer).active = active; ((Constrainer_angle)constrainer).maxAngle = maxAngle; ((Constrainer_angle)constrainer).transform = transform; ((Constrainer_angle)constrainer).parent = parent; ((Constrainer_angle)constrainer).child = child; break; case ConstrainerType.Constrainer_plane: constrainer = new Constrainer_plane(); ((Constrainer_plane)constrainer).active = active; ((Constrainer_plane)constrainer).drawProjection = drawProjection; ((Constrainer_plane)constrainer).transform = transform; ((Constrainer_plane)constrainer).parent = parent; ((Constrainer_plane)constrainer).child = child; ((Constrainer_plane)constrainer).plane = plane; ((Constrainer_plane)constrainer).threshold = threshold; break; case ConstrainerType.Constrainer_twist: constrainer = new Constrainer_twist(); ((Constrainer_twist)constrainer).active = active; ((Constrainer_twist)constrainer).minAngle = minAngle; ((Constrainer_twist)constrainer).maxAngle = maxAngle; ((Constrainer_twist)constrainer).transform = transform; ((Constrainer_twist)constrainer).localForward = localForward; break; case ConstrainerType.Constrainer_minmaxangle: constrainer = new Constrainer_minmaxangle(); ((Constrainer_minmaxangle)constrainer).active = active; ((Constrainer_minmaxangle)constrainer).minAngle = minAngle; ((Constrainer_minmaxangle)constrainer).maxAngle = maxAngle; ((Constrainer_minmaxangle)constrainer).transform = transform; ((Constrainer_minmaxangle)constrainer).parent = parent; ((Constrainer_minmaxangle)constrainer).child = child; break; case ConstrainerType.Constrainer_minmaxangle_plane: constrainer = new Constrainer_minmaxangle_plane(); ((Constrainer_minmaxangle_plane)constrainer).active = active; ((Constrainer_minmaxangle_plane)constrainer).drawProjection = drawProjection; ((Constrainer_minmaxangle_plane)constrainer).minAngle = minAngle; ((Constrainer_minmaxangle_plane)constrainer).maxAngle = maxAngle; ((Constrainer_minmaxangle_plane)constrainer).transform = transform; ((Constrainer_minmaxangle_plane)constrainer).parent = parent; ((Constrainer_minmaxangle_plane)constrainer).child = child; ((Constrainer_minmaxangle_plane)constrainer).plane = plane; ((Constrainer_minmaxangle_plane)constrainer).threshold = threshold; break; } Debug.Assert(constrainer != null); }
public RectangleF CalcContentBounds(bool includeMargins = false) { if (HasChildren && Visible) { Vector2 topLeft = new Vector2(float.MaxValue); Vector2 bottomRight = new Vector2(float.MinValue); foreach (UIControl control in controls) { RectangleF rect = RectangleF.Empty; if (control is UIContainer) { rect = (control as UIContainer).CalcContentBounds(); } else if (control.Visible) { rect = control.Bounds; if (includeMargins) { rect.Left -= Constrainer.GetEdgeDistance(Edge.Left); rect.Right += Constrainer.GetEdgeDistance(Edge.Right); rect.Top -= Constrainer.GetEdgeDistance(Edge.Top); rect.Bottom += Constrainer.GetEdgeDistance(Edge.Bottom); } } topLeft.X = Math.Min(topLeft.X, rect.Left); topLeft.Y = Math.Min(topLeft.Y, rect.Top); bottomRight.X = Math.Max(bottomRight.X, rect.Right); bottomRight.Y = Math.Max(bottomRight.Y, rect.Bottom); } return(new RectangleF(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y)); } return(RectangleF.Empty); }
void OnValidate() { constrainer = (Constrainer)Activator.CreateInstance(Constrainers[constrainerType]); Debug.Assert(constrainer != null); }