public void ApplySnap(bool ApplyToChildren) { if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene))) { Basic2DScene s = (Basic2DScene)ParentScene; if (s.GridSize != null) { Vector2 GridSize = s.GridSize.get(); Vector2 Pos = Position.get(); Position.set(new Vector2((float)Math.Round(Position.get().X / s.GridSize.get().X), (float)Math.Round(Position.get().Y / s.GridSize.get().Y)) * s.GridSize.get()); } } if (ApplyToChildren) { foreach (GameObject g in HierarchyChildren) #if EDITOR && WINDOWS { if (!ParentLevel.LevelForEditing || !g.EditorSelected) #endif { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplySnap(true); } } } }
private void PositionChange() { if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene))) { Basic2DScene s = (Basic2DScene)ParentScene; if (s.UseGrid.get()) { ApplySnap(false); } } }
public override void Create() { Position = new Vector2Value("Position", EditType.Average); Size = new Vector2Value("Size", Vector2.One, EditType.Scalar); Rotation = new FloatValue("Angle", RotationChange); MoveValuetoFront(Position, Size, Rotation); #if EDITOR && WINDOWS if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene))) { Basic2DScene s = (Basic2DScene)ParentScene; if (s.GridSize != null) { Size.set(s.GridSize.get()); } } #endif base.Create(); }