Quarter View Example
4 분
ZEPETO 캐릭터 컨트롤은 V-Pad 대신 Unity의 새로운 입력 시스템을 사용하도록 사용자 정의할 수 있습니다.
이것은 쿼터 뷰 컨트롤 설정의 예입니다.

1단계 : 카메라 뷰 설정
카메라를 쿼터 뷰로 설정합니다 (이것은 예시이므로, 프로젝트에 맞게 카메라 설정을 수정해 주세요).
이 시점에서 카메라의 태그는 MainCamera로 설정되어야 합니다.

2단계 : InputAction 설정
쿼터 뷰에 대한 새로운 InputAction을 정의함으로써, 터치 스크린을 통해 캐릭터의 움직임을 제어할 수 있습니다.
Create > Input Actions를 선택하고 파일 이름을 QuarterViewActions로 설정합니다.
- 이동
- 액션 유형 : 통과
- 이동 트리거
- 액션 유형 : 버튼

계층 구조 > 빈 객체 만들기 후, 파일 이름을 QuarterViewController로 변경합니다.
QuarterViewController 객체에서 구성 요소 추가를 선택하고 플레이어 입력을 추가합니다.

방금 생성한 QuarterView 작업을 작업 목록에 드래그하여 연결합니다.
동작을 Unity 이벤트 호출로 변경합니다.

3단계 : 스크립팅
터치 스크린 입력을 통해 캐릭터의 움직임 방향을 계산하는 스크립트를 작성하세요.
Create > ZEPETO > TypeScript를 선택하고 이름을 QuarterView Controller로 변경하세요.
QuarterView Controller 객체에 스크립트를 추가합니다.
import {ZepetoScriptBehaviour} from 'ZEPETO.Script'
import {PlayerInput,InputAction} from "UnityEngine.InputSystem"
import {CallbackContext} from "UnityEngine.InputSystem.InputAction"
import {CharacterState, ZepetoCharacter, ZepetoPlayers, ZepetoCamera} from 'ZEPETO.Character.Controller'
import {Camera, Quaternion, Time, Vector2, Vector3, WaitForEndOfFrame} from "UnityEngine";
export default class QuarterViewController extends ZepetoScriptBehaviour {
private myCharacter: ZepetoCharacter;
private startPos: Vector2 = Vector2.zero;
private curPos: Vector2 = Vector2.zero;
private playerInput: PlayerInput;
private touchPositionAction : InputAction;
private touchTriggerAction : InputAction;
private isTriggered: boolean = false;
private isTouchDown: boolean = false;
private CanMove() : boolean {
return this.isTouchDown && !this.isTriggered;
}
OnEnable(){
this.playerInput = this.gameObject.GetComponent<PlayerInput>();
}
Start() {
this.touchTriggerAction = this.playerInput.actions.FindAction("MoveTrigger");
this.touchPositionAction = this.playerInput.actions.FindAction("Move");
this.touchTriggerAction.add_started((context)=>{
this.isTriggered = true;
this.isTouchDown = true;
});
this.touchTriggerAction.add_canceled((context)=>{
this.isTriggered = false;
this.isTouchDown = false;
});
this.touchPositionAction.add_performed((context)=>{
if(this.isTouchDown)
{
this.curPos = context.ReadValueAsObject() as Vector2;
if(this.isTriggered) {
this.isTriggered = false;
this.startPos = this.curPos;
}
}
});
ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
ZepetoPlayers.instance.LocalPlayer.zepetoCamera.gameObject.SetActive(false);
this.myCharacter = ZepetoPlayers.instance.LocalPlayer.zepetoPlayer.character;
this.StartCoroutine(this.InputControlLoop());
});
}
private *InputControlLoop(){
while(true)
{
yield new WaitForEndOfFrame();
if (this.myCharacter && this.CanMove()) {
var camRot = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y, 0);
var moveDir = Vector2.op_Subtraction(this.curPos, this.startPos);
moveDir = Vector2.op_Division(moveDir, 100);
if (moveDir.magnitude > 0) {
if(moveDir.magnitude > 1)
moveDir.Normalize();
var optMoveDir = new Vector3(moveDir.x, 0, moveDir.y);
optMoveDir = Vector3.op_Multiply(optMoveDir, Time.deltaTime * 80 );
this.myCharacter.Move(camRot * optMoveDir);
}
}
}
}
}