# Spine

<https://www.youtube.com/watch?v=DxDZtTK2nlE>

SkeletonAnimation 컴포넌트

* spine 패키지의 핵심
* 하는 일
  * GameObject에 Spine skeleton을 추가한다
  * animate한다
  * 애니메이션 이벤트에 반응한다
  * 기타 등등

SkeletonDataAsset

* skeleton data와 texture atlas 제공
* spine editor에서 export한 것들 그대로 넣으면 asset 자동 생성됨
* 씬에 끌어다 놓으면 skeleton GameObject 생성

AnimationState

* `GetComponent<SkeletonAnimation>().AnimationState` : 할당해놓고 애니메이션 현재 상태 확인할 수 있는 인스턴스
* track 개념 : 상위 track은 하위 track을 override
* `AnimationState.SetAnimation()`
  * SetAnimation()은 기존 Animation을 내쫓고 재생
  * 인자 1 : Track Index, 애니메이션 override 가능
  * 인자 2 : Animation, 무슨 애니메이션
  * 인자 3 : loop, 루프 할건지
* 애니메이션이 다른 애니메이션으로 바뀔 때 mix duration이 부드럽게 전환 정도 결정
* SkeletonDataAsset에서 Mix Settings로 mix duration 설정 가능
* `AnimationState.SetAnimation()`
  * 애니메이션 뒤에 재생할 애니메이션 추가
  * 인자 1,2,3 : 동일
  * 인자 4 : delay, 얼마나 기다린 후에 재생될건지. 0으로 두면 앞에거 끝난 후에 재생.
* SetAnimation()과 AddAnimation()은 TrackEntry 객체를 반환하는데, 이걸로 애니메이션 추가 조정 가능
  * mix duration 등 수많은 속성 조절 가능
* `skeletonAnimation.AnimationState.Event += HandleAnimationStateEvent` : 모든 애니메이션에 이벤트 발생 체크 (editor에서 이벤트 지정)
* `trackEntry.Event += HandleAnimationStateEvent` : 특정 애니메이션에 이벤트 발생 체크
* AttachmentTrheshhold : 파티클같은거 애니메이션에서 attachment로 추가했을 때 애니메이션 전환 시에 갑툭튀 안 하게 조절
* `skeletonAnimation.state.AddEmptyAnimation()` : 포즈 초기화 애니메이션 추가

SkeletonAnimation은 meshrenderer를 사용하기 때문에 lighting 있으면 shadow cast한다

SkeletonUtilityBone 컴포넌트 : 계단 걸을 때 발 높이 맞추기 등

SkeletonGraphic 컴포넌트 : SkeletonAnimation 대신 사용. UI에 spine 객체 렌더링 가능

* BoneFollwerGraphic : UI 요소가 본을 따라가게 함

SkeletonMecanim 컴포넌트 : SkeletonAnimation 대신 사용. animation controller처럼 애니메이션 편집 가능하게 됨 (limitations 있으니 안 쓰는게 맞다)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lazyartisan.gitbook.io/note/main-page/r-and-d/spine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
