코드에서 설정을 관리하려면 Unity 스크립팅 API RemoteSettings 클래스를 사용합니다. RemoteSettings.Updated
이벤트를 위한 핸들러 함수를 등록할 수 있습니다. RemoteSettings
클래스는 새로운 세션이 시작할 때마다 모든 등록된 핸들러를 호출합니다. Unity Analytics 대시보드에 다운로드하려면 RemoteSettings
오브젝트를 위해 키-값 페어를 생성합니다.
설정을 가져오려면 네트워크 트랜잭션이 필요하므로, RemoteSettings
오브젝트는 Updated
이벤트를 비동기로 보냅니다. 핸들러 함수는 각각 플랫폼 또는 동일한 플랫폼의 각각의 시작에서 동일한 순서에서 호출되지 않을 수도 있습니다. 사실, 네트워크 연결을 사용할 수 없거나 캐싱된 세팅을 찾을 수 없는 경우, RemoteSettings
오브젝트는 Updated
이벤트를 전혀 디스패치하지 않습니다. 합리적인 기본값으로 설정 변수를 항상 초기화하고, 다른 시간에서 또는 다른 순서로 Updated
핸들러가 호출될 가능성을 염두에 둡니다.
코드 예제
다음의 예제는 게임 난이도를 조정하는 다수의 프로퍼티를 정의하는 클래스를 보여줍니다:
using UnityEngine;
public class RemoteTuningVariables : MonoBehaviour {
public float DefaultSpawnRateFactor = 1.0f;
public float DefaultEnemySpeedFactor = 1.0f;
public float DefaultEnemyStrengthFactor = 1.0f;
public static float SpawnRateFactor{ get; private set; }
public static float EnemySpeedFactor{ get; private set; }
public static float EnemyStrengthFactor{ get; private set; }
void Start () {
SpawnRateFactor = DefaultSpawnRateFactor;
EnemySpeedFactor = DefaultEnemySpeedFactor;
EnemyStrengthFactor = DefaultEnemyStrengthFactor;
RemoteSettings.Updated +=
new RemoteSettings.UpdatedEventHandler(HandleRemoteUpdate);
}
private void HandleRemoteUpdate(){
SpawnRateFactor
= RemoteSettings.GetFloat ("SpawnRateFactor", DefaultSpawnRateFactor);
EnemySpeedFactor
= RemoteSettings.GetFloat ("EnemySpeedFactor", DefaultEnemySpeedFactor);
EnemyStrengthFactor
= RemoteSettings.GetFloat ("EnemyStrengthFactor", DefaultEnemyStrengthFactor);
}
}
RemoteSettings.GetFloat()
메서드 호출에서 클래스가 기본값을 제공한다는 점을 기억하시기 바랍니다. RemoteSettings
오브젝트가 지정된 키를 찾을 수 없는 경우 (예를 들어, 키 이름의 철자가 틀린 경우), 메서드는 여전히 기본값을 튜닝 변수에 배정합니다. 그렇지 않으면, GetFloat()
및 GetInt()
메서드는 0을 숫자에 배정하고 GetString()
은 빈 문자열을 문자열에 배정하며, GetBool()
는 false를 불 변수에 배정합니다.
클래스는 또한 같은 기본값을 Start()
메서드의 프로퍼티에 배정합니다. Unity가 분석 서비스에 액세스할 수 없고 이전에 캐싱된 설정이 로컬에서 사용이 불가능할 때, RemoteSettings
오브젝트는 Updated
이벤트를 디스패치하지 않습니다. Start()
메서드에서 기본값을 배정하여 프로퍼티는 항상 타당한 값을 가질 수 있게 합니다.
2017–05–30 편집 리뷰를 거쳐 페이지 게시됨
2017–05–30 - 이 날짜에는 Unity 5.5와 서비스가 호환되지만 버전 호환성은 변경할 수 있습니다.
Unity 2017.1의 새로운 기능
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.