在初始化下游游戏对象之前,在游戏开始时初始化服务/代码的推荐方法是什么?例如,我有以下代码尝试初始化Google Play游戏。我想确保在单独的游戏对象尝试通过Init()
使用登录的用户名更新标签之前,我想确保Social.localUser.userName
是完整的(我希望将显示逻辑与GameManager
代码分开)。
谢谢
public class GameManager : MonoBehaviour
private void Start ()
{
PlayServicesClient.Init(() =>
{
// More Game Logic
});
}
}
// Separate script used in the menu UI
login.text = (Social.localUser.authenticated) ? Social.localUser.userName : "Login";
编辑:我曾尝试按照Eric的建议将Play游戏的初始化移至Awake()
,但即使登录代码位于另一个脚本的Start()
中,登录文本代码也不会等待Init方法完成。
private void Awake()
{
PlayGamesClient.Init((success) => { });
}
// Start method of the other script
private void Start()
{
loginText.text = (Social.localUser.authenticated) ? Social.localUser.userName : "Login";
}