private void DrawMainPart(Building.Part part, GUIContent label) { EditorGUILayout.LabelField(label); using (new EditorGUI.IndentLevelScope()) { part.Renderer.sprite = EditorGUILayout.ObjectField(_spriteContent, part.Renderer.sprite, typeof(Sprite), false, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight)) as Sprite; part.OrderOffset = part.Renderer.sortingOrder = EditorGUILayout.IntSlider(_orderOffsetContent, part.Renderer.sortingOrder, 0, _building.Accessories.Count + 2); } }
private void DrawPart(Building.Part part) { if (part.Renderer.sprite) { var snap = 1 / part.Renderer.sprite.pixelsPerUnit; var selectedBounds = HandleHelper.MoveHandle(part.Renderer.bounds.center, part.Bounds.size, new Vector2(snap, snap), Color.green, new Color(0.0f, 0.0f, 0.0f, 0.25f)); selectedBounds -= (Vector2)part.Renderer.bounds.extents; UpdatePartTransform(part, selectedBounds); } }
private void UpdatePartTransform(Building.Part part, Vector2 position) { if (part.Renderer.sprite) { var snap = 1 / part.Renderer.sprite.pixelsPerUnit; var pivot = part.Renderer.sprite.pivot / part.Renderer.sprite.rect.size * part.Renderer.size; position.x = MathHelper.Snap(position.x, snap); position.y = MathHelper.Snap(position.y, snap); var clamped = position + pivot; clamped.x = Mathf.Clamp(clamped.x, _building.Bounds.xMin, _building.Bounds.xMax); clamped.y = Mathf.Clamp(clamped.y, _building.Bounds.yMin, _building.Bounds.yMax); part.Bounds = new Rect(position, part.Renderer.size); part.Renderer.transform.localScale = Vector2.one; part.Renderer.transform.position = clamped; } }