본문 바로가기

Programming/Unity

[Unity]Parts 교체시 bones 정보 세팅

반응형

Parts 인스펙터

 

 

 

 

* 호출하는 곳 소스

public void ChangeCloth() 

{ 

if (Cloth != null) 

{ 

Destroy(Cloth); 

} 

 

if (ClothList.Length > ClothIndex && ClothList[ClothIndex] != null) 

{ 

Cloth = Instantiate(ClothList[ClothIndex], Body.transform, false); 

JointStructString[] jsss = Cloth.GetComponentsInChildren<JointStructString>(); 

foreach (JointStructString jss in jsss) 

{ 

jss.Apply(Body.transform); 

}

 

 

 

 

 

* JointStructString 클래스

public class JointStructString : MonoBehaviour

{

public SkinnedMeshRenderer sk;

public string root = null;

public string[] strBoneList = null;

 

public void Apply(Transform t)

{

        body.rootBone = CommonFunc.FindChildByName(root, t);

        if (body.rootBone == null)

                body.rootBone = t;

 

        Transform[] bones = new Transform[list.Length];

        for(int i = 0; i< strBoneList.Length; i++)

        {

            bones[i] = CommonFunc.FindChildByName(strBoneList[i], t);

            if (bones[i] == null)

            {

                bones[i] = t;

            }

        }

        

        body.bones = bones;

    }

}

 

 

 

 

 

 

파츠마다 애니메이션에 사용하는 바디의 본 목록이 다르기 때문에 각 파츠마다 strBoneList에 바디의 Bone의 목록을 가지고 있고, 이 정보를 바디의 SkinnedMeshRenderer.bones에 리스트로 넣어 놓으면 바디가 애니메이션 될 때 해당 Bone과 Bone에 영향을 받는 파츠의 정점들도 같이 애니메이션 된다.

반응형

'Programming > Unity' 카테고리의 다른 글

절대강좌! 유니티  (0) 2019.02.02
유니티 쉐이더 스타트업  (0) 2019.02.02
Polybrush  (0) 2019.02.02
Material charts  (0) 2019.02.02
Unity Download Asset Path  (0) 2019.02.02