Skip to content

πŸ†2025 ν¬λž˜ν”„ν†€ μ˜¬ν•΄μ˜ κ²Œμž„ 1μœ„πŸ† / 2025 경일IT아카데미 λŒ€μƒμž‘ ν”„λ‘œν† νƒ€μž…

Notifications You must be signed in to change notification settings

Hwanji2/WARP_Prototype

Repository files navigation

DragManager

마우슀 λ“œλž˜κ·Έ 기반 μ˜μ—­ 생성 / 곡간 이동 μ‹œμŠ€ν…œ

ν”„λ‘œν† νƒ€μž… 및 μ΄μ‹μš©μœΌλ‘œ μž‘μ„±λœ 핡심 λͺ¨λ“ˆμž…λ‹ˆλ‹€.
DragManager.cs ν•˜λ‚˜λ§Œ μ΄ν•΄ν•˜λ©΄ 전체 λ©”μ»€λ‹ˆμ¦˜μ„ νŒŒμ•…ν•  수 μžˆμŠ΅λ‹ˆλ‹€.


Requirements

  • Unity 2021+
  • Main Camera (ScreenToWorldPoint μ‚¬μš©)
  • Zone ν”„λ¦¬νŒΉ (SpriteRenderer + Collider2D)
  • Draggable νƒœκ·Έ (λ“œλž˜κ·Έ 영ν–₯ λŒ€μƒ μ§€μ •)

Directory Structure

/Scripts/DragManager.cs /Prefabs/Zone.prefab /Scenes/2dflat (ν…ŒμŠ€νŠΈ 씬)


Setup

  1. DragManager.csλ₯Ό 빈 GameObject에 μΆ”κ°€
  2. Inspectorμ—μ„œ zonePrefab μ—°κ²°
  3. 이동 λŒ€μƒ μ˜€λΈŒμ νŠΈμ— Draggable νƒœκ·Έ λΆ€μ—¬
  4. Scenes/2dflat μ‹€ν–‰ν•˜μ—¬ ν…ŒμŠ€νŠΈ

Core Logic

Drag Start

  • Left Mouse Button Down
  • λ“œλž˜κ·Έ μ‹œμž‘μ  기둝
  • Zone ν”„λ¦¬νŒΉ μΈμŠ€ν„΄μŠ€ 생성

Dragging

  • 마우슀 μœ„μΉ˜λ₯Ό World μ’Œν‘œλ‘œ λ³€ν™˜
  • μ‹œμž‘μ  λŒ€λΉ„ μ˜μ—­ 크기 μ‹€μ‹œκ°„ μ—…λ°μ΄νŠΈ
  • Zone 크기 및 μœ„μΉ˜ μ •κ·œν™” 처리

Drag End

  • Left Mouse Button Up
  • Zone ν™•μ • (Collider λ²”μœ„ κ³ μ •)
  • Zone λ‚΄λΆ€ Draggable 검색
  • 이후 μƒμ„±λ˜λŠ” Zone으둜 λŒ€μƒ Teleport

Teleport Rule

  • Zone Aμ—μ„œ Zone B둜 이동할 λ•Œ
  • A λ‚΄λΆ€μ˜ λͺ¨λ“  Draggable
    β†’ B.center둜 μ¦‰μ‹œ μŠ€λƒ… 이동
  • Player λ˜ν•œ λ™μΌν•œ κ·œμΉ™ 적용

Why Draggable Tag?

  • λ“œλž˜κ·Έ 영ν–₯ λŒ€μƒμ„ λͺ…ν™•νžˆ μ œν•œν•˜κΈ° μœ„ν•¨
  • μ „ 였브젝트 이동 μ‹œ 물리 및 좩돌 문제 λ°œμƒ
  • νƒœκ·Έ 기반 μŠ€μ½”ν”„ λΆ„λ¦¬λ‘œ μ•ˆμ •μ„± 확보

Test Scene (2dflat)

ν…ŒμŠ€νŠΈμš© μ”¬μ—λŠ” λ‹€μŒμ΄ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

  • DragManager
  • κΈ°λ³Έ ν”Œλž«ν¬λ¨Έ Player
  • Draggable μƒ˜ν”Œ 였브젝트
  • Zone ν”„λ¦¬νŒΉ

Notes

  • 이동은 Rigidbody2D 기반이 μ•„λ‹Œ Transform μŠ€λƒ… 방식
  • Draggable μ˜€λΈŒμ νŠΈλŠ” Collider2D ν•„μˆ˜
  • Zone은 λ“œλž˜κ·Έ 벑터 기반으둜 μžλ™ 크기 μ‘°μ •
  • λͺ¨λ“  μž…λ ₯ μ²˜λ¦¬λŠ” DragManager 단일 λͺ¨λ“ˆλ‘œ 관리 (Global Input Layer)

Execution Flow

LMB Down β†’ record startPos β†’ instantiate ZonePrefab

LMB Hold β†’ update Zone scale/position

LMB Up β†’ lock Zone β†’ find Draggable inside β†’ on next Zone β†’ teleport to center


Summary

이 μ‹œμŠ€ν…œμ€ β€œμ˜μ—­ 그리기 β†’ 곡간 μ΄λ™β€μ΄λΌλŠ” μƒˆλ‘œμš΄ μ‘°μž‘ κ²½ν—˜μ— μ§‘μ€‘ν•œ ν”„λ‘œν† νƒ€μž…μž…λ‹ˆλ‹€.
단일 Manager 기반 ꡬ쑰둜 이식성이 λ†’μœΌλ©°, μ΅œμ†Œ λ¦¬μ†ŒμŠ€λ‘œ 높은 μƒν˜Έμž‘μš© 효과λ₯Ό 얻을 수 μžˆλ„λ‘ μ„€κ³„λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

About

πŸ†2025 ν¬λž˜ν”„ν†€ μ˜¬ν•΄μ˜ κ²Œμž„ 1μœ„πŸ† / 2025 경일IT아카데미 λŒ€μƒμž‘ ν”„λ‘œν† νƒ€μž…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •