CREATE YOUR WORLD
Players & Characters : Tips

ZEPETO 캐릭터 색상 및 착용 중인 아이템 색상 변경하기

7min
이 가이드는 매력적인 콘텐츠를 만드는 데 도움을 주기 위한 것입니다 zepeto 캐릭터의 색상 변경 zepeto 캐릭터는 실행 시간에 zepetocharacter 객체로 인스턴스화됩니다 zepetocharacter의 구조를 검사하면 zepeto context라는 하위 객체를 찾을 수 있습니다 zepeto context 내에는 body라는 또 다른 객체가 있습니다 스크립트를 사용하여 실행 시간에 body 객체의 body(clone) 재질을 교체하면 zepeto 캐릭터의 색상을 변경할 수 있습니다 비애니메이션 아바타의 경우, 이 방법은 전체 얼굴과 몸의 색상을 변경합니다 그러나 애니메이션 아바타의 경우, body 객체의 자식인 anime basemodel의 body(clone) 재질도 수정해야 합니다 재질 교체는 동일한 길이의 재질 배열로 가능하다는 점에 유의하십시오 📘 유니티 재료 https //docs unity3d com/2020 3/documentation/manual/materials html https //docs unity3d com/2020 3/documentation/manual/materials html 아래는 로컬 플레이어의 몸체 색상을 변경하는 샘플 코드입니다 캐릭터가 로드된 후에만 캐릭터의 색상이 변경되도록 로직을 구현해야 합니다 import { zepetoscriptbehaviour } from 'zepeto script' import {localplayer, spawninfo, zepetocharacter, zepetocharactercreator, zepetoplayers} from "zepeto character controller"; import {zepetopropertyflag} from "zepeto"; import { gameobject, material, renderer, skinnedmeshrenderer, transform, waitforseconds } from 'unityengine'; import { button } from 'unityengine ui'; export default class changeskincolor extends zepetoscriptbehaviour { public newcolormaterial material; public changecolorbutton button; public originalcolorbutton button; private originalcolormaterial material; private originalanimematerials material\[]; private animerend renderer; private bodyrend renderer; private bodyrends renderer\[]; private localcharacter zepetocharacter; start() { // find the local player and set it to localcharacter zepetoplayers instance onaddedlocalplayer addlistener(() => { this localcharacter = zepetoplayers instance localplayer zepetoplayer character; // find the material of the local player's zepeto context this bodyrend= this localcharacter context getcomponentinchildren\<skinnedmeshrenderer>(); // store the original material this originalcolormaterial = this bodyrend material; // determine if it is an animated avatar and save related information this bodyrends= this localcharacter getcomponentsinchildren\<skinnedmeshrenderer>(); this bodyrends foreach((currentrenderer) =>{ if(currentrenderer name includes("anime basemodel")){ this animerend = currentrenderer; this originalanimematerials = this animerend sharedmaterials; } }); }); // replace with the preset material when the button is pressed this changecolorbutton onclick addlistener(() => { if(this localcharacter != null) { this bodyrend material = this newcolormaterial; if(this animerend != null) { let tempmaterials material\[] = \[this animerend sharedmaterials\[0],this animerend sharedmaterials\[1],this newcolormaterial,this animerend sharedmaterials\[3]]; this animerend sharedmaterials = tempmaterials; } } }); // return to the original material when the button is pressed this originalcolorbutton onclick addlistener(() => { if(this localcharacter != null) { this bodyrend material = this originalcolormaterial; if(this animerend != null) { this animerend sharedmaterials = this originalanimematerials; } } }); } } 몸의 재질을 변경하면 zepeto 아바타의 메이크업이 올바르게 표시되지 않을 수 있습니다 마모된 아이템의 색상 변경 마모된 아이템은 본체 객체의 하위 객체로 인스턴스화됩니다 아이템 객체의 재료 섹션에서 각 아이템에 적용된 재료를 확인할 수 있습니다 스크립트를 사용하여 런타임에 재료를 교체함으로써 아이템의 색상을 변경할 수 있습니다 아래는 로컬 플레이어가 착용한 첫 번째 아이템의 색상을 변경하는 샘플 코드입니다 캐릭터가 로드된 후에만 아이템의 색상이 변경되도록 하세요 import { zepetoscriptbehaviour } from 'zepeto script' import {localplayer, zepetocharacter, zepetoplayers} from "zepeto character controller"; import { gameobject, material, renderer, skinnedmeshrenderer, transform, waitforseconds } from 'unityengine'; import { button } from 'unityengine ui'; export default class changeskincolor extends zepetoscriptbehaviour { public newcolormaterial material; public changecolorbutton button; public originalcolorbutton button; private originalcolormaterial material; private body gameobject; private itemrend renderer; private localcharacter zepetocharacter; start() { // 로컬 플레이어를 찾고 localcharacter에 설정합니다 zepetoplayers instance onaddedlocalplayer addlistener(() => { this localcharacter = zepetoplayers instance localplayer zepetoplayer character; // 로컬 플레이어의 zepeto 컨텍스트의 몸체에 접근합니다 this body = this localcharacter context getcomponentinchildren\<skinnedmeshrenderer>() gameobject; // 몸체의 첫 번째 자식 아이템의 재질에 접근합니다 this itemrend = this body transform getchild(0) getcomponent\<skinnedmeshrenderer>(); // 원래 재질을 저장합니다 this originalcolormaterial = this itemrend material; }); // 버튼이 눌리면 미리 설정된 재질로 교체합니다 this changecolorbutton onclick addlistener(() => { if(this localcharacter != null) { this itemrend material = this newcolormaterial; } }); // 버튼이 눌리면 원래 재질로 돌아갑니다 this originalcolorbutton onclick addlistener(() => { if(this localcharacter != null) { this itemrend material = this originalcolormaterial; } }); } } 코드 설명 this body transform getchild(0) 는 착용한 아이템 중 첫 번째 아이템, 즉 인덱스 0에 있는 아이템을 참조합니다 이것을 조정하여 다른 착용 아이템의 색상을 변경할 수 있습니다 여러 재질을 사용하는 아이템의 경우, 재질 교체는 동일한 길이의 재질 배열이 필요하다는 점을 기억하세요 zepeto 캐릭터와 모든 아이템의 색상 변경 지금까지 얻은 통찰력을 활용하여 캐릭터와 모든 아이템의 색상을 균일하게 수정할 수 있습니다 "색상 변경" 버튼을 클릭할 때 로컬 플레이어의 캐릭터와 아이템 색상을 완전히 변경하고, "원래 색상" 버튼을 클릭할 때 원래 색상으로 되돌리는 샘플 코드입니다 import { zepetoscriptbehaviour } from 'zepeto script' import {localplayer, zepetocharacter, zepetoplayers} from "zepeto character controller"; import { gameobject, material, renderer, skinnedmeshrenderer, transform, waitforseconds } from 'unityengine'; import { button } from 'unityengine ui'; export default class changeallmaterial extends zepetoscriptbehaviour { public newcolormaterial material; public changecolorbutton button; public originalcolorbutton button; private originalmaterials material\[] = new array(); private bodyrends renderer\[]; private localcharacter zepetocharacter; start() { // 로컬 플레이어를 찾고 localcharacter에 설정합니다 zepetoplayers instance onaddedlocalplayer addlistener(() => { this localcharacter = zepetoplayers instance localplayer zepetoplayer character; // 원래 재료를 유지하기 위해 저장합니다 this bodyrends= this localcharacter getcomponentsinchildren\<skinnedmeshrenderer>(); this bodyrends foreach((currentrenderer) =>{ for(let i=0; i\<currentrenderer sharedmaterials length;i++){ this originalmaterials push(currentrenderer sharedmaterials\[i]); } }); }); // 버튼이 눌릴 때 미리 설정된 재료로 교체합니다 this changecolorbutton onclick addlistener(() => { if(this localcharacter != null) { this bodyrends foreach((currentrenderer) =>{ let tempmaterials material\[] = new array(); for(let i=0; i\<currentrenderer sharedmaterials length;i++){ tempmaterials push(this newcolormaterial); } currentrenderer sharedmaterials = tempmaterials; }); } }); // 버튼이 눌릴 때 원래 재료로 돌아갑니다 this originalcolorbutton onclick addlistener(() => { if(this localcharacter != null) { let indexnum = 0; this bodyrends= this localcharacter getcomponentsinchildren\<skinnedmeshrenderer>(); this bodyrends foreach((currentrenderer) =>{ let tempmaterials material\[] = new array(); for(let i=0; i\<currentrenderer sharedmaterials length;i++){ tempmaterials push(this originalmaterials\[indexnum]); indexnum++; } currentrenderer sharedmaterials = tempmaterials; }); } }); } } 이 방법은 로컬 플레이어뿐만 아니라 런타임에 생성된 모든 zepeto 캐릭터, npc 캐릭터를 포함하여 적용할 수 있습니다 창의력을 발휘하고 재미있는 방법으로 적용해 보세요!