这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

73 行
1.7 KiB

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
/// <summary>
/// This class contains the function to call when play button is pressed
/// </summary>
public class StartGame : MonoBehaviour
{
public LoadEventChannelSO onPlayButtonPress;
public GameSceneSO[] locationsToLoad;
public bool showLoadScreen;
public SaveSystem saveSystem;
public Text startText;
public Button resetSaveDataButton;
private bool _hasSaveData;
private void Start()
{
_hasSaveData = saveSystem.LoadSaveDataFromDisk();
if (_hasSaveData)
{
startText.text = "Continue";
resetSaveDataButton.gameObject.SetActive(true);
}
else
{
resetSaveDataButton.gameObject.SetActive(false);
}
}
public void OnPlayButtonPress()
{
if (!_hasSaveData)
{
saveSystem.WriteEmptySaveFile();
//Start new game
onPlayButtonPress.RaiseEvent(locationsToLoad, showLoadScreen);
}
else
{
//Load Game
StartCoroutine(LoadSaveGame());
}
}
public void OnResetSaveDataPress()
{
_hasSaveData = false;
startText.text = "Play";
resetSaveDataButton.gameObject.SetActive(false);
}
public IEnumerator LoadSaveGame()
{
yield return StartCoroutine(saveSystem.LoadSavedInventory());
var locationGuid = saveSystem.saveData._locationId;
var asyncOperationHandle = Addressables.LoadAssetAsync<LocationSO>(locationGuid);
yield return asyncOperationHandle;
if (asyncOperationHandle.Status == AsyncOperationStatus.Succeeded)
{
var locationSo = asyncOperationHandle.Result;
onPlayButtonPress.RaiseEvent(new[] { (GameSceneSO)locationSo }, showLoadScreen);
}
}
}